通过 CMake 在 Xcode 4.2 项目中使用 C++0x
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7879630/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using C++0x in Xcode 4.2 project via CMake
提问by Gerald
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:
我正在使用 CMake 在 OSX Lion 上为 Xcode 4.2 生成项目文件,并且我在 LLVM 中使用了一些 C++0x 功能,如 nullptr 和 auto。为了使用这些,Xcode 需要设置 2 个项目设置:
C++ Language Dialect set to C++0x [-std=C++0x]
C++ 语言方言设置为 C++0x [-std=C++0x]
C++ Standard Library set to libc++ (LLVM C++ standard library with C++'0X support)
C++ 标准库设置为 libc++(支持 C++'0X 的 LLVM C++ 标准库)
Currently every time I generate an Xcode project, I have to go in and manually adjust these settings.
目前每次生成Xcode项目,都得进去手动调整这些设置。
Is there a way to specify these settings in CMake?
有没有办法在 CMake 中指定这些设置?
Thanks
谢谢
回答by moka
after digging into this for a little, these are the commands to set the appropriate xcode settings:
在深入研究之后,这些是设置适当 xcode 设置的命令:
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.
我认为设置 c++ 标志是多余的,所以它也可能在没有最后一行的情况下工作。
hope that helps!
希望有帮助!
回答by scooterman
The first one you could change the CMAKE_CXX_FLAGS attribute and add it: SET(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=C++0x")
第一个您可以更改 CMAKE_CXX_FLAGS 属性并添加它: 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
至于选择 GCC 而不是 Clang,你必须使用类似的东西: 使用 CMake 在 GCC 和 Clang/LLVM 之间切换
That will override the CLang default values to use GCC
这将覆盖 CLang 默认值以使用 GCC