From 6ee87b2e5cd31b256c9f1d2f43bd24e665469732 Mon Sep 17 00:00:00 2001 From: David Cole Date: Fri, 29 Jan 2010 11:56:35 -0500 Subject: Fix issue #10155 - default value of CMAKE_OSX_DEPLOYMENT_TARGET should always be the empty string. When the value of CMAKE_OSX_DEPLOYMENT_TARGET is the empty string, the -mmacosx-version-min flag should not show up on the compiler command line. The logic for selecting default value of CMAKE_OSX_SYSROOT is orthogonal to and independent of the value of the deployment target. The default value for CMAKE_OSX_SYSROOT is the SDK that corresponds to the current version of Mac OSX on which cmake is running. --- Modules/CMakeCCompiler.cmake.in | 1 + Modules/CMakeCXXCompiler.cmake.in | 1 + Modules/Platform/Darwin-GNU-C.cmake | 1 + Modules/Platform/Darwin-GNU-CXX.cmake | 1 + Modules/Platform/Darwin-GNU.cmake | 20 +++++++++++++++ Modules/Platform/Darwin.cmake | 47 ++++++++++++----------------------- Source/cmLocalGenerator.cxx | 10 +++++--- 7 files changed, 47 insertions(+), 34 deletions(-) diff --git a/Modules/CMakeCCompiler.cmake.in b/Modules/CMakeCCompiler.cmake.in index 9e355a0..051df4c 100644 --- a/Modules/CMakeCCompiler.cmake.in +++ b/Modules/CMakeCCompiler.cmake.in @@ -38,6 +38,7 @@ IF(CMAKE_C_COMPILER_ABI) ENDIF(CMAKE_C_COMPILER_ABI) SET(CMAKE_C_HAS_ISYSROOT "@CMAKE_C_HAS_ISYSROOT@") +@CMAKE_C_OSX_DEPLOYMENT_TARGET_FLAG_CODE@ SET(CMAKE_C_IMPLICIT_LINK_LIBRARIES "@CMAKE_C_IMPLICIT_LINK_LIBRARIES@") SET(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "@CMAKE_C_IMPLICIT_LINK_DIRECTORIES@") diff --git a/Modules/CMakeCXXCompiler.cmake.in b/Modules/CMakeCXXCompiler.cmake.in index 5e71d1f..b264da1 100644 --- a/Modules/CMakeCXXCompiler.cmake.in +++ b/Modules/CMakeCXXCompiler.cmake.in @@ -39,6 +39,7 @@ IF(CMAKE_CXX_COMPILER_ABI) ENDIF(CMAKE_CXX_COMPILER_ABI) SET(CMAKE_CXX_HAS_ISYSROOT "@CMAKE_CXX_HAS_ISYSROOT@") +@CMAKE_CXX_OSX_DEPLOYMENT_TARGET_FLAG_CODE@ SET(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "@CMAKE_CXX_IMPLICIT_LINK_LIBRARIES@") SET(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "@CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES@") diff --git a/Modules/Platform/Darwin-GNU-C.cmake b/Modules/Platform/Darwin-GNU-C.cmake index 155d594..4e326c4 100644 --- a/Modules/Platform/Darwin-GNU-C.cmake +++ b/Modules/Platform/Darwin-GNU-C.cmake @@ -1,3 +1,4 @@ include(Platform/Darwin-GNU) __darwin_compiler_gnu(C) cmake_gnu_has_isysroot(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 6cc0812..b39487e 100644 --- a/Modules/Platform/Darwin-GNU-CXX.cmake +++ b/Modules/Platform/Darwin-GNU-CXX.cmake @@ -1,3 +1,4 @@ include(Platform/Darwin-GNU) __darwin_compiler_gnu(CXX) cmake_gnu_has_isysroot(CXX) +cmake_gnu_set_osx_deployment_target_flag(CXX) diff --git a/Modules/Platform/Darwin-GNU.cmake b/Modules/Platform/Darwin-GNU.cmake index b528c88..4c2194a 100644 --- a/Modules/Platform/Darwin-GNU.cmake +++ b/Modules/Platform/Darwin-GNU.cmake @@ -42,3 +42,23 @@ macro(cmake_gnu_has_isysroot lang) endif() endif() endmacro() + +macro(cmake_gnu_set_osx_deployment_target_flag lang) + if(NOT DEFINED CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG) + set(_doc "${lang} compiler supports OSX deployment target flag") + message(STATUS "Checking whether ${_doc}") + execute_process( + COMMAND ${CMAKE_${lang}_COMPILER} "-v" "--help" + OUTPUT_VARIABLE _gcc_help + ERROR_VARIABLE _gcc_help + ) + if("${_gcc_help}" MATCHES "macosx-version-min") + message(STATUS "Checking whether ${_doc} - yes") + set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "-mmacosx-version-min=") + else() + message(STATUS "Checking whether ${_doc} - no") + set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "") + endif() + set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG_CODE "SET(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG \"${CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG}\")") + endif() +endmacro() diff --git a/Modules/Platform/Darwin.cmake b/Modules/Platform/Darwin.cmake index 4aecc1b..c8bcad1 100644 --- a/Modules/Platform/Darwin.cmake +++ b/Modules/Platform/Darwin.cmake @@ -78,34 +78,19 @@ EXECUTE_PROCESS(COMMAND sw_vers -productVersion OUTPUT_STRIP_TRAILING_WHITESPACE) #---------------------------------------------------------------------------- -# CMAKE_OSX_DEPLOYMENT_TARGET - -# Environment variable set by the user overrides our default. -# Use the same environment variable that Xcode uses. -SET(ENV_MACOSX_DEPLOYMENT_TARGET "$ENV{MACOSX_DEPLOYMENT_TARGET}") - -# Set CMAKE_OSX_DEPLOYMENT_TARGET_DEFAULT - if user has already specified an SDK -# with CMAKE_OSX_SYSROOT, then deployment target should default to "", otherwise, -# default it to the current OSX version. -IF(CMAKE_OSX_SYSROOT) - SET(CMAKE_OSX_DEPLOYMENT_TARGET_DEFAULT "") -ELSE(CMAKE_OSX_SYSROOT) - STRING(REGEX REPLACE "^.*(10)\\.([0-9]+)\\.*([0-9]+)*.*$" "\\1.\\2" - CMAKE_OSX_DEPLOYMENT_TARGET_DEFAULT ${CURRENT_OSX_VERSION}) -ENDIF(CMAKE_OSX_SYSROOT) +# _CURRENT_OSX_VERSION - as a two-component string: 10.5, 10.6, ... +# +STRING(REGEX REPLACE "^([0-9]+\\.[0-9]+).*$" "\\1" + _CURRENT_OSX_VERSION "${CURRENT_OSX_VERSION}") -# Use environment or default as initial cache value: -IF(NOT ENV_MACOSX_DEPLOYMENT_TARGET STREQUAL "") - SET(CMAKE_OSX_DEPLOYMENT_TARGET_VALUE ${ENV_MACOSX_DEPLOYMENT_TARGET}) -ELSE(NOT ENV_MACOSX_DEPLOYMENT_TARGET STREQUAL "") - SET(CMAKE_OSX_DEPLOYMENT_TARGET_VALUE ${CMAKE_OSX_DEPLOYMENT_TARGET_DEFAULT}) -ENDIF(NOT ENV_MACOSX_DEPLOYMENT_TARGET STREQUAL "") +#---------------------------------------------------------------------------- +# CMAKE_OSX_DEPLOYMENT_TARGET # Set cache variable - end user may change this during ccmake or cmake-gui configure. -IF(CURRENT_OSX_VERSION GREATER 10.3) - SET(CMAKE_OSX_DEPLOYMENT_TARGET ${CMAKE_OSX_DEPLOYMENT_TARGET_VALUE} CACHE STRING +IF(_CURRENT_OSX_VERSION VERSION_GREATER 10.3) + SET(CMAKE_OSX_DEPLOYMENT_TARGET "$ENV{MACOSX_DEPLOYMENT_TARGET}" CACHE STRING "Minimum OS X version to target for deployment (at runtime); newer APIs weak linked. Set to empty string for default value.") -ENDIF(CURRENT_OSX_VERSION GREATER 10.3) +ENDIF(_CURRENT_OSX_VERSION VERSION_GREATER 10.3) #---------------------------------------------------------------------------- # CMAKE_OSX_SYSROOT @@ -114,20 +99,20 @@ ENDIF(CURRENT_OSX_VERSION GREATER 10.3) # Use the same environment variable that Xcode uses. SET(ENV_SDKROOT "$ENV{SDKROOT}") -# Set CMAKE_OSX_SYSROOT_DEFAULT based on CMAKE_OSX_DEPLOYMENT_TARGET, +# Set CMAKE_OSX_SYSROOT_DEFAULT based on _CURRENT_OSX_VERSION, # accounting for the known specially named SDKs. SET(CMAKE_OSX_SYSROOT_DEFAULT - "${OSX_DEVELOPER_ROOT}/SDKs/MacOSX${CMAKE_OSX_DEPLOYMENT_TARGET}.sdk") + "${OSX_DEVELOPER_ROOT}/SDKs/MacOSX${_CURRENT_OSX_VERSION}.sdk") -IF(CMAKE_OSX_DEPLOYMENT_TARGET EQUAL "10.4") +IF(_CURRENT_OSX_VERSION STREQUAL "10.4") SET(CMAKE_OSX_SYSROOT_DEFAULT "${OSX_DEVELOPER_ROOT}/SDKs/MacOSX10.4u.sdk") -ENDIF(CMAKE_OSX_DEPLOYMENT_TARGET EQUAL "10.4") +ENDIF(_CURRENT_OSX_VERSION STREQUAL "10.4") -IF(CMAKE_OSX_DEPLOYMENT_TARGET EQUAL "10.3") +IF(_CURRENT_OSX_VERSION STREQUAL "10.3") SET(CMAKE_OSX_SYSROOT_DEFAULT "${OSX_DEVELOPER_ROOT}/SDKs/MacOSX10.3.9.sdk") -ENDIF(CMAKE_OSX_DEPLOYMENT_TARGET EQUAL "10.3") +ENDIF(_CURRENT_OSX_VERSION STREQUAL "10.3") # Use environment or default as initial cache value: IF(NOT ENV_SDKROOT STREQUAL "") @@ -152,7 +137,7 @@ function(SanityCheckSDKAndDeployTarget _sdk_path _deploy) 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}") + 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(SanityCheckSDKAndDeployTarget) #---------------------------------------------------------------------------- diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 3339ee4..1937c2b 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1784,6 +1784,9 @@ void cmLocalGenerator::AddArchitectureFlags(std::string& flags, 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')) { @@ -1815,10 +1818,11 @@ void cmLocalGenerator::AddArchitectureFlags(std::string& flags, flags += sysroot; } - if (deploymentTarget && *deploymentTarget && - lang && (lang[0] =='C' || lang[0] == 'F')) + if (deploymentTargetFlag && *deploymentTargetFlag && + deploymentTarget && *deploymentTarget) { - flags += " -mmacosx-version-min="; + flags += " "; + flags += deploymentTargetFlag; flags += deploymentTarget; } } -- cgit v0.12