Reputation:
I'am using CMake to create a Visual Studio 2008 project. In this project I need to create a new configuration, called UnitaryTests. So, in CMakeLists.txt I put the line
set(CMAKE_CONFIGURATION_TYPES "Release;Debug;UnitaryTest" CACHE STRING "Configurations" FORCE)
Later in the CMakeLists.txt file there is the following line:
target_link_libraries( ${PROJECT_NAME} ${ASTEK_LIBRARIES} )
to link with an external package. The variable ASTEK_LIBRARIES contains a text like:
debug;debug/libs;optimized;release/libs
My problem is that I must force the new configuration to only use the debug version of this package (currently it is using the release version). Do you know how to do this?
Note: it is not me that fill the variable ASTEK_LIBRARIES. It is created by a corporate script that I cannot change.
Thanks for your help.
Upvotes: 3
Views: 1919
Reputation: 1459
To force target_link_libraries()
to link against a different library on a per-target basis, replace keywords as appropriate before linking. The following example shows how you would replace 'optimized' by 'general' to force a debug build to link against a release (optimized) library:
string(REPLACE "optimized" "general" MODIFIED_LIBS "${MY_LIBS}")
target_link_libraries(MyTarget ${MODIFIED_LIBS})
E.g. For MY_LIBS = "optimized;mylib.lib;debug;mylib_d.lib", MODIFIED_LIBS will be "general;mylib.lib;debug;mylib_d.lib". In this example, the 'general' keyword will cause both libraries to be linked against in your target during a debug build.
See https://cmake.org/cmake/help/latest/command/target_link_libraries.html for more information.
Upvotes: 0
Reputation: 78280
Use:
set_property(GLOBAL PROPERTY DEBUG_CONFIGURATIONS "Debug;UnitaryTest")
If you also have RelWithDebInfo
defined, this would belong in here too.
For further info run:
cmake --help-property DEBUG_CONFIGURATIONS
Upvotes: 5