17

I'm using CMake to generate a project file for Xcode 4.2 on OSX Lion, and I'm using some of the C++0x features in LLVM like nullptr and auto. In order to use these, Xcode requires that 2 project settings be set:

C++ Language Dialect set to C++0x [-std=C++0x]

C++ Standard Library set to libc++ (LLVM C++ standard library with C++'0X support)

Currently every time I generate an Xcode project, I have to go in and manually adjust these settings.

Is there a way to specify these settings in CMake?

Thanks

R. Martinho Fernandes
  • 228,013
  • 71
  • 433
  • 510
Gerald
  • 23,011
  • 10
  • 73
  • 102
  • hi, did you find a solution to this? no matter what compiler I specify for Cmake, the xcode 4.2 project always chooses the default compiler. – moka Nov 19 '11 at 15:31

2 Answers2

24

after digging into this for a little, these are the commands to set the appropriate xcode settings:

set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvm.clang.1_0")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++0x")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -stdlib=libc++ -g -Wall")

I think setting the c++ flags is redundant, so it might also work without the last line.

hope that helps!

Austin Brunkhorst
  • 20,704
  • 6
  • 47
  • 61
moka
  • 4,353
  • 2
  • 37
  • 63
1

The first one you could change the CMAKE_CXX_FLAGS attribute and add it: SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=C++0x")

As for selecting GCC instead of Clang you'll have to use something like: Switching between GCC and Clang/LLVM using CMake

That will override the CLang default values to use GCC

Community
  • 1
  • 1
scooterman
  • 1,336
  • 2
  • 17
  • 36