title: Clang Apple C++11 correct setup for CMake
body: <p>I am trying to configure CMake to compile for OS X Target.This is IMac with OS X Yosemite v 10.10.2</p>
  
  <p>Clang version:</p>
  
  <p>Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)</p>
  
  <p>Target: x86_64-apple-darwin14.1.0</p>
  
  <p>When I compile without putting any compiler flags I am getting one error for this chunk of code in one the sources:</p>
  
  <pre><code> static const char* LogLevelStr[] {
       "TRACE  " ,
       "INFO   " ,
       "WARNING" ,
       "ERROR  " ,
       "FATAL  " ,
  };
  </code></pre>
  
  <blockquote>
    <p>error: definition of variable with array type needs an
          explicit size or an initializer</p>
  </blockquote>
  
  <p>I am compiling this code on Windows and GCC and it is completely fine so I don't understand why Clang complains here.So I decided,maybe I have to set C++11 support flags because I use this standard in the code a lot.</p>
  
  <p>Setting </p>
  
  <pre><code>set (CMAKE_CXX_STANDARD 11)
  </code></pre>
  
  <p>or</p>
  
  <pre><code>set(CMAKE_CXX_FLAGS " -std=c++11")
  </code></pre>
  
  <p>Adds even more  weird errors like these:</p>
  
  <blockquote>
    <p>/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__bit_reference:51:52:
    error: 
          expected ';' at end of declaration list
        _LIBCPP_INLINE_VISIBILITY operator bool() const _NOEXCEPT
                                                       ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__bit_reference:87:57:
    error: 
          expected ';' at end of declaration swap(__bit_reference&lt;_Cp> __x, __bit_reference&lt;_Cp> __y) _NOEXCEPT
                                                            ^ >/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolc>hain/usr/bin/../include/c++/v1/__bit_reference:87:58:
    error: 
          C++ requires a type specifier for all declarations >swap(__bit_reference&lt;_Cp> __x, __bit_reference&lt;_Cp> __y) _NOEXCEPT
                                                             ^ >/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config:338:21:
    note: 
          expanded from macro '_NOEXCEPT'
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__bit_reference:89:10:
    error: 
          expected '(' for function-style cast or type construction
        bool __t = __x;
        ~~~~ ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__bit_reference:92:2:
    error: 
          expected ';' after top level declarator }  ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__bit_reference:1111:47:
    error: 
          expected ';' at end of declaration list
        _LIBCPP_INLINE_VISIBILITY __bit_iterator() _NOEXCEPT</p>
  </blockquote>
  
  <p>The error block from above the compiler spits at the point it is trying to parse  include</p>
  
  <p>Now,I tried also to set:</p>
  
  <pre><code>set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++") 
  </code></pre>
  
  <p>Same errors.</p>
  
  <p>What do I miss here?   </p>
  
  <p>UPDATE:</p>
  
  <p>I don't understand why some people marked this question for closing.Anyway,here is the problem in more details.I tried all those C++11 flags.I also added '=' to that static array.But most of the errors come after that.And it looks like root of those is  .At the very first place where  gets parsed it goes down into another class called __bit_reference and there at line 51 the compiler complains
  on the following line 
   _LIBCPP_INLINE_VISIBILITY operator bool() const _NOEXCEPT   </p>
  
  <blockquote>
    <p>/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__bit_reference:51:52:
    Expected ';' at end of declaration list</p>
  </blockquote>
  
  <p>Most of the other errors are also in some ways connected to stl containers.</p>
  
  <p>So my question is still valid.How do I get my source code to compile with the latest Clang on OS X including C++11 support.I am trying  to do that with Xcode and have the same issues.</p>
  
  <p>Xcode compiler output(some of it):</p>
  
  <blockquote>
    <p>CompileC
    /Users/michaeliv/Library/Developer/Xcode/DerivedData/xxxxxTest-hdkkzwyyppywsjgmoyuphranqtok/Build/Intermediates/xxxxxxTest.build/Debug/xxxxxxTest.build/Objects-normal/x86_64/XXXMath.o
    /Users/XXXXXXX/Documents/XXXXX/xxxxxx/src/XXXMath.cpp normal x86_64
    c++ com.apple.compilers.llvm.clang.1_0.compiler
        cd /Users/xxxxxx/Desktop/xxxxTest
        export LANG=en_US.US-ASCII
        /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
    -x c++ -arch x86_64 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu++11 -stdlib=libc++ ....</p>
  </blockquote>