FW: [CMake] Rediscovering the compiler.

Josef Karthauser joe.karthauser at geomerics.com
Tue Dec 4 04:24:46 EST 2007


> From: cmake-bounces+joe.karthauser=geomerics.com at cmake.org
> [mailto:cmake-bounces+joe.karthauser=geomerics.com at cmake.org] On
Behalf
> Of Brandon Van Every
> Sent: 03 December 2007 20:06
> To: cmake at cmake.org
> Subject: Re: [CMake] Rediscovering the compiler.
> 
> On Dec 3, 2007 7:35 AM, Bill Hoffman <bill.hoffman at kitware.com> wrote:
> >
> > No, there is no way currently in cmake to switch compilers once
> picked...
> 
> Which I think is a good thing.  It would drive me nuts if I couldn't
> count on the compiler choice as an invariant.

Maybe, but there's something to be said for "Tools not Policy".

The good reasons I have for wanting to change the compiler without
rebuilding the build tree from scratch of course should not break the
default policy, which quite clearly should be what you say.

I'm sure thinks will get much better for me once the next version of
cmake is released with native cross compiler support.  Alas it wasn't
there when I started using 2.4.7, and so I've had to glue this together
myself.

For interest this is what we're doing.  We have a number of
configurations and platforms, each platform with its own compiler tool
chain.  All of the configurations are described in the top level
CMakeLists.txt file like so:

	#=======================================
	# Win32 : RELEASE_WIN32 and DEBUG_WIN32
	#=======================================

	COMPILER_FLAG(WIN32_FLAGS "/D WIN32")		# Compilation on
a win32 box
	COMPILER_FLAG(WIN32_FLAGS "/EHsc")		# C++ exception
handling
	COMPILER_FLAG(WIN32_FLAGS "/arch:SSE2")		# Create SSE2
code (x64 only)
	COMPILER_FLAG(WIN32_FLAGS "/fp:fast")		# Floating point
handling
	COMPILER_FLAG(WIN32_FLAGS "/W3")		# Warning level
	COMPILER_FLAG(WIN32_FLAGS "/Wp64")		# Detect 64 bit
portability issues
	COMPILER_FLAG(WIN32_FLAGS "/Zi")		# Debug format
is 'Program Database'
	LINKER_FLAG(WIN32_LINK_FLAGS "")		# Put linker
flags here.
	
	COMPILER_FLAG(RELEASE_WIN32_FLAGS "/O2")	# Creates fast
code
	COMPILER_FLAG(RELEASE_WIN32_FLAGS "/D NDEBUG")	# Not DEBUG code
	COMPILER_FLAG(RELEASE_WIN32_FLAGS "/MT")	# Multithreaded
code
	ADD_CONFIGURATION(RELEASE WIN32 "${WIN32_FLAGS}
${RELEASE_WIN32_FLAGS}" "${WIN32_LINK_FLAGS}")
	
	COMPILER_FLAG(DEBUG_WIN32_FLAGS "/Od")		# Disable
optimisation
	COMPILER_FLAG(DEBUG_WIN32_FLAGS "/D _DEBUG")	# DEBUG Code
	COMPILER_FLAG(DEBUG_WIN32_FLAGS "/D GEO_DEBUG")	# Geomerics
Debug code
	COMPILER_FLAG(DEBUG_WIN32_FLAGS "/MTd")		# Multithreaded
debug code
	COMPILER_FLAG(DEBUG_WIN32_FLAGS "/RTC1")	# Enable
run-time error checking
	ADD_CONFIGURATION(DEBUG WIN32 "${WIN32_FLAGS}
${DEBUG_WIN32_FLAGS}" "${WIN32_LINK_FLAGS}")
	
	
	#=============================================
	# XBOX360 : RELEASE_XBOX360 and DEBUG_XBOX360
	#=============================================
	
	COMPILER_FLAG(XBOX360_FLAGS "/D _XBOX")		# Compilation on
an XBOX360
	COMPILER_FLAG(XBOX360_FLAGS "/D XBOX")		# Compilation on
an XBOX360
	COMPILER_FLAG(XBOX360_FLAGS "/EHsc")		# C++ exception
handling
	COMPILER_FLAG(XBOX360_FLAGS "/W3")		# Warning level
	
	COMPILER_FLAG(RELEASE_XBOX360_FLAGS "/O2")	# Creates fast
code
	COMPILER_FLAG(RELEASE_XBOX360_FLAGS "/D NDEBUG")# Not DEBUG code
	COMPILER_FLAG(RELEASE_XBOX360_FLAGS "/MT")	# Multithreaded
code
	ADD_CONFIGURATION(RELEASE XBOX360 "${XBOX360_FLAGS}
${RELEASE_XBOX360_FLAGS}" "")
	
	COMPILER_FLAG(DEBUG_XBOX360_FLAGS "/Od")	# Disable
optimisation
	COMPILER_FLAG(DEBUG_XBOX360_FLAGS "/D _DEBUG")	# DEBUG Code
	COMPILER_FLAG(DEBUG_XBOX360_FLAGS "/D GEO_DEBUG")# Geomerics
Debug code
	COMPILER_FLAG(DEBUG_XBOX360_FLAGS "/MTd")	# Multithreaded
debug code
	COMPILER_FLAG(DEBUG_XBOX360_FLAGS "/RTC1")	# Enable
run-time error checking
	COMPILER_FLAG(DEBUG_XBOX360_FLAGS "/Zi")	# Generates
complete debug information
	ADD_CONFIGURATION(DEBUG XBOX360 "${XBOX360_FLAGS}
${DEBUG_XBOX360_FLAGS}" "")
	
	
	#=================================
	# PS3 : RELEASE_PS3 and DEBUG_PS3
	#=================================

	COMPILER_FLAG(PS3_FLAGS "-D__GCC__")		# It's a GNU
compiler
	COMPILER_FLAG(PS3_FLAGS "-DPLATFORM_PS3")	# NB: only
required for LuaPlus
	COMPILER_FLAG(PS3_FLAGS "-DSN_TARGET_PS3")	# PS3 build
	COMPILER_FLAG(PS3_FLAGS "-Wall")		# All warnings
	COMPILER_FLAG(PS3_FLAGS "-fno-exceptions")	# No exception
handlers
	COMPILER_FLAG(PS3_FLAGS "-fno-strict-aliasing")	# No strict
aliasing

	COMPILER_FLAG(RELEASE_PS3_FLAGS "-O2")		# Optimisation
	ADD_CONFIGURATION(RELEASE PS3 "${PS3_FLAGS}
${RELEASE_PS3_FLAGS}" "")

	COMPILER_FLAG(RELEASE_PS3_FLAGS "-O")		# Disable
optimisation
	COMPILER_FLAG(DEBUG_PS3_FLAGS "-g")		# Include symbol
tables
	COMPILER_FLAG(DEBUG_PS3_FLAGS "-DGEO_DEBUG")	# Debug build
	ADD_CONFIGURATION(DEBUG PS3 "${PS3_FLAGS} ${DEBUG_PS3_FLAGS}"
"")


When cmake is run the top level cmake spawns a cmake for each of the
configurations and makes several 'make' build trees which self manage.

It also makes a visual studio build tree, which generates (via a few
patches to cmake) external Make vcproj files (using VCNMakeTools) which
execute make commands in the right place.   This allows us to use visual
studio as the development platform, but still have full control over the
build configurations.  The ZERO_CHECK rules rebuild the project and
solution files only, and the per-configuration sub-build trees manage
themselves (with copious additionally 'make depend's run when
necessary).

There were a couple of reasons why we adopted this approach.  We wanted
a single CMakeList infrastructure to deal with our entire source base
and all platforms.  Both XBox and PS3 were integrated in non-orthogonal
ways into Visual Studio and in ways that CMake didn't support, and CMake
2.4.7 didn't allow us to make multiple platform visual studio files.

Maybe 2.5 or 2.6 will give us more flexibility, however what we have
right now works pretty well.

Joe

p.s. none of this explains why the compilers needed to be changed
without rebuilding! :)  That's an entirely separate issue to do with the
fact that we made a transition of put putting the compilers and SDK
headers and libraries into our source repository (SVN) and I wanted to
get the developers build trees to transparently reconfigure without
unnecessarily blowing away their pre-built trees and forcing them to
individually recompile everything - a sizable amount of unnecessary
waiting time for a large team of developers approaching a deadline!


More information about the CMake mailing list