[CMake] Visual Studio configurations with cmake

Michael Hertling mhertling at online.de
Sat Dec 3 08:36:11 EST 2011


On 12/03/2011 12:31 PM, terje loe wrote:
> 
> Hi,
> I'm trying to set up cmake for my visual studio project.. I' ve set it up so it works fine for make files, but got some problems setting it up as I want it for visual studio.
> 1.
> I'm setting up different visual studio configurations so I have DebugOpenGL, DebugDirectX, ReleaseOpenGL and ReleaseDirectX. And I want to set special defines for eachof the configurations, USE_OPENGL, USE_DIRECTX , but I cant figure out how to do it? I know for QMake you can do this:
> 
> !build_pass:addExclusiveBuilds(use_opengl, OpenGL , use_directx, DirectX)build_pass {    CONFIG(use_opengl, use_opengl|use_directx):DEFINES+=USE_OPENGL    else:DEFINES+=USE_DIRECTX}
> Is it possible to do something similar with cmake? Note that this is not the normal debug/release flag you give to cmake, but different configurations in visual studio.
> This is how I set up the configurations:
> if(CMAKE_CONFIGURATION_TYPES AND MSVC)	set(CMAKE_CONFIGURATION_TYPES "DebugOpenGL;ReleaseOpenGL;DebugDirectX;ReleaseDirectX")	set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING	"Reset the configurations to what we need"	FORCE)		#DebugOpenGL flags	set(CMAKE_CXX_FLAGS_DEBUGOPENGL "/D_DEBUG /MDd /Zi /Ob0 /Od /RTC1" CACHE STRING "Flags used by the C++ compiler during maintainer builds." FORCE)	set(CMAKE_C_FLAGS_DEBUGOPENGL "/D_DEBUG /MDd /Zi  /Ob0 /Od /RTC1" CACHE STRING "Flags used by the C compiler during maintainer builds." FORCE)	set(CMAKE_EXE_LINKER_FLAGS_DEBUGOPENGL "/debug /INCREMENTAL" CACHE STRING "Flags used for linking binaries during maintainer builds." FORCE )	set(CMAKE_SHARED_LINKER_FLAGS_DEBUGOPENGL "/debug /INCREMENTAL" CACHE STRING "Flags used by the shared libraries linker during maintainer builds." FORCE )
> 	#ReleaseOpenGL flags	set(CMAKE_CXX_FLAGS_RELEASEOPENGL "/MD /O2 /Ob2 /D NDEBUG" CACHE STRING "Flags used by the C++ compiler during maintainer builds." FORCE)	set(CMAKE_C_FLAGS_RELEASEOPENGL "/MD /O2 /Ob2 /D NDEBUG" CACHE STRING "Flags used by the C compiler during maintainer builds." FORCE)	set(CMAKE_EXE_LINKER_FLAGS_RELEASEOPENGL "/INCREMENTAL:NO" CACHE STRING "Flags used for linking binaries during maintainer builds." FORCE )	set(CMAKE_SHARED_LINKER_FLAGS_RELEASEOPENGL "/INCREMENTAL:NO" CACHE STRING "Flags used by the shared libraries linker during maintainer builds." FORCE )		#DebugDirectX flags	set(CMAKE_CXX_FLAGS_DEBUGDIRECTX "/D_DEBUG /MDd /Zi /Ob0 /Od /RTC1" CACHE STRING "Flags used by the C++ compiler during maintainer builds." FORCE)	set(CMAKE_C_FLAGS_DEBUGDIRECTX "/D_DEBUG /MDd /Zi  /Ob0 /Od /RTC1" CACHE STRING "Flags used by the C compiler during maintainer builds." FORCE)	set(CMAKE_EXE_LINKER_FLAGS_DEBUGDIRECTX "/debug /INCREMENTAL" CACHE STRING "Flags used fo
r linking binaries during maintainer builds." FORCE )	set(CMAKE_SHARED_LINKER_FLAGS_DEBUGDIRECTX "/debug /INCREMENTAL" CACHE STRING "Flags used by the shared libraries linker during maintainer builds." FORCE )		#ReleaseDirectx flags	set(CMAKE_CXX_FLAGS_RELEASEDIRECTX "/MD /O2 /Ob2 /D NDEBUG" CACHE STRING "Flags used by the C++ compiler during maintainer builds." FORCE)	set(CMAKE_C_FLAGS_RELEASEDIRECTX "/MD /O2 /Ob2 /D NDEBUG" CACHE STRING "Flags used by the C compiler during maintainer builds." FORCE)	set(CMAKE_EXE_LINKER_FLAGS_RELEASEDIRECTX "/INCREMENTAL:NO" CACHE STRING "Flags used for linking binaries during maintainer builds." FORCE )	set(CMAKE_SHARED_LINKER_FLAGS_RELEASEDIRECTX "/INCREMENTAL:NO" CACHE STRING "Flags used by the shared libraries linker during maintainer builds." FORCE )endif()

SET_DIRECTORY_PROPERTIES(PROPERTIES
    COMPILE_DEFINITIONS_DEBUGOPENGL USE_OPENGL
    COMPILE_DEFINITIONS_RELEASEOPENGL USE_OPENGL
    COMPILE_DEFINITIONS_DEBUGDIRECTX USE_DIRECTX
    COMPILE_DEFINITIONS_RELEASEDIRECTX USE_DIRECTX
)

> 2.
> I have been able to exclude .cpp files from the visual studio build by doing this:
> set_source_files_properties(${files}PROPERTIES HEADER_FILE_ONLY true)
> But in visual studio you can right click a file-> properties and select exclude file from build.. this sets a red icon on the file. I want to do this for sepereate configurations as in question 1. 		 	   		  

http://www.mail-archive.com/cmake@cmake.org/msg38418.html

Regards,

Michael


More information about the CMake mailing list