Selaa lähdekoodia

Merge topic 'xcode12-ios_install_combined'

0110aa018d IOS_INSTALL_COMBINED: Support Xcode 12 (command line only)

Acked-by: Kitware Robot <[email protected]>
Merge-request: !5785
Brad King 4 vuotta sitten
vanhempi
sitoutus
cab99f7dba

+ 18 - 13
Modules/CMakeIOSInstallCombined.cmake

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

+ 2 - 0
Source/cmLocalGenerator.cxx

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

+ 2 - 0
Source/cmLocalGenerator.h

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

+ 57 - 3
Source/cmLocalXCodeGenerator.cxx

@@ -4,6 +4,7 @@
 
 #include "cmGeneratorTarget.h"
 #include "cmGlobalXCodeGenerator.h"
+#include "cmMakefile.h"
 #include "cmSourceFile.h"
 
 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()) {
     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(

+ 1 - 1
Source/cmLocalXCodeGenerator.h

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

+ 25 - 4
Tests/RunCMake/XcodeProject/RunCMakeTest.cmake

@@ -236,7 +236,7 @@ if(NOT XCODE_VERSION VERSION_LESS 7)
   unset(RunCMake_TEST_OPTIONS)
 endif()
 
-if(XCODE_VERSION VERSION_GREATER_EQUAL 6 AND XCODE_VERSION VERSION_LESS 12)
+if(XCODE_VERSION VERSION_GREATER_EQUAL 6)
   # XcodeIOSInstallCombined
   set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/XcodeIOSInstallCombined-build)
   set(RunCMake_TEST_NO_CLEAN 1)
@@ -250,7 +250,14 @@ if(XCODE_VERSION VERSION_GREATER_EQUAL 6 AND XCODE_VERSION VERSION_LESS 12)
 
   run_cmake(XcodeIOSInstallCombined)
   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_NO_CLEAN)
@@ -269,7 +276,14 @@ if(XCODE_VERSION VERSION_GREATER_EQUAL 6 AND XCODE_VERSION VERSION_LESS 12)
 
   run_cmake(XcodeIOSInstallCombinedPrune)
   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_NO_CLEAN)
@@ -288,7 +302,14 @@ if(XCODE_VERSION VERSION_GREATER_EQUAL 6 AND XCODE_VERSION VERSION_LESS 12)
 
   run_cmake(XcodeIOSInstallCombinedSingleArch)
   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_NO_CLEAN)

+ 2 - 0
Tests/RunCMake/XcodeProject/XcodeIOSInstallCombined-cmakeinstall-check.cmake

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

+ 2 - 0
Tests/RunCMake/XcodeProject/XcodeIOSInstallCombinedSingleArch-cmakeinstall-check.cmake

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