I am using cmake 2.8.2 and I have added a custom configuration to my project like this:<br><br># Add configuration for debug pthreads builds based on the debug configuration<br># =================================================================================<br>
set(CMAKE_C_FLAGS_DEBUGPTHREADS ${CMAKE_C_FLAGS_DEBUG} CACHE STRING "Flags used by the compiler during DebugPthreads builds")<br>set(CMAKE_CXX_FLAGS_DEBUGPTHREADS ${CMAKE_CXX_FLAGS_DEBUG} CACHE STRING "Flags used by the compiler during DebugPthreads builds")<br>
set(CMAKE_EXE_LINKER_FLAGS_DEBUGPTHREADS ${CMAKE_EXE_LINKER_FLAGS_DEBUG} CACHE STRING "Flags used by the linker for executables during DebugPthreads builds")<br>set(CMAKE_SHARED_LINKER_FLAGS_DEBUGPTHREADS ${CMAKE_SHARED_LINKER_FLAGS_DEBUG} CACHE STRING "Flags used by the linker for shared libraries during DebugPthreads builds")<br>
set(CMAKE_MODULE_LINKER_FLAGS_DEBUGPTHREADS ${CMAKE_MODULE_LINKER_FLAGS_DEBUG} CACHE STRING "Flags used by the linker for loadable modules during DebugPthreads builds")<br><br># add in the details specific to this configuration<br>
set(CMAKE_C_FLAGS_DEBUGPTHREADS "${CMAKE_C_FLAGS_DEBUGPTHREADS} /DSC_USE_PTHREADS")<br>set(CMAKE_CXX_FLAGS_DEBUGPTHREADS "${CMAKE_CXX_FLAGS_DEBUGPTHREADS} /DSC_USE_PTHREADS")<br><br>mark_as_advanced(<br>
CMAKE_C_FLAGS_DEBUGPTHREADS<br> CMAKE_CXX_FLAGS_DEBUGPTHREADS<br> CMAKE_EXE_LINKER_FLAGS_DEBUGPTHREADS<br> CMAKE_SHARED_LINKER_FLAGS_DEBUGPTHREADS <br> CMAKE_MODULE_LINKER_FLAGS_DEBUGPTHREADS<br>)<br><br># This variable is only set for multi-config IDE generators like MSVC<br>
if(CMAKE_CONFIGURATION_TYPES)<br> list(APPEND CMAKE_CONFIGURATION_TYPES DebugPthreads)<br> list(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES)<br> set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}"<br>
CACHE STRING "Semicolon separated list of supported configuration types [Debug|Release|MinSizeRel|RelWithDebInfo|DebugPthreads]"<br> FORCE)<br>endif()<br><br>This works and inside Visual Studio 2008 I now get a DebugPthreads configuration in addition to the normal 4. As part of my project I build a library which I now want to add a target dependency for, but only in the DebugPthreads configuration. Something like this:<br>
<br>add_library(myLib ${sources})<br><br>if (activeConfig is DebugPthreads)<br> target_link_libraries(myLib ${FULL_PATH_TO_PTHREADS_LIB})<br>endif()<br><br>There doesn't seem to be a way to specify target_link_libraries() for selected configurations. I see that it can be specified for all debug or all release configurations but that isn't what I need. The Debug and Release versions of myLib do not depend on the pthreads library but the DebugPthreads version of myLib does.<br>
<br>Googling for answers has revealed several people with the similar problems but no clear answers. I have seen recommendations to use an imported library and the IMPORTED_LOCATION and IMPORTED_CONFIGURATIONS properties. I tried this code:<br>
<br>add_library(my_pthreads STATIC IMPORTED)<br>set_target_properties(my_pthreads PROPERTIES<br> IMPORTED_CONFIGURATIONS "DebugPthreads"<br> IMPORTED_LOCATION_DEBUGPTHREADS "${PTHREADS_LIBRARIES}"<br>
)<br>target_link_libraries(myLib my_pthreads)<br><br>but that includes the pthreads library as a target dependency in all configurations. If I omit the IMPORTED_CONFIGURATIONS options then I get the correct result for the DebugPthreads configuration but all other configurations are trying to find a library called my_pthreads-NOTFOUND.<br>
<br>Is there a way to do what I want in cmake ?<br><br>--<br>Glenn<br><br>