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 &quot;Flags used by the compiler during DebugPthreads builds&quot;)<br>set(CMAKE_CXX_FLAGS_DEBUGPTHREADS                ${CMAKE_CXX_FLAGS_DEBUG}            CACHE STRING &quot;Flags used by the compiler during DebugPthreads builds&quot;)<br>
set(CMAKE_EXE_LINKER_FLAGS_DEBUGPTHREADS        ${CMAKE_EXE_LINKER_FLAGS_DEBUG}        CACHE STRING &quot;Flags used by the linker for executables during DebugPthreads builds&quot;)<br>set(CMAKE_SHARED_LINKER_FLAGS_DEBUGPTHREADS        ${CMAKE_SHARED_LINKER_FLAGS_DEBUG}    CACHE STRING &quot;Flags used by the linker for shared libraries during DebugPthreads builds&quot;)<br>
set(CMAKE_MODULE_LINKER_FLAGS_DEBUGPTHREADS        ${CMAKE_MODULE_LINKER_FLAGS_DEBUG}    CACHE STRING &quot;Flags used by the linker for loadable modules during DebugPthreads builds&quot;)<br><br># add in the details specific to this configuration<br>
set(CMAKE_C_FLAGS_DEBUGPTHREADS            &quot;${CMAKE_C_FLAGS_DEBUGPTHREADS} /DSC_USE_PTHREADS&quot;)<br>set(CMAKE_CXX_FLAGS_DEBUGPTHREADS        &quot;${CMAKE_CXX_FLAGS_DEBUGPTHREADS} /DSC_USE_PTHREADS&quot;)<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 &quot;${CMAKE_CONFIGURATION_TYPES}&quot;<br>
        CACHE STRING &quot;Semicolon separated list of supported configuration types [Debug|Release|MinSizeRel|RelWithDebInfo|DebugPthreads]&quot;<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&#39;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&#39;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                &quot;DebugPthreads&quot;<br>    IMPORTED_LOCATION_DEBUGPTHREADS        &quot;${PTHREADS_LIBRARIES}&quot;<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>