Customize CMAKE_XXX_LINK_EXECUTABLE with -Wl options when linking shared libraries

Hi, I am a new beginner who is trying to write a new language in cmake, writing files such as CMakeXXXInformation.cmake. I am confused at how -Wl option is passed in CMAKE_CXX_LINK_EXECUTABLE. Among those variables I saw (FLAGS, CMAKE_CXX_LINK_FLAGS, LINK_FLAGS), seems to be not related to -Wl,rpath option.

When building an executable, it seems that linking a shared library always needed -Wl,rpath to find the path to that shared library during runtime. But I really have no clue how to pass that information in my own customized CMAKE_XXX_LINK_EXECUTABLE.

Any help or suggestion is appreciated. Thanks in advance.

In details, in the CMakeCXXInformation.cmake, the command to link executable is:
set(CMAKE_CXX_LINK_EXECUTABLE
“<CMAKE_CXX_COMPILER> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> -o <LINK_LIBRARIES>”)

I add some -L options into:
<CMAKE_CXX_COMPILER> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> -o -LAAA <LINK_LIBRARIES> -LBBB.

And the cmake command turns into:
-o my_app -LAAA -Wl,-rpath,xxxxx libA.so -LBBB.
From my view, this “-Wl,-rpath” definitely comes from a cmake set up, but which variable should I focus on to get this “-Wl,-rpath” information?It must be related to <LINK_LIBRARIES> somehow, but what am I missing that does not have “-Wl,-rpath” in my own cmake language?

Seems to be the CMAKE_EXECUTABLE_RUNTIME_CXX_FLAG that matters. :slight_smile: