[CMake] Visual Studio configurations with cmake

terje loe terjeloe at hotmail.com
Sat Dec 3 06:31:03 EST 2011


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 for 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()
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. 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20111203/5cc81d6e/attachment.htm>


More information about the CMake mailing list