[CMake] Chasing up: XCode 3.2.4 and CMake 2.8.2, setting GCC version to 4.0

Michael Wild themiwi at gmail.com
Tue Jan 4 10:27:09 EST 2011


Hi John

You shouldn't rely on CMAKE_SIZEOF_VOID_P anyway; it's deadly when you
try to build a universal binary. Much better to use the CheckTypeSize
module with which you can do the following:

include(CheckTypeSize)
check_type_size("void*" SIZEOF_VOID_P)
if(SIZEOF_VOID_P STREQUAL "")
  message(SEND_ERROR "Failed to determine sizeof(void*)")
endif()
configure_file(config.h.in {CMAKE_BINARY_DIR}/config.h @ONLY)


where config.h.in might look like this:

#ifndef CONFIG_H
#define CONFIG_H

/* defines SIZEOF_VOID_P to sizeof(void*) depending
   on the architecture */
@SIZEOF_VOID_P_CODE@

#endif

Then include config.h in all the sources where you need to know the size
of void*. Try NOT to include it in other headers, at least not in
headers that get installed as part of a development package. If you
must, give it a more unique name and make the names of the defines
unique such that they don't conflict with other config.h from other
packages.

This should work across all platforms supported by CMake and also work
if CMAKE_OSX_ARCHITECTURES is set to e.g. "i386;x86_64".

HTH

Michael

On 01/04/2011 03:59 PM, John Clayton wrote:
> I have a solution for the problem of creating XCode 3.2.x project on a 10.6 
> machine that are to target the 10.4u SDK.
> 
> Here's what I did (thanks to the OGRE and Open Scene Graph projects - which 
> exposed me to this solution).
> 
> WARNING: my solution assumes a 32 bit build, so here goes:
> 
> Here's how: put this right at the top of the CMakeLists.txt - in my case, the 
> very top level one.
> 
> if (APPLE)
> # Force gcc <= 4.0 on Mac OS X because 4.2 is not supported prior to Mac OS X 10.5
> include(CMakeForceCompiler)
> CMAKE_FORCE_C_COMPILER(gcc-4.0 GNU)
> CMAKE_FORCE_CXX_COMPILER(g++-4.0 GNU)
> SET(CMAKE_SIZEOF_VOID_P 4)
> endif ()
> 
> set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "4.0")
> 
> 
> so, what's it do??
> 
> the FORCE_C_COMPILER stuff is going to ensure that the 4.0 series GCC compiler 
> is picked up, which is really useful when the compiler-test phases of cmake get 
> run. What isn't obvious though is that when this is done, some tests the ptr 
> size are NOT carried out any longer, which impacted our project - so here's the 
> caveat: I'm forcing the CMAKE_SIZEOF_VOID_P to 4, which means the rest of our 
> codebase goes with a 32 bit build. For me, not a problem - for you - good luck :-)
> 
> The CMAKE_XCODE_ATTRIBUTE_GCC_VERSION is *also* required. This forces the 
> GCC_VERSION attribute within the xcode configuration to be 4.0 instead of 4.2 
> (assuming build platform of 10.6).
> 
> Take note; if you leave the CMAKE_XCODE_ATTRIBUTE_GCC_VERSION out - then the 
> Xcode GCC version will *still be 4.2* - so you need both of these settings in 
> the CMakeLists.txt file.
> 
> If anyone can improve on this - I'd appreciate it, thanks for all your help and 
> good luck with those 10.4u builds from a 10.6.x machine!
> 
> 
> 
> 
> John Clayton
>
> On 03.01.2011, at 14:36, John Clayton wrote:
> 
>> Hi All,
>>
>> i'm still having problems getting the CMAKE_XCODE_ATTRIBUTE_GCC_VERSION flag 
>> to properly force the compiler version I want to use for my project.
>>
>> I'm using XCode 3.2.5, on a Mac 10.6.3 machine - trying to target a Max OS X 
>> Tiger 10.4u build. I get compiler errors because the gcc-4.2 compiler is being 
>> used in the compiler-test stage of CMake.
>>
>> I thought CMAKE_XCODE_ATTRIBUTE_GCC_VERSION could be used to force the 
>> compiler setting to 4.0?
>>
>> My top level CMakeLists.txt file has this as its first few lines - is this the 
>> correct way to use this option?
>>
>> PROJECT( FileWave )
>> cmake_minimum_required(VERSION 2.6)
>> set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "4.0")
>>
>> The error I get after running an XCode based generator is:
>> -- The C compiler identification is GNU
>> -- The CXX compiler identification is GNU
>> -- Checking whether C compiler has -isysroot
>> -- Checking whether C compiler has -isysroot - yes
>> -- Checking whether C compiler supports OSX deployment target flag
>> -- Checking whether C compiler supports OSX deployment target flag - yes
>> -- Check for working C compiler using: Xcode
>> -- Check for working C compiler using: Xcode -- broken
>> CMake Error at /Users/john/CMake/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
>> The C compiler "/usr/bin/gcc-4.0" is not able to compile a simple test
>> program.
>>
>> It fails with the following output:
>>
>> Change Dir: /Users/john/src/TRUNK/BuildSystem/Xcode/CMakeFiles/CMakeTmp
>>
>>
>> Run Build Command:/Users/john/CMake/bin/cmakexbuild -project
>> CMAKE_TRY_COMPILE.xcodeproj build -target cmTryCompileExec -configuration
>> Debug
>>
>>
>> === BUILD NATIVE TARGET cmTryCompileExec OF PROJECT CMAKE_TRY_COMPILE WITH
>> CONFIGURATION Debug ===
>>
>> Check dependencies
>>
>> GCC 4.2 is not compatible with the Mac OS X 10.4 SDK (file testCCompiler.c)
>>
>> GCC 4.2 is not compatible with the Mac OS X 10.4 SDK (file testCCompiler.c)
>>
>> ** BUILD FAILED **
>>
>>
>>
>> <pastedGraphic.tiff>
>>
>>
>>
>> John Clayton
>>




More information about the CMake mailing list