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.
This commit is contained in:
parent
42c3eb85d6
commit
6ee87b2e5c
|
@ -38,6 +38,7 @@ IF(CMAKE_C_COMPILER_ABI)
|
||||||
ENDIF(CMAKE_C_COMPILER_ABI)
|
ENDIF(CMAKE_C_COMPILER_ABI)
|
||||||
|
|
||||||
SET(CMAKE_C_HAS_ISYSROOT "@CMAKE_C_HAS_ISYSROOT@")
|
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_LIBRARIES "@CMAKE_C_IMPLICIT_LINK_LIBRARIES@")
|
||||||
SET(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "@CMAKE_C_IMPLICIT_LINK_DIRECTORIES@")
|
SET(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "@CMAKE_C_IMPLICIT_LINK_DIRECTORIES@")
|
||||||
|
|
|
@ -39,6 +39,7 @@ IF(CMAKE_CXX_COMPILER_ABI)
|
||||||
ENDIF(CMAKE_CXX_COMPILER_ABI)
|
ENDIF(CMAKE_CXX_COMPILER_ABI)
|
||||||
|
|
||||||
SET(CMAKE_CXX_HAS_ISYSROOT "@CMAKE_CXX_HAS_ISYSROOT@")
|
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_LIBRARIES "@CMAKE_CXX_IMPLICIT_LINK_LIBRARIES@")
|
||||||
SET(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "@CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES@")
|
SET(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "@CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES@")
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
include(Platform/Darwin-GNU)
|
include(Platform/Darwin-GNU)
|
||||||
__darwin_compiler_gnu(C)
|
__darwin_compiler_gnu(C)
|
||||||
cmake_gnu_has_isysroot(C)
|
cmake_gnu_has_isysroot(C)
|
||||||
|
cmake_gnu_set_osx_deployment_target_flag(C)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
include(Platform/Darwin-GNU)
|
include(Platform/Darwin-GNU)
|
||||||
__darwin_compiler_gnu(CXX)
|
__darwin_compiler_gnu(CXX)
|
||||||
cmake_gnu_has_isysroot(CXX)
|
cmake_gnu_has_isysroot(CXX)
|
||||||
|
cmake_gnu_set_osx_deployment_target_flag(CXX)
|
||||||
|
|
|
@ -42,3 +42,23 @@ macro(cmake_gnu_has_isysroot lang)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endmacro()
|
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()
|
||||||
|
|
|
@ -77,35 +77,20 @@ EXECUTE_PROCESS(COMMAND sw_vers -productVersion
|
||||||
OUTPUT_VARIABLE CURRENT_OSX_VERSION
|
OUTPUT_VARIABLE CURRENT_OSX_VERSION
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# _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}")
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# CMAKE_OSX_DEPLOYMENT_TARGET
|
# 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)
|
|
||||||
|
|
||||||
# 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 "")
|
|
||||||
|
|
||||||
# Set cache variable - end user may change this during ccmake or cmake-gui configure.
|
# Set cache variable - end user may change this during ccmake or cmake-gui configure.
|
||||||
IF(CURRENT_OSX_VERSION GREATER 10.3)
|
IF(_CURRENT_OSX_VERSION VERSION_GREATER 10.3)
|
||||||
SET(CMAKE_OSX_DEPLOYMENT_TARGET ${CMAKE_OSX_DEPLOYMENT_TARGET_VALUE} CACHE STRING
|
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.")
|
"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
|
# CMAKE_OSX_SYSROOT
|
||||||
|
@ -114,20 +99,20 @@ ENDIF(CURRENT_OSX_VERSION GREATER 10.3)
|
||||||
# Use the same environment variable that Xcode uses.
|
# Use the same environment variable that Xcode uses.
|
||||||
SET(ENV_SDKROOT "$ENV{SDKROOT}")
|
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.
|
# accounting for the known specially named SDKs.
|
||||||
SET(CMAKE_OSX_SYSROOT_DEFAULT
|
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
|
SET(CMAKE_OSX_SYSROOT_DEFAULT
|
||||||
"${OSX_DEVELOPER_ROOT}/SDKs/MacOSX10.4u.sdk")
|
"${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
|
SET(CMAKE_OSX_SYSROOT_DEFAULT
|
||||||
"${OSX_DEVELOPER_ROOT}/SDKs/MacOSX10.3.9.sdk")
|
"${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:
|
# Use environment or default as initial cache value:
|
||||||
IF(NOT ENV_SDKROOT STREQUAL "")
|
IF(NOT ENV_SDKROOT STREQUAL "")
|
||||||
|
@ -152,7 +137,7 @@ function(SanityCheckSDKAndDeployTarget _sdk_path _deploy)
|
||||||
|
|
||||||
string(REGEX REPLACE "(.*MacOSX*)(....)(.*\\.sdk)" "\\2" SDK "${_sdk_path}")
|
string(REGEX REPLACE "(.*MacOSX*)(....)(.*\\.sdk)" "\\2" SDK "${_sdk_path}")
|
||||||
if(_deploy GREATER "${SDK}")
|
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()
|
endif()
|
||||||
endfunction(SanityCheckSDKAndDeployTarget)
|
endfunction(SanityCheckSDKAndDeployTarget)
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
|
@ -1784,6 +1784,9 @@ void cmLocalGenerator::AddArchitectureFlags(std::string& flags,
|
||||||
this->Makefile->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET");
|
this->Makefile->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET");
|
||||||
std::string isysrootVar = std::string("CMAKE_") + lang + "_HAS_ISYSROOT";
|
std::string isysrootVar = std::string("CMAKE_") + lang + "_HAS_ISYSROOT";
|
||||||
bool hasIsysroot = this->Makefile->IsOn(isysrootVar.c_str());
|
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;
|
bool flagsUsed = false;
|
||||||
if(!archs.empty() && sysroot && lang && (lang[0] =='C' || lang[0] == 'F'))
|
if(!archs.empty() && sysroot && lang && (lang[0] =='C' || lang[0] == 'F'))
|
||||||
{
|
{
|
||||||
|
@ -1815,10 +1818,11 @@ void cmLocalGenerator::AddArchitectureFlags(std::string& flags,
|
||||||
flags += sysroot;
|
flags += sysroot;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deploymentTarget && *deploymentTarget &&
|
if (deploymentTargetFlag && *deploymentTargetFlag &&
|
||||||
lang && (lang[0] =='C' || lang[0] == 'F'))
|
deploymentTarget && *deploymentTarget)
|
||||||
{
|
{
|
||||||
flags += " -mmacosx-version-min=";
|
flags += " ";
|
||||||
|
flags += deploymentTargetFlag;
|
||||||
flags += deploymentTarget;
|
flags += deploymentTarget;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue