title: The CXX compiler identification is unknown: xcode
body: <p>I am trying to install an external library into my C++ project using <code>Cmake</code>. I want the <code>Xcode</code> project to be produced with that library. In my terminal i run the following from the build directory:</p>
  
  <pre><code>cmake -G Xcode ..
  </code></pre>
  
  <p>and that gives me the following errors:</p>
  
  <pre><code>-- The CXX compiler identification is unknown
  -- The C compiler identification is unknown
  CMake Error at CMakeLists.txt:6 (project):
  No CMAKE_CXX_COMPILER could be found.
  
  CMake Error at CMakeLists.txt:6 (project):
    No CMAKE_C_COMPILER could be found.
  </code></pre>
  
  <p>I am using g++ compiler:</p>
  
  <pre><code> Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
      Apple LLVM version 7.0.0 (clang-700.1.76)
      Target: x86_64-apple-darwin14.5.0
      Thread model: posix
  </code></pre>
  
  <p>Edit: CMakeLists.txt file</p>
  
  <pre><code>file(READ "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" PROJECT_VERSION_FULL)
  string(REGEX REPLACE "[\n\r]" "" PROJECT_VERSION_FULL "${PROJECT_VERSION_FULL}")
  string(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+$" "\\1" PROJECT_VERSION_MAJOR "${PROJECT_VERSION_FULL}")
  string(REGEX REPLACE "^[0-9]+\\.([0-9]+)\\.[0-9]+$" "\\1" PROJECT_VERSION_MINOR "${PROJECT_VERSION_FULL}")
  string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+)$" "\\1" PROJECT_VERSION_PATCH "${PROJECT_VERSION_FULL}")
  set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
  math(EXPR LIBRARY_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
  set(LIBRARY_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
  set(LIBRARY_VERSION_PATCH "${PROJECT_VERSION_PATCH}")
  set(LIBRARY_VERSION "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}")
  set(LIBRARY_VERSION_FULL "${LIBRARY_VERSION}.${LIBRARY_VERSION_PATCH}")
  
  
  option(CODE_COVERAGE "Set ON to add code coverage compile options" OFF)
  option(GENERATE_DOC "Set ON to genrate doxygen API reference in build/doc directory" OFF)
  
  # C++11 compiler Check
  if(NOT CMAKE_CXX_COMPILER_VERSION) # work around for cmake versions smaller than 2.8.10
      execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE CMAKE_CXX_COMPILER_VERSION)
  endif()
  if(CMAKE_CXX_COMPILER MATCHES ".*clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
        set(CMAKE_COMPILER_IS_CLANGXX 1)
  endif()
  if( (CMAKE_COMPILER_IS_GNUCXX AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 4.7) OR
      (CMAKE_COMPILER_IS_CLANGXX AND ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 3.2))
    message(FATAL_ERROR "Your C++ compiler does not support C++11. Please install g++ 4.7 (or greater) or clang 3.2 (or greater)")
  else()
    message(STATUS "Compiler is recent enough to support C++11.")
  endif()
  
  if( CMAKE_COMPILER_IS_GNUCXX )
      append_cxx_compiler_flags("-std=c++11 -Wall -Wextra  -DNDEBUG" "GCC" CMAKE_CXX_FLAGS)
      append_cxx_compiler_flags("-O3 -ffast-math -funroll-loops" "GCC" CMAKE_CXX_OPT_FLAGS)
      if ( CODE_COVERAGE )
          append_cxx_compiler_flags("-g -fprofile-arcs -ftest-coverage -lgcov" "GCC" CMAKE_CXX_FLAGS)
      endif()
  
  else()
      if(MSVC)
          append_cxx_compiler_flags("/EHsc" "MSVC" CMAKE_CXX_FLAGS)
          append_cxx_compiler_flags("/Od" "MSVC" CMAKE_CXX_FLAGS_DEBUG)
          append_cxx_compiler_flags("/Ox" "MSVC" CMAKE_CXX_FLAGS_RELEASE)
          set(vars CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
          foreach(var ${vars})
              string(REPLACE "/MD" "-MT" ${var} "${${var}}")
          endforeach(var)
  
          add_definitions("/DMSVC_COMPILER")
      else()
          append_cxx_compiler_flags("-std=c++11 -DNDEBUG" "CLANG" CMAKE_CXX_FLAGS)
          append_cxx_compiler_flags("-stdlib=libc++" "CLANG" CMAKE_CXX_FLAGS)
          append_cxx_compiler_flags("-O3 -ffast-math -funroll-loops" "CLANG" CMAKE_CXX_OPT_FLAGS)
      endif()
  endif()
  </code></pre>
  
  <p>Also CMakeEdit.log:</p>
  
  <pre><code>Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
  Compiler:  
  Build flags: 
  Id flags: 
  
  The output was:
  1
  xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
  
  
  Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
  Compiler:  
  Build flags: 
  Id flags: 
  
  The output was:
  1
  xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>This problem happens when xcode-select developer directory was pointing to /Library/Developer/CommandLineTools, when a full regular XCode was required (happens when CLT are installed after XCode).</p>
  
  <p>I have found the solution to be this:</p>
  
  <pre><code>sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
  </code></pre>
  
  <p>After this being done, when I run <code>cmake -G Xcode ..</code> I get other errors:</p>
  
  <pre><code>-- The CXX compiler identification is AppleClang 7.0.0.7000176
  -- The C compiler identification is AppleClang 7.0.0.7000176
  CMake Error at /usr/local/Cellar/cmake/3.4.0/share/cmake/Modules/Platform/Darwin.cmake:76 (message):
    CMAKE_OSX_DEPLOYMENT_TARGET is '10.10' but CMAKE_OSX_SYSROOT:
  
     ""
  
    is not set to a MacOSX SDK with a recognized version.  Either set
    CMAKE_OSX_SYSROOT to a valid SDK or set CMAKE_OSX_DEPLOYMENT_TARGET to
    empty.
  Call Stack (most recent call first):
    /usr/local/Cellar/cmake/3.4.0/share/cmake/Modules/CMakeSystemSpecificInformation.cmake:36 (include)
    CMakeLists.txt:6 (project)
  </code></pre>
  
  <p><strong>EDIT 2</strong>
  Looks like the SDK specified by the OS is wrong.</p>
  
  <pre><code>CMAKE_OSX_DEPLOYMENT_TARGET is '10.10' but the matching SDK does not exist
    at:
  
     "/Applications/DEV/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk"
  
    Instead using SDK:
  
     "/Applications/DEV/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk".
  Call Stack (most recent call first):
    /usr/local/Cellar/cmake/3.4.0/share/cmake/Modules/CMakeSystemSpecificInitialize.cmake:18 (include)
    CMakeLists.txt:6 (project)
  
  
  -- The CXX compiler identification is AppleClang 7.0.0.7000176
  -- The C compiler identification is AppleClang 7.0.0.7000176
  CMake Error at /usr/local/Cellar/cmake/3.4.0/share/cmake/Modules/Platform/Darwin.cmake:76 (message):
    CMAKE_OSX_DEPLOYMENT_TARGET is '10.10' but CMAKE_OSX_SYSROOT:
  
     ""
  
    is not set to a MacOSX SDK with a recognized version.  Either set
    CMAKE_OSX_SYSROOT to a valid SDK or set CMAKE_OSX_DEPLOYMENT_TARGET to
    empty.
  Call Stack (most recent call first):
    /usr/local/Cellar/cmake/3.4.0/share/cmake/Modules/CMakeSystemSpecificInformation.cmake:36 (include)
    CMakeLists.txt:6 (project)
  </code></pre>