I have a static link library (say libfoo).
add_library(foo STATIC foo.cpp)
There are many executables that links(uses) this library.
add_executable(myexe1 myexe1.cpp)
link_target_libraries(myexe1 foo)
add_executable(myexe2 myexe2.cpp)
link_target_libraries(myexe2 foo)
add_executable(myexe3 myexe3.cpp)
link_target_libraries(myexe3 foo)
#... and so on. (These definitions are actually scattered in the project)
Now I would like to use -Wl,--whole-archive
flag to the library.
It seems one solution is to add the flags in the executable side.
add_executable(myexe1 myexe1.cpp)
link_target_libraries(myexe1 -Wl,--whole-archive foo -Wl,--no-whole-archive)
But in this way I have to write this every time I define executable that links to this library.
Is there any way to add this flag to the library definition side so that the flag is always used when linking the executables that depend on the library?