1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 02:08:27 +08:00

IOS_INSTALL_COMBINED: Support Xcode 12 (command line only)

Xcode 12 doesn't allow nested builds within the same build directory.
That means we can no longer do an install by building the install target
when IOS_INSTALL_COMBINED is true. We can, however, still do an install
by running the cmake_install.cmake script or executing cmake --install,
since there is no outer build and therefore the associated SDK can be
built as a sub-build.

The non-build methods previously didn't work when
IOS_INSTALL_COMBINED was true because the generated install script
and the CMakeIOSInstallCombined script both made certain assumptions
that relied on being part of a build. Those assumptions are now
removed. A side-effect of this work is that cpack now also works from the
command line when IOS_INSTALL_COMBINED is true.

Relates: #21282
Fixes: #20023
This commit is contained in:
Craig Scott
2021-02-08 17:30:48 +11:00
parent f0257a87a3
commit 0110aa018d
8 changed files with 109 additions and 21 deletions

View File

@@ -3,10 +3,11 @@
cmake_policy(PUSH) cmake_policy(PUSH)
cmake_policy(SET CMP0057 NEW) # if IN_LIST cmake_policy(SET CMP0057 NEW) # if IN_LIST
cmake_policy(SET CMP0054 NEW)
# Function to print messages of this module # Function to print messages of this module
function(_ios_install_combined_message) function(_ios_install_combined_message)
message("[iOS combined] " ${ARGN}) message(STATUS "[iOS combined] " ${ARGN})
endfunction() endfunction()
# Get build settings for the current target/config/SDK by running # Get build settings for the current target/config/SDK by running
@@ -176,29 +177,33 @@ function(_ios_install_combined_keep_archs lib archs)
endforeach() endforeach()
endfunction() endfunction()
function(_ios_install_combined_detect_sdks this_sdk_var corr_sdk_var) function(_ios_install_combined_detect_associated_sdk corr_sdk_var)
set(this_sdk "$ENV{PLATFORM_NAME}") if("${PLATFORM_NAME}" STREQUAL "")
if("${this_sdk}" STREQUAL "") message(FATAL_ERROR "PLATFORM_NAME should not be empty")
message(FATAL_ERROR "Environment variable PLATFORM_NAME is empty")
endif() endif()
set(all_platforms "$ENV{SUPPORTED_PLATFORMS}") set(all_platforms "$ENV{SUPPORTED_PLATFORMS}")
if("${all_platforms}" STREQUAL "") if("${SUPPORTED_PLATFORMS}" STREQUAL "")
message(FATAL_ERROR "Environment variable SUPPORTED_PLATFORMS is empty") _ios_install_combined_get_build_setting(
${PLATFORM_NAME} SUPPORTED_PLATFORMS all_platforms)
if("${all_platforms}" STREQUAL "")
message(FATAL_ERROR
"SUPPORTED_PLATFORMS not set as an environment variable nor "
"able to be determined from project")
endif()
endif() endif()
separate_arguments(all_platforms) separate_arguments(all_platforms)
if(NOT this_sdk IN_LIST all_platforms) if(NOT PLATFORM_NAME IN_LIST all_platforms)
message(FATAL_ERROR "`${this_sdk}` not found in `${all_platforms}`") message(FATAL_ERROR "`${PLATFORM_NAME}` not found in `${all_platforms}`")
endif() endif()
list(REMOVE_ITEM all_platforms "" "${this_sdk}") list(REMOVE_ITEM all_platforms "" "${PLATFORM_NAME}")
list(LENGTH all_platforms all_platforms_length) list(LENGTH all_platforms all_platforms_length)
if(NOT all_platforms_length EQUAL 1) if(NOT all_platforms_length EQUAL 1)
message(FATAL_ERROR "Expected one element: ${all_platforms}") message(FATAL_ERROR "Expected one element: ${all_platforms}")
endif() endif()
set(${this_sdk_var} "${this_sdk}" PARENT_SCOPE)
set(${corr_sdk_var} "${all_platforms}" PARENT_SCOPE) set(${corr_sdk_var} "${all_platforms}" PARENT_SCOPE)
endfunction() endfunction()
@@ -274,10 +279,10 @@ function(ios_install_combined target destination)
_ios_install_combined_message("Destination: ${destination}") _ios_install_combined_message("Destination: ${destination}")
# Get SDKs # Get SDKs
_ios_install_combined_detect_sdks(this_sdk corr_sdk) _ios_install_combined_detect_associated_sdk(corr_sdk)
# Get architectures of the target # Get architectures of the target
_ios_install_combined_get_valid_archs("${this_sdk}" this_valid_archs) _ios_install_combined_get_valid_archs("${PLATFORM_NAME}" this_valid_archs)
_ios_install_combined_get_valid_archs("${corr_sdk}" corr_valid_archs) _ios_install_combined_get_valid_archs("${corr_sdk}" corr_valid_archs)
_ios_install_combined_prune_common_archs("${corr_sdk}" corr_valid_archs this_valid_archs) _ios_install_combined_prune_common_archs("${corr_sdk}" corr_valid_archs this_valid_archs)

View File

@@ -644,6 +644,8 @@ void cmLocalGenerator::GenerateInstallRules()
/* clang-format on */ /* clang-format on */
} }
this->AddGeneratorSpecificInstallSetup(fout);
// Ask each install generator to write its code. // Ask each install generator to write its code.
cmPolicies::PolicyStatus status = this->GetPolicyStatus(cmPolicies::CMP0082); cmPolicies::PolicyStatus status = this->GetPolicyStatus(cmPolicies::CMP0082);
auto const& installers = this->Makefile->GetInstallGenerators(); auto const& installers = this->Makefile->GetInstallGenerators();

View File

@@ -493,6 +493,8 @@ protected:
std::ostream& os, const std::string& config, std::ostream& os, const std::string& config,
std::vector<std::string> const& configurationTypes); std::vector<std::string> const& configurationTypes);
virtual void AddGeneratorSpecificInstallSetup(std::ostream&) {}
std::string& CreateSafeUniqueObjectFileName(const std::string& sin, std::string& CreateSafeUniqueObjectFileName(const std::string& sin,
std::string const& dir_max); std::string const& dir_max);

View File

@@ -4,6 +4,7 @@
#include "cmGeneratorTarget.h" #include "cmGeneratorTarget.h"
#include "cmGlobalXCodeGenerator.h" #include "cmGlobalXCodeGenerator.h"
#include "cmMakefile.h"
#include "cmSourceFile.h" #include "cmSourceFile.h"
class cmGeneratorTarget; class cmGeneratorTarget;
@@ -45,13 +46,66 @@ void cmLocalXCodeGenerator::Generate()
} }
} }
void cmLocalXCodeGenerator::GenerateInstallRules() void cmLocalXCodeGenerator::AddGeneratorSpecificInstallSetup(std::ostream& os)
{ {
cmLocalGenerator::GenerateInstallRules(); // First check if we need to warn about incompatible settings
for (const auto& target : this->GetGeneratorTargets()) { for (const auto& target : this->GetGeneratorTargets()) {
target->HasMacOSXRpathInstallNameDir(""); target->HasMacOSXRpathInstallNameDir("");
} }
// CMakeIOSInstallCombined.cmake needs to know the location of the top of
// the build directory
os << "set(CMAKE_BINARY_DIR \"" << this->GetBinaryDirectory() << "\")\n\n";
if (this->Makefile->PlatformIsAppleEmbedded()) {
std::string platformName;
switch (this->Makefile->GetAppleSDKType()) {
case cmMakefile::AppleSDK::IPhoneOS:
platformName = "iphoneos";
break;
case cmMakefile::AppleSDK::IPhoneSimulator:
platformName = "iphonesimulator";
break;
case cmMakefile::AppleSDK::AppleTVOS:
platformName = "appletvos";
break;
case cmMakefile::AppleSDK::AppleTVSimulator:
platformName = "appletvsimulator";
break;
case cmMakefile::AppleSDK::WatchOS:
platformName = "watchos";
break;
case cmMakefile::AppleSDK::WatchSimulator:
platformName = "watchsimulator";
break;
case cmMakefile::AppleSDK::MacOS:
break;
}
if (!platformName.empty()) {
// The effective platform name is just the platform name with a hyphen
// prepended. We can get the SUPPORTED_PLATFORMS from the project file
// at runtime, so we don't need to compute that here.
/* clang-format off */
os <<
"if(NOT PLATFORM_NAME)\n"
" if(NOT \"$ENV{PLATFORM_NAME}\" STREQUAL \"\")\n"
" set(PLATFORM_NAME \"$ENV{PLATFORM_NAME}\")\n"
" endif()\n"
" if(NOT PLATFORM_NAME)\n"
" set(PLATFORM_NAME " << platformName << ")\n"
" endif()\n"
"endif()\n\n"
"if(NOT EFFECTIVE_PLATFORM_NAME)\n"
" if(NOT \"$ENV{EFFECTIVE_PLATFORM_NAME}\" STREQUAL \"\")\n"
" set(EFFECTIVE_PLATFORM_NAME \"$ENV{EFFECTIVE_PLATFORM_NAME}\")\n"
" endif()\n"
" if(NOT EFFECTIVE_PLATFORM_NAME)\n"
" set(EFFECTIVE_PLATFORM_NAME -" << platformName << ")\n"
" endif()\n"
"endif()\n\n";
/* clang-format off */
}
}
} }
void cmLocalXCodeGenerator::ComputeObjectFilenames( void cmLocalXCodeGenerator::ComputeObjectFilenames(

View File

@@ -32,7 +32,7 @@ public:
void AppendFlagEscape(std::string& flags, void AppendFlagEscape(std::string& flags,
const std::string& rawFlag) const override; const std::string& rawFlag) const override;
void Generate() override; void Generate() override;
virtual void GenerateInstallRules(); void AddGeneratorSpecificInstallSetup(std::ostream& os) override;
void ComputeObjectFilenames( void ComputeObjectFilenames(
std::map<cmSourceFile const*, std::string>& mapping, std::map<cmSourceFile const*, std::string>& mapping,
cmGeneratorTarget const* gt = nullptr) override; cmGeneratorTarget const* gt = nullptr) override;

View File

@@ -206,7 +206,7 @@ if(NOT XCODE_VERSION VERSION_LESS 7)
unset(RunCMake_TEST_OPTIONS) unset(RunCMake_TEST_OPTIONS)
endif() endif()
if(XCODE_VERSION VERSION_GREATER_EQUAL 6 AND XCODE_VERSION VERSION_LESS 12) if(XCODE_VERSION VERSION_GREATER_EQUAL 6)
# XcodeIOSInstallCombined # XcodeIOSInstallCombined
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/XcodeIOSInstallCombined-build) set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/XcodeIOSInstallCombined-build)
set(RunCMake_TEST_NO_CLEAN 1) set(RunCMake_TEST_NO_CLEAN 1)
@@ -220,7 +220,14 @@ if(XCODE_VERSION VERSION_GREATER_EQUAL 6 AND XCODE_VERSION VERSION_LESS 12)
run_cmake(XcodeIOSInstallCombined) run_cmake(XcodeIOSInstallCombined)
run_cmake_command(XcodeIOSInstallCombined-build ${CMAKE_COMMAND} --build .) run_cmake_command(XcodeIOSInstallCombined-build ${CMAKE_COMMAND} --build .)
run_cmake_command(XcodeIOSInstallCombined-install ${CMAKE_COMMAND} --build . --target install) if(XCODE_VERSION VERSION_LESS 12)
run_cmake_command(XcodeIOSInstallCombined-install ${CMAKE_COMMAND} --build . --target install)
endif()
# --build defaults to Debug, --install defaults to Release, so we have to
# specify the configuration explicitly
run_cmake_command(XcodeIOSInstallCombined-cmakeinstall
${CMAKE_COMMAND} --install . --config Debug
)
unset(RunCMake_TEST_BINARY_DIR) unset(RunCMake_TEST_BINARY_DIR)
unset(RunCMake_TEST_NO_CLEAN) unset(RunCMake_TEST_NO_CLEAN)
@@ -239,7 +246,14 @@ if(XCODE_VERSION VERSION_GREATER_EQUAL 6 AND XCODE_VERSION VERSION_LESS 12)
run_cmake(XcodeIOSInstallCombinedPrune) run_cmake(XcodeIOSInstallCombinedPrune)
run_cmake_command(XcodeIOSInstallCombinedPrune-build ${CMAKE_COMMAND} --build .) run_cmake_command(XcodeIOSInstallCombinedPrune-build ${CMAKE_COMMAND} --build .)
run_cmake_command(XcodeIOSInstallCombinedPrune-install ${CMAKE_COMMAND} --build . --target install) if(XCODE_VERSION VERSION_LESS 12)
run_cmake_command(XcodeIOSInstallCombinedPrune-install ${CMAKE_COMMAND} --build . --target install)
endif()
# --build defaults to Debug, --install defaults to Release, so we have to
# specify the configuration explicitly
run_cmake_command(XcodeIOSInstallCombinedPrune-cmakeinstall
${CMAKE_COMMAND} --install . --config Debug
)
unset(RunCMake_TEST_BINARY_DIR) unset(RunCMake_TEST_BINARY_DIR)
unset(RunCMake_TEST_NO_CLEAN) unset(RunCMake_TEST_NO_CLEAN)
@@ -258,7 +272,14 @@ if(XCODE_VERSION VERSION_GREATER_EQUAL 6 AND XCODE_VERSION VERSION_LESS 12)
run_cmake(XcodeIOSInstallCombinedSingleArch) run_cmake(XcodeIOSInstallCombinedSingleArch)
run_cmake_command(XcodeIOSInstallCombinedSingleArch-build ${CMAKE_COMMAND} --build .) run_cmake_command(XcodeIOSInstallCombinedSingleArch-build ${CMAKE_COMMAND} --build .)
run_cmake_command(XcodeIOSInstallCombinedSingleArch-install ${CMAKE_COMMAND} --build . --target install) if(XCODE_VERSION VERSION_LESS 12)
run_cmake_command(XcodeIOSInstallCombinedSingleArch-install ${CMAKE_COMMAND} --build . --target install)
endif()
# --build defaults to Debug, --install defaults to Release, so we have to
# specify the configuration explicitly
run_cmake_command(XcodeIOSInstallCombinedSingleArch-cmakeinstall
${CMAKE_COMMAND} --install . --config Debug
)
unset(RunCMake_TEST_BINARY_DIR) unset(RunCMake_TEST_BINARY_DIR)
unset(RunCMake_TEST_NO_CLEAN) unset(RunCMake_TEST_NO_CLEAN)

View File

@@ -0,0 +1,2 @@
# Expect the same results whether installing directly or via cmake --install
include(${CMAKE_CURRENT_LIST_DIR}/XcodeIOSInstallCombined-install-check.cmake)

View File

@@ -0,0 +1,2 @@
# Expect the same results whether installing directly or via cmake --install
include(${CMAKE_CURRENT_LIST_DIR}/XcodeIOSInstallCombinedSingleArch-install-check.cmake)