I am working on a really large project, which I'm in the process of moving from using custom Makefiles to using cmake instead, but I'm still missing a functionality that was implemented with the Makefiles.
The project has many sub-directories, each one of which is compiled into a static library, and then linked into the final executable.
Here is a small example
src/
lib1/
lib2/
lib3/
main.cpp
CMakeLists.txt
and in CMakeLists.txt might be something like this:
add_subdirectory(lib1)
add_subdirectory(lib2)
add_subdirectory(lib3)
add_executable(test main.cpp)
target_link_libraries(test PUBLIC lib1 lib2 lib3)
I want to debug the final executable, but I don't want to build all static libraries with debug symbols and no optimizations, because then the debugging becomes too slow.
So I want to build lib2
with CMAKE_BUILD_TYPE=Release
and lib1
and lib3
with CMAKE_BUILD_TYPE=Debug
.
Please bear in mind that instead of three libraries, there are actually ~10, and I want to be able to do that for each one of them, and for a number of them at the same time.
Is there a way to do that from the main CMakeLists.txt
?
What I would prefer would be something that would make this possible from the command line:
cmake -DDEBUG_LIBS={lib1,lib3} /path/to/src
cmake --build .