From 33a60e6bd148479c63734286417f582444bf36b6 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 21 Sep 2012 08:47:02 -0400 Subject: [PATCH 01/11] Xcode: Remove unused code reading CMAKE_OSX_SYSROOT_DEFAULT The condition for entering the block where the value is used can never be true anymore. --- Source/cmGlobalXCodeGenerator.cxx | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index e8ab38fe1..5fdfcf8f0 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -3118,18 +3118,14 @@ void cmGlobalXCodeGenerator const char* sysroot = this->CurrentMakefile->GetDefinition("CMAKE_OSX_SYSROOT"); - const char* sysrootDefault = - this->CurrentMakefile->GetDefinition("CMAKE_OSX_SYSROOT_DEFAULT"); const char* deploymentTarget = this->CurrentMakefile->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET"); if(osxArch && sysroot) { - bool flagsUsed = false; // recompute this as it may have been changed since enable language this->Architectures.clear(); cmSystemTools::ExpandListArgument(std::string(osxArch), this->Architectures); - flagsUsed = true; buildSettings->AddAttribute("SDKROOT", this->CreateString(sysroot)); std::string archString; @@ -3144,12 +3140,6 @@ void cmGlobalXCodeGenerator } buildSettings->AddAttribute("ARCHS", this->CreateString(archString.c_str())); - if(!flagsUsed && sysrootDefault && - strcmp(sysroot, sysrootDefault) != 0) - { - buildSettings->AddAttribute("SDKROOT", - this->CreateString(sysroot)); - } } if(deploymentTarget && *deploymentTarget) { From a0a0877a1eb111d37ac4766a368206e73458489e Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 21 Sep 2012 08:53:42 -0400 Subject: [PATCH 02/11] OS X: Always generate -isysroot if any SDK is in use Drop the last use of CMAKE_OSX_SYSROOT_DEFAULT. Replace internal platform variable CMAKE_${lang}_HAS_ISYSROOT with a more general CMAKE_${lang}_SYSROOT_FLAG variable. If the -isysroot flag exists and CMAKE_OSX_SYSROOT points to an SDK (not "/") then always add it to compiler command lines. This is already done in the Xcode IDE. --- Modules/CMakeCCompiler.cmake.in | 2 +- Modules/CMakeCXXCompiler.cmake.in | 2 +- Modules/CMakeFindPackageMode.cmake | 4 +-- Modules/Platform/Darwin-Clang.cmake | 2 +- Modules/Platform/Darwin-GNU-C.cmake | 2 +- Modules/Platform/Darwin-GNU-CXX.cmake | 2 +- Modules/Platform/Darwin-GNU.cmake | 9 +++--- Source/cmLocalGenerator.cxx | 44 ++++++++++----------------- 8 files changed, 28 insertions(+), 39 deletions(-) diff --git a/Modules/CMakeCCompiler.cmake.in b/Modules/CMakeCCompiler.cmake.in index 17d63ebab..d74dcdcee 100644 --- a/Modules/CMakeCCompiler.cmake.in +++ b/Modules/CMakeCCompiler.cmake.in @@ -45,7 +45,7 @@ if(CMAKE_C_LIBRARY_ARCHITECTURE) set(CMAKE_LIBRARY_ARCHITECTURE "@CMAKE_C_LIBRARY_ARCHITECTURE@") endif() -set(CMAKE_C_HAS_ISYSROOT "@CMAKE_C_HAS_ISYSROOT@") +@CMAKE_C_SYSROOT_FLAG_CODE@ @CMAKE_C_OSX_DEPLOYMENT_TARGET_FLAG_CODE@ set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "@CMAKE_C_IMPLICIT_LINK_LIBRARIES@") diff --git a/Modules/CMakeCXXCompiler.cmake.in b/Modules/CMakeCXXCompiler.cmake.in index 7f66be506..8c5d84e6c 100644 --- a/Modules/CMakeCXXCompiler.cmake.in +++ b/Modules/CMakeCXXCompiler.cmake.in @@ -46,7 +46,7 @@ if(CMAKE_CXX_LIBRARY_ARCHITECTURE) set(CMAKE_LIBRARY_ARCHITECTURE "@CMAKE_CXX_LIBRARY_ARCHITECTURE@") endif() -set(CMAKE_CXX_HAS_ISYSROOT "@CMAKE_CXX_HAS_ISYSROOT@") +@CMAKE_CXX_SYSROOT_FLAG_CODE@ @CMAKE_CXX_OSX_DEPLOYMENT_TARGET_FLAG_CODE@ set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "@CMAKE_CXX_IMPLICIT_LINK_LIBRARIES@") diff --git a/Modules/CMakeFindPackageMode.cmake b/Modules/CMakeFindPackageMode.cmake index c9f58e3f3..cea018706 100644 --- a/Modules/CMakeFindPackageMode.cmake +++ b/Modules/CMakeFindPackageMode.cmake @@ -53,8 +53,8 @@ include(CMakeDetermineSystem) # short-cut some tests on Darwin, see Darwin-GNU.cmake: if("${CMAKE_SYSTEM_NAME}" MATCHES Darwin AND "${COMPILER_ID}" MATCHES GNU) - set(${CMAKE_${LANGUAGE}_HAS_ISYSROOT} 0 ) - set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "") + set(CMAKE_${LANGUAGE}_SYSROOT_FLAG "") + set(CMAKE_${LANGUAGE}_OSX_DEPLOYMENT_TARGET_FLAG "") endif() # Also load the system specific file, which sets up e.g. the search paths. diff --git a/Modules/Platform/Darwin-Clang.cmake b/Modules/Platform/Darwin-Clang.cmake index 46f06f768..de7a85636 100644 --- a/Modules/Platform/Darwin-Clang.cmake +++ b/Modules/Platform/Darwin-Clang.cmake @@ -21,6 +21,6 @@ set(__DARWIN_COMPILER_CLANG 1) macro(__darwin_compiler_clang lang) set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-dynamiclib -Wl,-headerpad_max_install_names") set(CMAKE_SHARED_MODULE_CREATE_${lang}_FLAGS "-bundle -Wl,-headerpad_max_install_names") + set(CMAKE_${lang}_SYSROOT_FLAG "-isysroot") set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "-mmacosx-version-min=") - set(CMAKE_${lang}_HAS_ISYSROOT 1) endmacro() diff --git a/Modules/Platform/Darwin-GNU-C.cmake b/Modules/Platform/Darwin-GNU-C.cmake index 4e326c4ca..efdfd0014 100644 --- a/Modules/Platform/Darwin-GNU-C.cmake +++ b/Modules/Platform/Darwin-GNU-C.cmake @@ -1,4 +1,4 @@ include(Platform/Darwin-GNU) __darwin_compiler_gnu(C) -cmake_gnu_has_isysroot(C) +cmake_gnu_set_sysroot_flag(C) cmake_gnu_set_osx_deployment_target_flag(C) diff --git a/Modules/Platform/Darwin-GNU-CXX.cmake b/Modules/Platform/Darwin-GNU-CXX.cmake index b39487e58..e3c2ea7c5 100644 --- a/Modules/Platform/Darwin-GNU-CXX.cmake +++ b/Modules/Platform/Darwin-GNU-CXX.cmake @@ -1,4 +1,4 @@ include(Platform/Darwin-GNU) __darwin_compiler_gnu(CXX) -cmake_gnu_has_isysroot(CXX) +cmake_gnu_set_sysroot_flag(CXX) cmake_gnu_set_osx_deployment_target_flag(CXX) diff --git a/Modules/Platform/Darwin-GNU.cmake b/Modules/Platform/Darwin-GNU.cmake index 5e9f8f096..d9535039f 100644 --- a/Modules/Platform/Darwin-GNU.cmake +++ b/Modules/Platform/Darwin-GNU.cmake @@ -24,8 +24,8 @@ macro(__darwin_compiler_gnu lang) set(CMAKE_SHARED_MODULE_CREATE_${lang}_FLAGS "-bundle -Wl,-headerpad_max_install_names") endmacro() -macro(cmake_gnu_has_isysroot lang) - if("x${CMAKE_${lang}_HAS_ISYSROOT}" STREQUAL "x") +macro(cmake_gnu_set_sysroot_flag lang) + if(NOT DEFINED CMAKE_${lang}_SYSROOT_FLAG) set(_doc "${lang} compiler has -isysroot") message(STATUS "Checking whether ${_doc}") execute_process( @@ -35,11 +35,12 @@ macro(cmake_gnu_has_isysroot lang) ) if("${_gcc_help}" MATCHES "isysroot") message(STATUS "Checking whether ${_doc} - yes") - set(CMAKE_${lang}_HAS_ISYSROOT 1) + set(CMAKE_${lang}_SYSROOT_FLAG "-isysroot") else() message(STATUS "Checking whether ${_doc} - no") - set(CMAKE_${lang}_HAS_ISYSROOT 0) + set(CMAKE_${lang}_SYSROOT_FLAG "") endif() + set(CMAKE_${lang}_SYSROOT_FLAG_CODE "set(CMAKE_${lang}_SYSROOT_FLAG \"${CMAKE_${lang}_SYSROOT_FLAG}\")") endif() endmacro() diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index cf2af0a4f..f2bced42d 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1792,46 +1792,34 @@ void cmLocalGenerator::AddArchitectureFlags(std::string& flags, { std::vector archs; target->GetAppleArchs(config, archs); - const char* sysroot = - this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT"); - const char* sysrootDefault = - this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT_DEFAULT"); + const char* sysroot = this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT"); + if(sysroot && sysroot[0] == '/' && !sysroot[1]) + { sysroot = 0; } + std::string sysrootFlagVar = + std::string("CMAKE_") + lang + "_SYSROOT_FLAG"; + const char* sysrootFlag = + this->Makefile->GetDefinition(sysrootFlagVar.c_str()); const char* deploymentTarget = this->Makefile->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET"); - std::string isysrootVar = std::string("CMAKE_") + lang + "_HAS_ISYSROOT"; - bool hasIsysroot = this->Makefile->IsOn(isysrootVar.c_str()); std::string deploymentTargetFlagVar = std::string("CMAKE_") + lang + "_OSX_DEPLOYMENT_TARGET_FLAG"; const char* deploymentTargetFlag = this->Makefile->GetDefinition(deploymentTargetFlagVar.c_str()); - bool flagsUsed = false; - if(!archs.empty() && sysroot && lang && (lang[0] =='C' || lang[0] == 'F')) + if(!archs.empty() && lang && (lang[0] =='C' || lang[0] == 'F')) { - // if there is more than one arch add the -arch and - // -isysroot flags, or if there is one arch flag, but - // it is not the default -arch flag for the system, then - // add it. Otherwize do not add -arch and -isysroot - if(archs[0] != "") + for(std::vector::iterator i = archs.begin(); + i != archs.end(); ++i) { - for( std::vector::iterator i = archs.begin(); - i != archs.end(); ++i) - { - flags += " -arch "; - flags += *i; - } - if(hasIsysroot) - { - flags += " -isysroot "; - flags += sysroot; - } - flagsUsed = true; + flags += " -arch "; + flags += *i; } } - if(!flagsUsed && sysroot && sysrootDefault && - strcmp(sysroot, sysrootDefault) != 0 && hasIsysroot) + if(sysrootFlag && *sysrootFlag && sysroot && *sysroot) { - flags += " -isysroot "; + flags += " "; + flags += sysrootFlag; + flags += " "; flags += sysroot; } From 230ea218a76df931b31394998f121eb34ba8f5ff Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 21 Sep 2012 08:59:01 -0400 Subject: [PATCH 03/11] OS X: Improve default CMAKE_OSX_SYSROOT selection Simplify the search for OSX_DEVELOPER_ROOT and allow it to fail if no "/Developer" exists. When it does exist, always find a MacOSX SDK inside it to use as the default CMAKE_OSX_SYSROOT. Otherwise set CMAKE_OSX_SYSROOT to empty. --- Modules/Platform/Darwin.cmake | 83 ++++++++++++++++------------------- 1 file changed, 39 insertions(+), 44 deletions(-) diff --git a/Modules/Platform/Darwin.cmake b/Modules/Platform/Darwin.cmake index 2a5f3cf30..b160854e6 100644 --- a/Modules/Platform/Darwin.cmake +++ b/Modules/Platform/Darwin.cmake @@ -59,28 +59,18 @@ if(NOT DEFINED CMAKE_INSTALL_NAME_TOOL) mark_as_advanced(CMAKE_INSTALL_NAME_TOOL) endif() -# Set the assumed (Pre 10.5 or Default) location of the developer tools -set(OSX_DEVELOPER_ROOT "/Developer") - -# Use the xcode-select tool if it's available (Xcode >= 3.0 installations) -find_program(CMAKE_XCODE_SELECT xcode-select) -mark_as_advanced(CMAKE_XCODE_SELECT) -if(CMAKE_XCODE_SELECT) - execute_process(COMMAND ${CMAKE_XCODE_SELECT} "-print-path" - OUTPUT_VARIABLE OSX_DEVELOPER_ROOT - OUTPUT_STRIP_TRAILING_WHITESPACE) -endif() - -# Find installed SDKs -# Start with Xcode-4.3+ default SDKs directory -set(_CMAKE_OSX_SDKS_DIR - "${OSX_DEVELOPER_ROOT}/Platforms/MacOSX.platform/Developer/SDKs") -file(GLOB _CMAKE_OSX_SDKS "${_CMAKE_OSX_SDKS_DIR}/*") - -# If not present, try pre-4.3 SDKs directory -if(NOT _CMAKE_OSX_SDKS) -set(_CMAKE_OSX_SDKS_DIR "${OSX_DEVELOPER_ROOT}/SDKs") - file(GLOB _CMAKE_OSX_SDKS "${_CMAKE_OSX_SDKS_DIR}/*") +# Ask xcode-select where to find /Developer or fall back to ancient location. +execute_process(COMMAND xcode-select -print-path + OUTPUT_VARIABLE _stdout + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_VARIABLE _stderr + RESULT_VARIABLE _failed) +if(NOT _failed AND IS_DIRECTORY ${_stdout}) + set(OSX_DEVELOPER_ROOT ${_stdout}) +elseif(IS_DIRECTORY "/Developer") + set(OSX_DEVELOPER_ROOT "/Developer") +else() + set(OSX_DEVELOPER_ROOT "") endif() execute_process(COMMAND sw_vers -productVersion @@ -107,32 +97,37 @@ endif() # Environment variable set by the user overrides our default. # Use the same environment variable that Xcode uses. -set(ENV_SDKROOT "$ENV{SDKROOT}") - -# Set CMAKE_OSX_SYSROOT_DEFAULT based on _CURRENT_OSX_VERSION, -# accounting for the known specially named SDKs. -set(CMAKE_OSX_SYSROOT_DEFAULT - "${_CMAKE_OSX_SDKS_DIR}/MacOSX${_CURRENT_OSX_VERSION}.sdk") - -if(_CURRENT_OSX_VERSION STREQUAL "10.4") - set(CMAKE_OSX_SYSROOT_DEFAULT - "${_CMAKE_OSX_SDKS_DIR}/MacOSX10.4u.sdk") -endif() - -if(_CURRENT_OSX_VERSION STREQUAL "10.3") - set(CMAKE_OSX_SYSROOT_DEFAULT - "${_CMAKE_OSX_SDKS_DIR}/MacOSX10.3.9.sdk") -endif() - -# Use environment or default as initial cache value: -if(NOT ENV_SDKROOT STREQUAL "") - set(CMAKE_OSX_SYSROOT_VALUE ${ENV_SDKROOT}) +if(NOT "x$ENV{SDKROOT}" STREQUAL "x" AND EXISTS "$ENV{SDKROOT}") + set(_CMAKE_OSX_SYSROOT_DEFAULT "$ENV{SDKROOT}") else() - set(CMAKE_OSX_SYSROOT_VALUE ${CMAKE_OSX_SYSROOT_DEFAULT}) + # Find installed SDKs in either Xcode-4.3+ or pre-4.3 SDKs directory. + set(_CMAKE_OSX_SDKS_DIR "") + if(OSX_DEVELOPER_ROOT) + foreach(d Platforms/MacOSX.platform/Developer/SDKs SDKs) + file(GLOB _CMAKE_OSX_SDKS ${OSX_DEVELOPER_ROOT}/${d}/*) + if(_CMAKE_OSX_SDKS) + set(_CMAKE_OSX_SDKS_DIR ${OSX_DEVELOPER_ROOT}/${d}) + break() + endif() + endforeach() + endif() + + if(_CMAKE_OSX_SDKS_DIR) + # Select SDK for current OSX version accounting for the known + # specially named SDKs. + set(_CMAKE_OSX_SDKS_VER_SUFFIX_10.4 "u") + set(_CMAKE_OSX_SDKS_VER_SUFFIX_10.3 ".9") + set(_CMAKE_OSX_SDKS_VER ${_CURRENT_OSX_VERSION}${_CMAKE_OSX_SDKS_VER_SUFFIX_${_CURRENT_OSX_VERSION}}) + set(_CMAKE_OSX_SYSROOT_DEFAULT + "${_CMAKE_OSX_SDKS_DIR}/MacOSX${_CMAKE_OSX_SDKS_VER}.sdk") + else() + # Assume developer files are in root (such as Xcode 4.5 command-line tools). + set(_CMAKE_OSX_SYSROOT_DEFAULT "") + endif() endif() # Set cache variable - end user may change this during ccmake or cmake-gui configure. -set(CMAKE_OSX_SYSROOT ${CMAKE_OSX_SYSROOT_VALUE} CACHE PATH +set(CMAKE_OSX_SYSROOT "${_CMAKE_OSX_SYSROOT_DEFAULT}" CACHE PATH "The product will be built against the headers and libraries located inside the indicated SDK.") #---------------------------------------------------------------------------- From a1c032b99477b1cd29be0e196187c5b878d00d5f Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 21 Sep 2012 10:06:00 -0400 Subject: [PATCH 04/11] bootstrap: Suppress CMAKE_OSX_SYSROOT if CFLAGS have -isysroot In order to bootstrap on OS X with Xcode without the command line tools one must add -isysroot to CFLAGS and CXXFLAGS. In this case the flags will make it into the configured CMake. Set CMAKE_OSX_SYSROOT to empty in the initial cache to prevent CMake from adding -isysroot again. --- bootstrap | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bootstrap b/bootstrap index 23134d091..ceddfdc41 100755 --- a/bootstrap +++ b/bootstrap @@ -1505,6 +1505,14 @@ set (CMAKE_MAN_DIR "'"${cmake_man_dir}"'" CACHE PATH "Install location for man p set (CMAKE_DATA_DIR "'"${cmake_data_dir}"'" CACHE PATH "Install location for data (relative to prefix)." FORCE) ' > "${cmake_bootstrap_dir}/InitialCacheFlags.cmake" +# Suppress -isysroot if user-provided flags already have it. +if echo "${cmake_c_flags}" | grep isysroot >/dev/null 2>&1 && + echo "${cmake_cxx_flags}" | grep isysroot >/dev/null 2>&1; then + echo ' +set(CMAKE_OSX_SYSROOT "" CACHE PATH "" FORCE) +' >> "${cmake_bootstrap_dir}/InitialCacheFlags.cmake" +fi + # Add configuration settings given as command-line options. if [ "x${cmake_bootstrap_qt_gui}" != "x" ]; then echo ' From 242f673829d40456bd1bcf3f52e10171bccd6868 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 21 Sep 2012 10:34:10 -0400 Subject: [PATCH 05/11] Tests/Assembler: Use CMAKE_OSX_SYSROOT to generate .s file On OS X if the user-provided flags do not include -isysroot and CMAKE_OSX_SYSROOT is defined then add the proper -isysroot flag to the C compiler invocation we use to generate the .s file. --- Tests/Assembler/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Tests/Assembler/CMakeLists.txt b/Tests/Assembler/CMakeLists.txt index 94a6325c8..bb4bcccbe 100644 --- a/Tests/Assembler/CMakeLists.txt +++ b/Tests/Assembler/CMakeLists.txt @@ -12,6 +12,9 @@ if("${CMAKE_GENERATOR}" MATCHES "Makefile|Xcode" AND if(("${CMAKE_C_COMPILER_ID}" MATCHES "^(GNU|Clang|HP|SunPro|XL)$") OR ("${CMAKE_C_COMPILER_ID}" STREQUAL "Intel" AND UNIX)) set(C_FLAGS "${CMAKE_C_FLAGS}") separate_arguments(C_FLAGS) + if(CMAKE_OSX_SYSROOT AND CMAKE_C_SYSROOT_FLAG AND NOT ";${C_FLAGS};" MATCHES ";${CMAKE_C_SYSROOT_FLAG};") + list(APPEND C_FLAGS ${CMAKE_C_SYSROOT_FLAG} ${CMAKE_OSX_SYSROOT}) + endif() set(SRCS main.s) add_custom_command( OUTPUT main.s From 1786b121b40ca0a50a57f44e5e2edef7b9d270ed Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 21 Sep 2012 13:18:49 -0400 Subject: [PATCH 06/11] OS X: Allow CMAKE_OSX_SYSROOT to be a logical SDK name Xcode supports SDKROOT values that just name an SDK rather than specifying the full path to it. Recognize these values and handle them. For Xcode we just put the value directly in the generated project file. For Makefile generators we ask xcodebuild to provide the full path to the named SDK. Suggested-by: Jason DiCioccio --- Modules/Platform/Darwin.cmake | 37 +++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/Modules/Platform/Darwin.cmake b/Modules/Platform/Darwin.cmake index b160854e6..56f340d18 100644 --- a/Modules/Platform/Darwin.cmake +++ b/Modules/Platform/Darwin.cmake @@ -97,7 +97,8 @@ endif() # Environment variable set by the user overrides our default. # Use the same environment variable that Xcode uses. -if(NOT "x$ENV{SDKROOT}" STREQUAL "x" AND EXISTS "$ENV{SDKROOT}") +if(NOT "x$ENV{SDKROOT}" STREQUAL "x" AND + (NOT "x$ENV{SDKROOT}" MATCHES "/" OR IS_DIRECTORY "$ENV{SDKROOT}")) set(_CMAKE_OSX_SYSROOT_DEFAULT "$ENV{SDKROOT}") else() # Find installed SDKs in either Xcode-4.3+ or pre-4.3 SDKs directory. @@ -127,9 +128,41 @@ else() endif() # Set cache variable - end user may change this during ccmake or cmake-gui configure. -set(CMAKE_OSX_SYSROOT "${_CMAKE_OSX_SYSROOT_DEFAULT}" CACHE PATH +# Choose the type based on the current value. +set(_CMAKE_OSX_SYSROOT_TYPE STRING) +foreach(v CMAKE_OSX_SYSROOT _CMAKE_OSX_SYSROOT_DEFAULT) + if("x${${v}}" MATCHES "/") + set(_CMAKE_OSX_SYSROOT_TYPE PATH) + break() + endif() +endforeach() +set(CMAKE_OSX_SYSROOT "${_CMAKE_OSX_SYSROOT_DEFAULT}" CACHE ${_CMAKE_OSX_SYSROOT_TYPE} "The product will be built against the headers and libraries located inside the indicated SDK.") +# Transform the cached value to something we can use. +if(CMAKE_OSX_SYSROOT) + if("x${CMAKE_OSX_SYSROOT}" MATCHES "/") + # This is a path to the SDK. Make sure it exists. + if(NOT IS_DIRECTORY "${CMAKE_OSX_SYSROOT}") + message(WARNING "Ignoring CMAKE_OSX_SYSROOT value:\n ${CMAKE_OSX_SYSROOT}\n" + "because the directory does not exist.") + set(CMAKE_OSX_SYSROOT "") + endif() + elseif(NOT "${CMAKE_GENERATOR}" MATCHES "Xcode") + # For non-Xcode generators transform the sdk name into a path. + execute_process( + COMMAND xcodebuild -sdk ${CMAKE_OSX_SYSROOT} -version Path + OUTPUT_VARIABLE _stdout + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_VARIABLE _stderr + RESULT_VARIABLE _failed + ) + if(NOT _failed AND IS_DIRECTORY "${_stdout}") + set(CMAKE_OSX_SYSROOT "${_stdout}") + endif() + endif() +endif() + #---------------------------------------------------------------------------- function(SanityCheckSDKAndDeployTarget _sdk_path _deploy) if(_deploy STREQUAL "") From 7995722e919c66ff3aad7de73d489bf838af5426 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 21 Sep 2012 14:13:06 -0400 Subject: [PATCH 07/11] OS X: Simplify selection of CMAKE_OSX_ARCHITECTURES Incremental changes to the logic over time have led to simply initializing the cache entry with the environment value. --- Modules/Platform/Darwin.cmake | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/Modules/Platform/Darwin.cmake b/Modules/Platform/Darwin.cmake index 56f340d18..f592085d5 100644 --- a/Modules/Platform/Darwin.cmake +++ b/Modules/Platform/Darwin.cmake @@ -77,6 +77,10 @@ execute_process(COMMAND sw_vers -productVersion OUTPUT_VARIABLE CURRENT_OSX_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) +# Save CMAKE_OSX_ARCHITECTURES from the environment. +set(CMAKE_OSX_ARCHITECTURES "$ENV{CMAKE_OSX_ARCHITECTURES}" CACHE STRING + "Build architectures for OSX") + #---------------------------------------------------------------------------- # _CURRENT_OSX_VERSION - as a two-component string: 10.5, 10.6, ... # @@ -183,29 +187,6 @@ endfunction() # Make sure the combination of SDK and Deployment Target are allowed SanityCheckSDKAndDeployTarget("${CMAKE_OSX_SYSROOT}" "${CMAKE_OSX_DEPLOYMENT_TARGET}") -# set _CMAKE_OSX_MACHINE to uname -m -execute_process(COMMAND uname -m - OUTPUT_STRIP_TRAILING_WHITESPACE - OUTPUT_VARIABLE _CMAKE_OSX_MACHINE) - -# check for Power PC and change to ppc -if(_CMAKE_OSX_MACHINE MATCHES "Power") - set(_CMAKE_OSX_MACHINE ppc) -endif() - -# check for environment variable CMAKE_OSX_ARCHITECTURES -# if it is set. -if(NOT "$ENV{CMAKE_OSX_ARCHITECTURES}" STREQUAL "") - set(CMAKE_OSX_ARCHITECTURES_VALUE "$ENV{CMAKE_OSX_ARCHITECTURES}") -else() - set(CMAKE_OSX_ARCHITECTURES_VALUE "") -endif() - -# now put _CMAKE_OSX_MACHINE into the cache -set(CMAKE_OSX_ARCHITECTURES ${CMAKE_OSX_ARCHITECTURES_VALUE} CACHE STRING - "Build architectures for OSX") - - if("${CMAKE_BACKWARDS_COMPATIBILITY}" MATCHES "^1\\.[0-6]$") set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS "${CMAKE_SHARED_MODULE_CREATE_C_FLAGS} -flat_namespace -undefined suppress") From 2690738458725f2c52afccd99ee744a9b92e30ed Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 21 Sep 2012 14:25:25 -0400 Subject: [PATCH 08/11] OS X: If CMAKE_OSX_SYSROOT is already set do not compute default The default computation logic is non-trivial. Do not bother with it if the value is already known. --- Modules/Platform/Darwin.cmake | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Modules/Platform/Darwin.cmake b/Modules/Platform/Darwin.cmake index f592085d5..90d34cad8 100644 --- a/Modules/Platform/Darwin.cmake +++ b/Modules/Platform/Darwin.cmake @@ -99,10 +99,12 @@ endif() #---------------------------------------------------------------------------- # CMAKE_OSX_SYSROOT -# Environment variable set by the user overrides our default. -# Use the same environment variable that Xcode uses. -if(NOT "x$ENV{SDKROOT}" STREQUAL "x" AND - (NOT "x$ENV{SDKROOT}" MATCHES "/" OR IS_DIRECTORY "$ENV{SDKROOT}")) +if(CMAKE_OSX_SYSROOT) + # Use the existing value without further computation to choose a default. + set(_CMAKE_OSX_SYSROOT_DEFAULT "${CMAKE_OSX_SYSROOT}") +elseif(NOT "x$ENV{SDKROOT}" STREQUAL "x" AND + (NOT "x$ENV{SDKROOT}" MATCHES "/" OR IS_DIRECTORY "$ENV{SDKROOT}")) + # Use the value of SDKROOT from the environment. set(_CMAKE_OSX_SYSROOT_DEFAULT "$ENV{SDKROOT}") else() # Find installed SDKs in either Xcode-4.3+ or pre-4.3 SDKs directory. From 43b74793de80153b9446689adf79c4acf1391969 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 21 Sep 2012 14:35:29 -0400 Subject: [PATCH 09/11] OS X: Further improve default CMAKE_OSX_SYSROOT selection Since commit 230ea218 (OS X: Improve default CMAKE_OSX_SYSROOT selection, 2012-09-21) we always set CMAKE_OSX_SYSROOT if any SDK is found in order to support Makefile generator builds with Xcode >= 4.3 without the command-line tools installed. However, in the basic POSIX-only case of the Makefile generator with command-line tools and no CMAKE_OSX_ARCHITECTURES we should not select any SDK by default. --- Modules/Platform/Darwin.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Modules/Platform/Darwin.cmake b/Modules/Platform/Darwin.cmake index 90d34cad8..46ea310ad 100644 --- a/Modules/Platform/Darwin.cmake +++ b/Modules/Platform/Darwin.cmake @@ -106,7 +106,9 @@ elseif(NOT "x$ENV{SDKROOT}" STREQUAL "x" AND (NOT "x$ENV{SDKROOT}" MATCHES "/" OR IS_DIRECTORY "$ENV{SDKROOT}")) # Use the value of SDKROOT from the environment. set(_CMAKE_OSX_SYSROOT_DEFAULT "$ENV{SDKROOT}") -else() +elseif("${CMAKE_GENERATOR}" MATCHES Xcode + OR CMAKE_OSX_ARCHITECTURES MATCHES "[^;]" + OR NOT EXISTS "/usr/include/sys/types.h") # Find installed SDKs in either Xcode-4.3+ or pre-4.3 SDKs directory. set(_CMAKE_OSX_SDKS_DIR "") if(OSX_DEVELOPER_ROOT) From e7e613efbf1da45a2a9e51d11a4022589d79c642 Mon Sep 17 00:00:00 2001 From: Brad King Date: Sat, 22 Sep 2012 07:41:36 -0400 Subject: [PATCH 10/11] OS X: Teach deployment target sanity check about SDK names Since commit 1786b121 (OS X: Allow CMAKE_OSX_SYSROOT to be a logical SDK name, 2012-09-21) we support names like "macosx" or "macosx10.7" as the specified value of CMAKE_OSX_SYSROOT. Extend the SDK name->path conversion to save the original value and also convert into a temporary variable for the Xcode generator. Re-implement the deployment target sanity check to detect the version from the transformed path. --- Modules/Platform/Darwin.cmake | 52 +++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/Modules/Platform/Darwin.cmake b/Modules/Platform/Darwin.cmake index 46ea310ad..a401762e5 100644 --- a/Modules/Platform/Darwin.cmake +++ b/Modules/Platform/Darwin.cmake @@ -148,6 +148,8 @@ set(CMAKE_OSX_SYSROOT "${_CMAKE_OSX_SYSROOT_DEFAULT}" CACHE ${_CMAKE_OSX_SYSROOT "The product will be built against the headers and libraries located inside the indicated SDK.") # Transform the cached value to something we can use. +set(_CMAKE_OSX_SYSROOT_ORIG "${CMAKE_OSX_SYSROOT}") +set(_CMAKE_OSX_SYSROOT_PATH "") if(CMAKE_OSX_SYSROOT) if("x${CMAKE_OSX_SYSROOT}" MATCHES "/") # This is a path to the SDK. Make sure it exists. @@ -155,9 +157,11 @@ if(CMAKE_OSX_SYSROOT) message(WARNING "Ignoring CMAKE_OSX_SYSROOT value:\n ${CMAKE_OSX_SYSROOT}\n" "because the directory does not exist.") set(CMAKE_OSX_SYSROOT "") + set(_CMAKE_OSX_SYSROOT_ORIG "") endif() - elseif(NOT "${CMAKE_GENERATOR}" MATCHES "Xcode") - # For non-Xcode generators transform the sdk name into a path. + set(_CMAKE_OSX_SYSROOT_PATH "${CMAKE_OSX_SYSROOT}") + else() + # Transform the sdk name into a path. execute_process( COMMAND xcodebuild -sdk ${CMAKE_OSX_SYSROOT} -version Path OUTPUT_VARIABLE _stdout @@ -166,30 +170,36 @@ if(CMAKE_OSX_SYSROOT) RESULT_VARIABLE _failed ) if(NOT _failed AND IS_DIRECTORY "${_stdout}") - set(CMAKE_OSX_SYSROOT "${_stdout}") + set(_CMAKE_OSX_SYSROOT_PATH "${_stdout}") + # For non-Xcode generators use the path. + if(NOT "${CMAKE_GENERATOR}" MATCHES "Xcode") + set(CMAKE_OSX_SYSROOT "${_CMAKE_OSX_SYSROOT_PATH}") + endif() endif() endif() endif() -#---------------------------------------------------------------------------- -function(SanityCheckSDKAndDeployTarget _sdk_path _deploy) - if(_deploy STREQUAL "") - return() - endif() - - if(_sdk_path STREQUAL "") - message(FATAL_ERROR "CMAKE_OSX_DEPLOYMENT_TARGET='${_deploy}' but CMAKE_OSX_SYSROOT is empty... - either set CMAKE_OSX_SYSROOT to a valid SDK or set CMAKE_OSX_DEPLOYMENT_TARGET to empty") - endif() - - string(REGEX REPLACE "(.*MacOSX*)(....)(.*\\.sdk)" "\\2" SDK "${_sdk_path}") - if(_deploy GREATER "${SDK}") - message(FATAL_ERROR "CMAKE_OSX_DEPLOYMENT_TARGET (${_deploy}) is greater than CMAKE_OSX_SYSROOT SDK (${_sdk_path}). Please set CMAKE_OSX_DEPLOYMENT_TARGET to ${SDK} or lower") - endif() -endfunction() -#---------------------------------------------------------------------------- - # Make sure the combination of SDK and Deployment Target are allowed -SanityCheckSDKAndDeployTarget("${CMAKE_OSX_SYSROOT}" "${CMAKE_OSX_DEPLOYMENT_TARGET}") +if(CMAKE_OSX_DEPLOYMENT_TARGET) + if("${_CMAKE_OSX_SYSROOT_PATH}" MATCHES "^.*/MacOSX([0-9]+\\.[0-9]+)[^/]*\\.sdk") + set(_sdk_ver "${CMAKE_MATCH_1}") + elseif("${_CMAKE_OSX_SYSROOT_ORIG}" MATCHES "^macosx([0-9]+\\.[0-9]+)$") + set(_sdk_ver "${CMAKE_MATCH_1}") + else() + message(FATAL_ERROR + "CMAKE_OSX_DEPLOYMENT_TARGET is '${CMAKE_OSX_DEPLOYMENT_TARGET}' " + "but CMAKE_OSX_SYSROOT:\n \"${_CMAKE_OSX_SYSROOT_ORIG}\"\n" + "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.") + endif() + if(CMAKE_OSX_DEPLOYMENT_TARGET VERSION_GREATER "${_sdk_ver}") + message(FATAL_ERROR + "CMAKE_OSX_DEPLOYMENT_TARGET (${CMAKE_OSX_DEPLOYMENT_TARGET}) " + "is greater than CMAKE_OSX_SYSROOT SDK:\n ${_CMAKE_OSX_SYSROOT_ORIG}\n" + "Please set CMAKE_OSX_DEPLOYMENT_TARGET to ${_sdk_ver} or lower.") + endif() +endif() if("${CMAKE_BACKWARDS_COMPATIBILITY}" MATCHES "^1\\.[0-6]$") set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS From df928646bae077d0b827116f93a64062e8bd1731 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 24 Sep 2012 14:44:07 -0400 Subject: [PATCH 11/11] OS X: Ignore MACOSX_DEPLOYMENT_TARGET during Xcode compiler id Xcode honors this environment variable if the project file does not set it. Hide it from Xcode while building the compiler id project. --- Modules/CMakeDetermineCompilerId.cmake | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index 8e383990f..906a5e7ba 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -185,12 +185,20 @@ Id flags: ${testflags} endif() configure_file(${CMAKE_ROOT}/Modules/CompilerId/Xcode-${v}.pbxproj.in ${id_dir}/CompilerId${lang}.${ext}/project.pbxproj @ONLY IMMEDIATE) + unset(_ENV_MACOSX_DEPLOYMENT_TARGET) + if(DEFINED ENV{MACOSX_DEPLOYMENT_TARGET}) + set(_ENV_MACOSX_DEPLOYMENT_TARGET "$ENV{MACOSX_DEPLOYMENT_TARGET}") + set(ENV{MACOSX_DEPLOYMENT_TARGET} "") + endif() execute_process(COMMAND xcodebuild WORKING_DIRECTORY ${CMAKE_${lang}_COMPILER_ID_DIR} OUTPUT_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT ERROR_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT RESULT_VARIABLE CMAKE_${lang}_COMPILER_ID_RESULT ) + if(DEFINED _ENV_MACOSX_DEPLOYMENT_TARGET) + set(ENV{MACOSX_DEPLOYMENT_TARGET} "${_ENV_MACOSX_DEPLOYMENT_TARGET}") + endif() # Match the link line from xcodebuild output of the form # Ld ...