diff options
author | Brad King <brad.king@kitware.com> | 2022-04-14 13:30:21 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2022-04-14 13:30:29 (GMT) |
commit | f011557f0eff1fe08b54cfb30a1b74beefe37456 (patch) | |
tree | d9638f183591960b14946b2b00da999728581847 | |
parent | d96e139f76a27c74d057cba8156cc495cf2b4151 (diff) | |
parent | 40dd46a96a5751f4a109ae555ce3b835b4c9ca68 (diff) | |
download | CMake-f011557f0eff1fe08b54cfb30a1b74beefe37456.zip CMake-f011557f0eff1fe08b54cfb30a1b74beefe37456.tar.gz CMake-f011557f0eff1fe08b54cfb30a1b74beefe37456.tar.bz2 |
Merge topic 'xcode-universal'
40dd46a96a Xcode: Add tests for OBJECT library per target `OSX_ARCHITECTURES`
da4ccb502b Xcode: Check for multiple `OSX_ARCHITECTURES` on target
41ba35a42b cmTarget: Add `HasKnownObjectFileLocation()` shorthand
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !7154
-rw-r--r-- | Source/cmExportBuildFileGenerator.cxx | 2 | ||||
-rw-r--r-- | Source/cmFileAPICodemodel.cxx | 2 | ||||
-rw-r--r-- | Source/cmGeneratorExpressionNode.cxx | 2 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.h | 11 | ||||
-rw-r--r-- | Source/cmGlobalXCodeGenerator.cxx | 24 | ||||
-rw-r--r-- | Source/cmGlobalXCodeGenerator.h | 3 | ||||
-rw-r--r-- | Source/cmInstallCommand.cxx | 3 | ||||
-rw-r--r-- | Source/cmTarget.cxx | 5 | ||||
-rw-r--r-- | Source/cmTarget.h | 2 | ||||
-rw-r--r-- | Tests/RunCMake/CMakeLists.txt | 3 | ||||
-rw-r--r-- | Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake | 9 | ||||
-rw-r--r-- | Tests/RunCMake/ObjectLibrary/TargetOverrideMultiArch-result.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/ObjectLibrary/TargetOverrideMultiArch-stderr.txt | 5 | ||||
-rw-r--r-- | Tests/RunCMake/ObjectLibrary/TargetOverrideMultiArch.cmake | 3 | ||||
-rw-r--r-- | Tests/RunCMake/ObjectLibrary/TargetOverrideSingleArch.cmake | 3 |
15 files changed, 65 insertions, 13 deletions
diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx index a47f1e5..c7e1f3c 100644 --- a/Source/cmExportBuildFileGenerator.cxx +++ b/Source/cmExportBuildFileGenerator.cxx @@ -195,7 +195,7 @@ cmStateEnums::TargetType cmExportBuildFileGenerator::GetExportTargetType( // to support transitive usage requirements on other targets that // use the object library. if (targetType == cmStateEnums::OBJECT_LIBRARY && - !this->LG->GetGlobalGenerator()->HasKnownObjectFileLocation(nullptr)) { + !target->Target->HasKnownObjectFileLocation(nullptr)) { targetType = cmStateEnums::INTERFACE_LIBRARY; } return targetType; diff --git a/Source/cmFileAPICodemodel.cxx b/Source/cmFileAPICodemodel.cxx index 40e1d2e..dd0540c 100644 --- a/Source/cmFileAPICodemodel.cxx +++ b/Source/cmFileAPICodemodel.cxx @@ -1728,7 +1728,7 @@ Json::Value Target::DumpArtifacts() // Object libraries have only object files as artifacts. if (this->GT->GetType() == cmStateEnums::OBJECT_LIBRARY) { - if (!this->GT->GetGlobalGenerator()->HasKnownObjectFileLocation(nullptr)) { + if (!this->GT->Target->HasKnownObjectFileLocation(nullptr)) { return artifacts; } std::vector<cmSourceFile const*> objectSources; diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 3d1cfbf..a9bc435 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -1785,7 +1785,7 @@ static const struct TargetObjectsNode : public cmGeneratorExpressionNode { std::string reason; if (!context->EvaluateForBuildsystem && - !gg->HasKnownObjectFileLocation(&reason)) { + !gt->Target->HasKnownObjectFileLocation(&reason)) { std::ostringstream e; e << "The evaluation of the TARGET_OBJECTS generator expression " "is only suitable for consumption by CMake (limited" diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 5965a16..dcef070 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -459,10 +459,13 @@ public: virtual bool IsNinja() const { return false; } - /** Return true if we know the exact location of object files. - If false, store the reason in the given string. - This is meaningful only after EnableLanguage has been called. */ - virtual bool HasKnownObjectFileLocation(std::string*) const { return true; } + /** Return true if we know the exact location of object files for the given + cmTarget. If false, store the reason in the given string. This is + meaningful only after EnableLanguage has been called. */ + virtual bool HasKnownObjectFileLocation(cmTarget const&, std::string*) const + { + return true; + } virtual bool UseFolderProperty() const; diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 3ce3d59..d53c3d5 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -1167,6 +1167,20 @@ std::string GetSourcecodeValueFromFileExtension( return sourcecode; } +template <class T> +std::string GetTargetObjectDirArch(T const& target, + const std::string& defaultVal) +{ + auto archs = cmExpandedList(target.GetSafeProperty("OSX_ARCHITECTURES")); + if (archs.size() > 1) { + return "$(CURRENT_ARCH)"; + } else if (archs.size() == 1) { + return archs.front(); + } else { + return defaultVal; + } +} + } // anonymous // Extracts the framework directory, if path matches the framework syntax @@ -4924,9 +4938,11 @@ bool cmGlobalXCodeGenerator::IsMultiConfig() const } bool cmGlobalXCodeGenerator::HasKnownObjectFileLocation( - std::string* reason) const + cmTarget const& target, std::string* reason) const { - if (this->ObjectDirArch.find('$') != std::string::npos) { + auto objectDirArch = GetTargetObjectDirArch(target, this->ObjectDirArch); + + if (objectDirArch.find('$') != std::string::npos) { if (reason != nullptr) { *reason = " under Xcode with multiple architectures"; } @@ -4957,10 +4973,12 @@ void cmGlobalXCodeGenerator::ComputeTargetObjectDirectory( cmGeneratorTarget* gt) const { std::string configName = this->GetCMakeCFGIntDir(); + auto objectDirArch = GetTargetObjectDirArch(*gt, this->ObjectDirArch); + std::string dir = cmStrCat(this->GetObjectsDirectory("$(PROJECT_NAME)", configName, gt, "$(OBJECT_FILE_DIR_normal:base)/"), - this->ObjectDirArch, '/'); + objectDirArch, '/'); gt->ObjectDirectory = dir; } diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h index 1159d1f..92e4528 100644 --- a/Source/cmGlobalXCodeGenerator.h +++ b/Source/cmGlobalXCodeGenerator.h @@ -107,7 +107,8 @@ public: bool IsXcode() const override { return true; } - bool HasKnownObjectFileLocation(std::string* reason) const override; + bool HasKnownObjectFileLocation(cmTarget const&, + std::string* reason) const override; bool IsIPOSupported() const override { return true; } diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index 1ed698d..7de2cb1 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -919,8 +919,7 @@ bool HandleTargetsMode(std::vector<std::string> const& args, if (!objectArgs.GetDestination().empty()) { // Verify that we know where the objects are to install them. std::string reason; - if (!helper.Makefile->GetGlobalGenerator() - ->HasKnownObjectFileLocation(&reason)) { + if (!target.HasKnownObjectFileLocation(&reason)) { status.SetError( cmStrCat("TARGETS given OBJECT library \"", target.GetName(), "\" whose objects may not be installed", reason, ".")); diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 5c43bc8..a01321d 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -691,6 +691,11 @@ bool cmTarget::IsAndroidGuiExecutable() const this->impl->IsAndroid && this->GetPropertyAsBool("ANDROID_GUI")); } +bool cmTarget::HasKnownObjectFileLocation(std::string* reason) const +{ + return this->GetGlobalGenerator()->HasKnownObjectFileLocation(*this, reason); +} + std::vector<cmCustomCommand> const& cmTarget::GetPreBuildCommands() const { return this->impl->PreBuildCommands; diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 97fdbeb..72497b3 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -220,6 +220,8 @@ public: //! Return whether this target is a GUI executable on Android. bool IsAndroidGuiExecutable() const; + bool HasKnownObjectFileLocation(std::string* reason = nullptr) const; + //! Get a backtrace from the creation of the target. cmListFileBacktrace const& GetBacktrace() const; diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index dbff293..024c388 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -352,6 +352,9 @@ if(MSVC) add_RunCMake_test(MSVCRuntimeTypeInfo) add_RunCMake_test(MSVCWarningFlags) endif() +if(XCODE_VERSION) + set(ObjectLibrary_ARGS -DXCODE_VERSION=${XCODE_VERSION}) +endif() add_RunCMake_test(ObjectLibrary) add_RunCMake_test(ParseImplicitIncludeInfo) add_RunCMake_test(ParseImplicitLinkInfo) diff --git a/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake b/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake index 8515ba5..0e31b78 100644 --- a/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake +++ b/Tests/RunCMake/ObjectLibrary/RunCMakeTest.cmake @@ -8,12 +8,21 @@ run_cmake(BadObjSource2) if(RunCMake_GENERATOR STREQUAL "Xcode" AND "$ENV{CMAKE_OSX_ARCHITECTURES}" MATCHES "[;$]") run_cmake(ImportMultiArch) run_cmake(InstallNotSupported) + + set(osx_archs $ENV{CMAKE_OSX_ARCHITECTURES}) + list(GET osx_archs 0 osx_arch) + run_cmake_with_options(TargetOverrideSingleArch -Dosx_arch=${osx_arch}) else() run_cmake(Import) run_cmake(Install) run_cmake(InstallLinkedObj1) run_cmake(InstallLinkedObj2) + + if(RunCMake_GENERATOR STREQUAL "Xcode" AND XCODE_VERSION VERSION_GREATER_EQUAL 13) + run_cmake(TargetOverrideMultiArch) + endif() endif() + run_cmake(Export) function (run_object_lib_build name) diff --git a/Tests/RunCMake/ObjectLibrary/TargetOverrideMultiArch-result.txt b/Tests/RunCMake/ObjectLibrary/TargetOverrideMultiArch-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/TargetOverrideMultiArch-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/ObjectLibrary/TargetOverrideMultiArch-stderr.txt b/Tests/RunCMake/ObjectLibrary/TargetOverrideMultiArch-stderr.txt new file mode 100644 index 0000000..eb0593c --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/TargetOverrideMultiArch-stderr.txt @@ -0,0 +1,5 @@ +CMake Error at TargetOverrideMultiArch.cmake:[0-9]+ \(install\): + install TARGETS given OBJECT library "A" whose objects may not be installed + under Xcode with multiple architectures. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/ObjectLibrary/TargetOverrideMultiArch.cmake b/Tests/RunCMake/ObjectLibrary/TargetOverrideMultiArch.cmake new file mode 100644 index 0000000..ada77f8 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/TargetOverrideMultiArch.cmake @@ -0,0 +1,3 @@ +add_library(A OBJECT a.c) +set_target_properties(A PROPERTIES OSX_ARCHITECTURES "x86_64;arm64") +install(TARGETS A DESTINATION lib) diff --git a/Tests/RunCMake/ObjectLibrary/TargetOverrideSingleArch.cmake b/Tests/RunCMake/ObjectLibrary/TargetOverrideSingleArch.cmake new file mode 100644 index 0000000..3f400e8 --- /dev/null +++ b/Tests/RunCMake/ObjectLibrary/TargetOverrideSingleArch.cmake @@ -0,0 +1,3 @@ +add_library(A OBJECT a.c) +set_target_properties(A PROPERTIES OSX_ARCHITECTURES ${osx_arch}) +install(TARGETS A DESTINATION lib) |