CMake variable or property to recognize betwen debug and release builds

I want to set the CMake variable differently for debugging and release. I tried using CMAKE_CFG_INTDIR as follows:

IF(${CMAKE_CFG_INTDIR} STREQUAL "Debug") SET(TESTRUNNER DllPlugInTesterd_dll) ELSE(${CMAKE_CFG_INTDIR} STREQUAL "Debug") SET(TESTRUNNER DllPlugInTester_dll) ENDIF(${CMAKE_CFG_INTDIR} STREQUAL "Debug") 

But this variable evaluates to $ (OUTDIR) at the time CMake does its thing.

Is there a CMake variable that I can use to distinguish between debug and release assemblies, or something like TARGET_LINK_LIBRARIES strings where you can specify debug and optimized libraries?

EDIT: I cannot use CMAKE_BUILD_TYPE since this is only supported by make-based generators and I need to get this to work with Visual Studio.

+6
build-process visual-c ++ cmake
source share
2 answers

You can define your own CMAKE_CFG_INTDIR

 IF(NOT CMAKE_CFG_INTDIR) SET(CMAKE_CFG_INTDIR "Release") ENDIF(NOT CMAKE_CFG_INTDIR) IF(CMAKE_CFG_INTDIR MATCHES "Debug") ...Debug PART... ELSE(CMAKE_CFG_INTDIR MATCHES "Debug") ...Release PART... ENDIF(CMAKE_CFG_INTDIR MATCHES "Debug") 

Then, when you invoke cmake, add a definition (-D):

 cmake -DCMAKE_CFG_INTDIR=Debug /path/of/your/CMakeLists.txt 

For goals, you have two solutions:

First:

 IF(CMAKE_CFG_INTDIR MATCHES "Debug") TARGET_LINK_LIBRARIES(YOUR_EXE DllPlugInTesterd...) ELSE(CMAKE_CFG_INTDIR MATCHES "Debug") TARGET_LINK_LIBRARIES(YOUR_EXE DllPlugInTester...) ENDIF(CMAKE_CFG_INTDIR MATCHES "Debug") 

Second:

 IF(CMAKE_CFG_INTDIR MATCHES "Debug") FIND_LIBRARY(DLL_PLUGIN DllPlugInTesterd_dll /path/of/your/lib) ELSE(CMAKE_CFG_INTDIR MATCHES "Debug") FIND_LIBRARY(DLL_PLUGIN PlugInTester_dll /path/of/your/lib) ENDIF(CMAKE_CFG_INTDIR MATCHES "Debug") 

Then for reference

 TARGET_LINK_LIBRARIES(YOUR_EXE ${DLL_PLUGIN}...) 
+3
source share

Try CMAKE_BUILD_TYPE instead

+3
source share