[CMake] set(CMAKE_CXX_STANDARD 11) on macos - "...CMake does not know the compile flags to use to enable it."

Laurent Demailly ldemailly at fb.com
Wed Jan 14 23:33:31 EST 2015


Hi all,

I have a very simple CMakeLists.txt – am using cmake 3.1 to be able to easily request C++ 11 – it works fine on ubuntu but not on MacOS with Xcode 6 and command line tools installed:

$ cat CMakeLists.txt
cmake_minimum_required(VERSION 3.1)

project("Test1" C CXX)

# We need C++ 11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED on)

file(WRITE test1.cpp "int main(int argc, char** argv) {auto x=argc; return x;}")

add_executable(test1 test1.cpp)

$ cmake31 .
-- The C compiler identification is AppleClang 6.0.0.6000056
-- The CXX compiler identification is AppleClang 6.0.0.6000056
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
CMake Error in CMakeLists.txt:
  Target "test1" requires the language dialect "CXX11" (with compiler
  extensions), but CMake does not know the compile flags to use to enable it.


This is with
CXX=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
CXXFLAGS="-std=c++11"
But same without that


Any idea why Cmake complains and how to not make it complain ?


Help/pointer greatly appreciated

Thanks
Laurent


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150115/9791b3ca/attachment.html>


More information about the CMake mailing list