CMake add a library which is a group of other libraries
cmake
Solution
I added a new type of library, the INTERFACE library to the upcoming CMake 3.0.0 release. That is designed as the solution to this problem:
http://www.cmake.org/cmake/help/git-master/manual/cmake-buildsystem.7.html#interface-libraries
add_library(all_branches INTERFACE)
target_link_libraries(all_branches INTERFACE branch1 branch2)
add_executable(myexe ...)
target_link_libraries(myexe all_branches)
Problem
I have a core library which branches off into several other libraries. In CMakeLists.txt it looks a bit like this ``` ADD_LIBRARY (core ...) ADD_LIBRARY (branch1 ...) ADD_LIBRARY (branch2 ...) ... TARGET_LINK_LIBRARIES (branch1 core) TARGET_LINK_LIBRARIES (branch2 core) ... ``` I have some executables which may depend on any or all of the branches. For those that depend on all the branches, instead of writing ``` ADD_EXECUTABLE (foo ...) TARGET_LINK_LIBRARIES (foo branch1 branch2 ...) ``` I tried ``` ADD_LIBRARY (all-branches) TARGET_LINK_LIBRARIES (all-branches branch1 branch2 ...) ``` then ``` TARGET_LINK_LIBRARIES (foo all-branches) ``` This works but CMake spits out a warning. ``` You have called ADD_LIBRARY for library all-branches without any source files. This typically indicates a problem with your CMakeLists.txt file ``` I understand the message, but it's not an error. What does CMake think is an acceptable way to build a meta-library like this?