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.
This commit is contained in:
Brad King 2012-09-21 08:53:42 -04:00
parent 33a60e6bd1
commit a0a0877a1e
8 changed files with 28 additions and 39 deletions

View File

@ -45,7 +45,7 @@ if(CMAKE_C_LIBRARY_ARCHITECTURE)
set(CMAKE_LIBRARY_ARCHITECTURE "@CMAKE_C_LIBRARY_ARCHITECTURE@") set(CMAKE_LIBRARY_ARCHITECTURE "@CMAKE_C_LIBRARY_ARCHITECTURE@")
endif() endif()
set(CMAKE_C_HAS_ISYSROOT "@CMAKE_C_HAS_ISYSROOT@") @CMAKE_C_SYSROOT_FLAG_CODE@
@CMAKE_C_OSX_DEPLOYMENT_TARGET_FLAG_CODE@ @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@")

View File

@ -46,7 +46,7 @@ if(CMAKE_CXX_LIBRARY_ARCHITECTURE)
set(CMAKE_LIBRARY_ARCHITECTURE "@CMAKE_CXX_LIBRARY_ARCHITECTURE@") set(CMAKE_LIBRARY_ARCHITECTURE "@CMAKE_CXX_LIBRARY_ARCHITECTURE@")
endif() endif()
set(CMAKE_CXX_HAS_ISYSROOT "@CMAKE_CXX_HAS_ISYSROOT@") @CMAKE_CXX_SYSROOT_FLAG_CODE@
@CMAKE_CXX_OSX_DEPLOYMENT_TARGET_FLAG_CODE@ @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@")

View File

@ -53,8 +53,8 @@ include(CMakeDetermineSystem)
# short-cut some tests on Darwin, see Darwin-GNU.cmake: # short-cut some tests on Darwin, see Darwin-GNU.cmake:
if("${CMAKE_SYSTEM_NAME}" MATCHES Darwin AND "${COMPILER_ID}" MATCHES GNU) if("${CMAKE_SYSTEM_NAME}" MATCHES Darwin AND "${COMPILER_ID}" MATCHES GNU)
set(${CMAKE_${LANGUAGE}_HAS_ISYSROOT} 0 ) set(CMAKE_${LANGUAGE}_SYSROOT_FLAG "")
set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "") set(CMAKE_${LANGUAGE}_OSX_DEPLOYMENT_TARGET_FLAG "")
endif() endif()
# Also load the system specific file, which sets up e.g. the search paths. # Also load the system specific file, which sets up e.g. the search paths.

View File

@ -21,6 +21,6 @@ set(__DARWIN_COMPILER_CLANG 1)
macro(__darwin_compiler_clang lang) macro(__darwin_compiler_clang lang)
set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-dynamiclib -Wl,-headerpad_max_install_names") 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_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}_OSX_DEPLOYMENT_TARGET_FLAG "-mmacosx-version-min=")
set(CMAKE_${lang}_HAS_ISYSROOT 1)
endmacro() endmacro()

View File

@ -1,4 +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_set_sysroot_flag(C)
cmake_gnu_set_osx_deployment_target_flag(C) cmake_gnu_set_osx_deployment_target_flag(C)

View File

@ -1,4 +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_set_sysroot_flag(CXX)
cmake_gnu_set_osx_deployment_target_flag(CXX) cmake_gnu_set_osx_deployment_target_flag(CXX)

View File

@ -24,8 +24,8 @@ macro(__darwin_compiler_gnu lang)
set(CMAKE_SHARED_MODULE_CREATE_${lang}_FLAGS "-bundle -Wl,-headerpad_max_install_names") set(CMAKE_SHARED_MODULE_CREATE_${lang}_FLAGS "-bundle -Wl,-headerpad_max_install_names")
endmacro() endmacro()
macro(cmake_gnu_has_isysroot lang) macro(cmake_gnu_set_sysroot_flag lang)
if("x${CMAKE_${lang}_HAS_ISYSROOT}" STREQUAL "x") if(NOT DEFINED CMAKE_${lang}_SYSROOT_FLAG)
set(_doc "${lang} compiler has -isysroot") set(_doc "${lang} compiler has -isysroot")
message(STATUS "Checking whether ${_doc}") message(STATUS "Checking whether ${_doc}")
execute_process( execute_process(
@ -35,11 +35,12 @@ macro(cmake_gnu_has_isysroot lang)
) )
if("${_gcc_help}" MATCHES "isysroot") if("${_gcc_help}" MATCHES "isysroot")
message(STATUS "Checking whether ${_doc} - yes") message(STATUS "Checking whether ${_doc} - yes")
set(CMAKE_${lang}_HAS_ISYSROOT 1) set(CMAKE_${lang}_SYSROOT_FLAG "-isysroot")
else() else()
message(STATUS "Checking whether ${_doc} - no") message(STATUS "Checking whether ${_doc} - no")
set(CMAKE_${lang}_HAS_ISYSROOT 0) set(CMAKE_${lang}_SYSROOT_FLAG "")
endif() endif()
set(CMAKE_${lang}_SYSROOT_FLAG_CODE "set(CMAKE_${lang}_SYSROOT_FLAG \"${CMAKE_${lang}_SYSROOT_FLAG}\")")
endif() endif()
endmacro() endmacro()

View File

@ -1792,46 +1792,34 @@ void cmLocalGenerator::AddArchitectureFlags(std::string& flags,
{ {
std::vector<std::string> archs; std::vector<std::string> archs;
target->GetAppleArchs(config, archs); target->GetAppleArchs(config, archs);
const char* sysroot = const char* sysroot = this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT");
this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT"); if(sysroot && sysroot[0] == '/' && !sysroot[1])
const char* sysrootDefault = { sysroot = 0; }
this->Makefile->GetDefinition("CMAKE_OSX_SYSROOT_DEFAULT"); std::string sysrootFlagVar =
std::string("CMAKE_") + lang + "_SYSROOT_FLAG";
const char* sysrootFlag =
this->Makefile->GetDefinition(sysrootFlagVar.c_str());
const char* deploymentTarget = const char* deploymentTarget =
this->Makefile->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET"); 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 deploymentTargetFlagVar =
std::string("CMAKE_") + lang + "_OSX_DEPLOYMENT_TARGET_FLAG"; std::string("CMAKE_") + lang + "_OSX_DEPLOYMENT_TARGET_FLAG";
const char* deploymentTargetFlag = const char* deploymentTargetFlag =
this->Makefile->GetDefinition(deploymentTargetFlagVar.c_str()); this->Makefile->GetDefinition(deploymentTargetFlagVar.c_str());
bool flagsUsed = false; if(!archs.empty() && lang && (lang[0] =='C' || lang[0] == 'F'))
if(!archs.empty() && sysroot && lang && (lang[0] =='C' || lang[0] == 'F'))
{ {
// if there is more than one arch add the -arch and for(std::vector<std::string>::iterator i = archs.begin();
// -isysroot flags, or if there is one arch flag, but i != archs.end(); ++i)
// 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<std::string>::iterator i = archs.begin(); flags += " -arch ";
i != archs.end(); ++i) flags += *i;
{
flags += " -arch ";
flags += *i;
}
if(hasIsysroot)
{
flags += " -isysroot ";
flags += sysroot;
}
flagsUsed = true;
} }
} }
if(!flagsUsed && sysroot && sysrootDefault && if(sysrootFlag && *sysrootFlag && sysroot && *sysroot)
strcmp(sysroot, sysrootDefault) != 0 && hasIsysroot)
{ {
flags += " -isysroot "; flags += " ";
flags += sysrootFlag;
flags += " ";
flags += sysroot; flags += sysroot;
} }