I need to get a list of all linked libraries in form as they will be passed to the linker in my CMake script.
For example, in my CMake project file, I define the target, which represents the build of a dynamic library. I call the functions from another CMake file's to include in my target all necessary static libraries, and finally if I
set(CMAKE_VERBOSE_MAKEFILE ON)
I see the output something like this: "clang++ -o /path/to/program.p /path/to/library1.a /path/to/library2.a" and so on.
I need to get the string that will contain the list of all static libraries linked to my dynamic library in my CMake script. I tried to do that like:
get_target_property(l_libs2 ${target} LINK_LIBRARIES)
message("!!!LINK_LIBRARIES: ${l_libs2}")
But it contains the string in the format like a: "Library::Library1;Library::Library2". I tried to get the same information from the properties: INTERFACE_LINK_LIBRARIES, LDFLAGS, LIBS, LINK_FLAGS, LINK_WHAT_YOU_USE, LINK_OPTIONS,...
Is it possible in principle? How to CMake engine "build" this argument for the linker?
Why I need that:
I need to exclude export from all libraries except one. If I pass to the linker option
"-Wl,--exclude-libs,ALL"
it leads to SEGFAULT when my dynamic library (python extension module) loads into python. I played with compiler flags and found that it happens because
"--exclude-libs,ALL"
exclude export from "python.a" library. So if I set the exclusion list more precisely i.e.
"-Wl,--exclude-libs,library1.a -Wl,--exclude-libs,library2.a"
and so on, i.e. all libraries except "python.a", the module load to python without any problem. So I decided to generate this compiler option dynamically to get the libraries list and then, process it with regex. The best way to solve that is if clang will have the opposite option to "--exclude-libs" for example "--exclude-libs-except" (or something like that) but unfortunately I do not find it in clang documentation.