From 6883b8212443028fbfff32863e004b311c7f26e8 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 29 Sep 2022 14:10:47 -0400 Subject: cmGlobalXCodeGenerator: Remove unused local variable settings --- Source/cmGlobalXCodeGenerator.cxx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 9739a4e..efa2d02 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -2540,10 +2540,6 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, buildSettings->AddAttribute("EXECUTABLE_SUFFIX", this->CreateString(pnsuffix)); } else if (gtgt->GetType() == cmStateEnums::OBJECT_LIBRARY) { - pnprefix = "lib"; - pnbase = gtgt->GetName(); - pnsuffix = ".a"; - std::string pncdir = this->GetObjectsDirectory( this->CurrentProject, configName, gtgt, OBJECT_LIBRARY_ARTIFACT_DIR); buildSettings->AddAttribute("CONFIGURATION_BUILD_DIR", -- cgit v0.12 From a7fb4bc4750ed2d8f4eb6e2aca312cc35b8e96cc Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 28 Sep 2022 15:05:54 -0400 Subject: Xcode: Set build product locations using CONFIGURATION_BUILD_DIR Since commit 59a2265576 (Xcode: Use EFFECTIVE_PLATFORM_NAME reference in ComputeOutputDir, 2011-08-12, v2.8.6~43^2~1) we can now set the build products path using `CONFIGURATION_BUILD_DIR` unconditionally because we compute the correct value even when using `EFFECTIVE_PLATFORM_NAME`. This avoids relying on `SYMROOT` to locate the build products. Issue: #22550 --- Source/cmGlobalXCodeGenerator.cxx | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index efa2d02..6f82cb5 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -2518,18 +2518,25 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, soName += *soversion; } + if (gtgt->CanCompileSources()) { + std::string outDir; + if (gtgt->GetType() == cmStateEnums::OBJECT_LIBRARY) { + // We cannot suppress the archive, so hide it with intermediate files. + outDir = this->GetObjectsDirectory(this->CurrentProject, configName, + gtgt, OBJECT_LIBRARY_ARTIFACT_DIR); + } else { + outDir = gtgt->GetDirectory(configName); + } + buildSettings->AddAttribute("CONFIGURATION_BUILD_DIR", + this->CreateString(outDir)); + } + // Set attributes to specify the proper name for the target. std::string pndir = this->CurrentLocalGenerator->GetCurrentBinaryDirectory(); if (gtgt->GetType() == cmStateEnums::STATIC_LIBRARY || gtgt->GetType() == cmStateEnums::SHARED_LIBRARY || gtgt->GetType() == cmStateEnums::MODULE_LIBRARY || gtgt->GetType() == cmStateEnums::EXECUTABLE) { - if (!gtgt->UsesDefaultOutputDir(configName, - cmStateEnums::RuntimeBinaryArtifact)) { - std::string pncdir = gtgt->GetDirectory(configName); - buildSettings->AddAttribute("CONFIGURATION_BUILD_DIR", - this->CreateString(pncdir)); - } if (gtgt->IsFrameworkOnApple() || gtgt->IsCFBundleOnApple()) { pnprefix = ""; @@ -2539,11 +2546,6 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, this->CreateString(pnprefix)); buildSettings->AddAttribute("EXECUTABLE_SUFFIX", this->CreateString(pnsuffix)); - } else if (gtgt->GetType() == cmStateEnums::OBJECT_LIBRARY) { - std::string pncdir = this->GetObjectsDirectory( - this->CurrentProject, configName, gtgt, OBJECT_LIBRARY_ARTIFACT_DIR); - buildSettings->AddAttribute("CONFIGURATION_BUILD_DIR", - this->CreateString(pncdir)); } // Store the product name for all target types. -- cgit v0.12 From dc5fc898f68846b24723b5702731ee2efb94f603 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 29 Sep 2022 14:31:26 -0400 Subject: Xcode: Set object file locations using TARGET_TEMP_DIR This avoids relying on `SYMROOT` to locate the object files. Issue: #22550 --- Source/cmGeneratorTarget.cxx | 3 --- Source/cmGlobalXCodeGenerator.cxx | 38 ++++++++++++-------------------------- Source/cmGlobalXCodeGenerator.h | 5 ----- 3 files changed, 12 insertions(+), 34 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 7f1e426..53cb030 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -5454,9 +5454,6 @@ std::string cmGeneratorTarget::GetObjectDirectory( std::string obj_dir = this->GlobalGenerator->ExpandCFGIntDir(this->ObjectDirectory, config); #if defined(__APPLE__) - // find and replace $(PROJECT_NAME) xcode placeholder - const std::string projectName = this->LocalGenerator->GetProjectName(); - cmSystemTools::ReplaceString(obj_dir, "$(PROJECT_NAME)", projectName); // Replace Xcode's placeholder for the object file directory since // installation and export scripts need to know the real directory. // Xcode has build-time settings (e.g. for sanitizers) that affect this, diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 6f82cb5..fab5120 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -607,7 +607,6 @@ std::string cmGlobalXCodeGenerator::PostBuildMakeTarget( } #define CMAKE_CHECK_BUILD_SYSTEM_TARGET "ZERO_CHECK" -#define OBJECT_LIBRARY_ARTIFACT_DIR std::string() void cmGlobalXCodeGenerator::AddExtraTargets( cmLocalGenerator* root, std::vector& gens) @@ -2519,11 +2518,14 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, } if (gtgt->CanCompileSources()) { + std::string tmpDir = + cmStrCat(gtgt->GetSupportDirectory(), '/', this->GetCMakeCFGIntDir()); + buildSettings->AddAttribute("TARGET_TEMP_DIR", this->CreateString(tmpDir)); + std::string outDir; if (gtgt->GetType() == cmStateEnums::OBJECT_LIBRARY) { // We cannot suppress the archive, so hide it with intermediate files. - outDir = this->GetObjectsDirectory(this->CurrentProject, configName, - gtgt, OBJECT_LIBRARY_ARTIFACT_DIR); + outDir = tmpDir; } else { outDir = gtgt->GetDirectory(configName); } @@ -4463,16 +4465,6 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects( return true; } -std::string cmGlobalXCodeGenerator::GetObjectsDirectory( - const std::string& projName, const std::string& configName, - const cmGeneratorTarget* t, const std::string& variant) const -{ - std::string dir = cmStrCat( - t->GetLocalGenerator()->GetCurrentBinaryDirectory(), '/', projName, - ".build/", configName, '/', t->GetName(), ".build/", variant); - return dir; -} - void cmGlobalXCodeGenerator::ComputeArchitectures(cmMakefile* mf) { this->Architectures.clear(); @@ -4596,10 +4588,8 @@ void cmGlobalXCodeGenerator::CreateXCodeDependHackMakefile( for (auto objLib : objlibs) { const std::string objLibName = objLib->GetName(); - std::string d = cmStrCat( - this->GetObjectsDirectory(this->CurrentProject, configName, objLib, - OBJECT_LIBRARY_ARTIFACT_DIR), - "lib", objLibName, ".a"); + std::string d = cmStrCat(objLib->GetSupportDirectory(), '/', + configName, "/lib", objLibName, ".a"); std::string dependency = this->ConvertToRelativeForMake(d); makefileStream << "\\\n\t" << dependency; @@ -4613,8 +4603,8 @@ void cmGlobalXCodeGenerator::CreateXCodeDependHackMakefile( // if building for more than one architecture // then remove those executables as well if (this->Architectures.size() > 1) { - std::string universal = this->GetObjectsDirectory( - this->CurrentProject, configName, gt, "$(OBJDIR)/"); + std::string universal = cmStrCat(gt->GetSupportDirectory(), '/', + configName, "/$(OBJDIR)/"); for (const auto& architecture : this->Architectures) { std::string universalFile = cmStrCat(universal, architecture, '/', gt->GetFullName(configName)); @@ -5011,14 +5001,10 @@ bool cmGlobalXCodeGenerator::ShouldStripResourcePath(cmMakefile*) const 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)/"), - objectDirArch, '/'); - gt->ObjectDirectory = dir; + gt->ObjectDirectory = + cmStrCat(gt->GetSupportDirectory(), '/', this->GetCMakeCFGIntDir(), + "/$(OBJECT_FILE_DIR_normal:base)/", objectDirArch, '/'); } std::string cmGlobalXCodeGenerator::GetDeploymentPlatform(const cmMakefile* mf) diff --git a/Source/cmGlobalXCodeGenerator.h b/Source/cmGlobalXCodeGenerator.h index 92e4528..e924169 100644 --- a/Source/cmGlobalXCodeGenerator.h +++ b/Source/cmGlobalXCodeGenerator.h @@ -339,11 +339,6 @@ private: std::string GetLibraryOrFrameworkPath(const std::string& path) const; - std::string GetObjectsDirectory(const std::string& projName, - const std::string& configName, - const cmGeneratorTarget* t, - const std::string& variant) const; - static std::string GetDeploymentPlatform(const cmMakefile* mf); void ComputeArchitectures(cmMakefile* mf); -- cgit v0.12 From d0a6ebf57bf4d42a5b6875d3064ce1c207b9cc40 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 29 Sep 2022 14:44:01 -0400 Subject: Xcode: Fix "clean" operation under the "new build system" Previously we set `SYMROOT` to tell Xcode where to place the build products. However, the "clean" operation in the Xcode "new build system" expects that only Xcode creates the `SYMROOT` directory or contents inside it. Since we create that directory, "clean" fails. We now explicitly set `CONFIGURATION_BUILD_DIR` and `TARGET_TEMP_DIR` instead of letting Xcode compute their values from `SYMROOT`, so we no longer need to set the latter. Drop the now-unnecessary `SYMROOT`. Fixes: #22550 --- Source/cmGlobalXCodeGenerator.cxx | 1 - Tests/RunCMake/XcodeProject/Clean.cmake | 2 ++ Tests/RunCMake/XcodeProject/Clean/CMakeLists.txt | 1 + Tests/RunCMake/XcodeProject/Clean/empty.c | 0 Tests/RunCMake/XcodeProject/RunCMakeTest.cmake | 8 ++++++++ 5 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 Tests/RunCMake/XcodeProject/Clean.cmake create mode 100644 Tests/RunCMake/XcodeProject/Clean/CMakeLists.txt create mode 100644 Tests/RunCMake/XcodeProject/Clean/empty.c diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index fab5120..31511c8 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -2552,7 +2552,6 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmGeneratorTarget* gtgt, // Store the product name for all target types. buildSettings->AddAttribute("PRODUCT_NAME", this->CreateString(realName)); - buildSettings->AddAttribute("SYMROOT", this->CreateString(pndir)); // Handle settings for each target type. switch (gtgt->GetType()) { diff --git a/Tests/RunCMake/XcodeProject/Clean.cmake b/Tests/RunCMake/XcodeProject/Clean.cmake new file mode 100644 index 0000000..1ab7e10 --- /dev/null +++ b/Tests/RunCMake/XcodeProject/Clean.cmake @@ -0,0 +1,2 @@ +enable_language(C) +add_subdirectory(Clean) diff --git a/Tests/RunCMake/XcodeProject/Clean/CMakeLists.txt b/Tests/RunCMake/XcodeProject/Clean/CMakeLists.txt new file mode 100644 index 0000000..59e62cb --- /dev/null +++ b/Tests/RunCMake/XcodeProject/Clean/CMakeLists.txt @@ -0,0 +1 @@ +add_library(empty empty.c) diff --git a/Tests/RunCMake/XcodeProject/Clean/empty.c b/Tests/RunCMake/XcodeProject/Clean/empty.c new file mode 100644 index 0000000..e69de29 diff --git a/Tests/RunCMake/XcodeProject/RunCMakeTest.cmake b/Tests/RunCMake/XcodeProject/RunCMakeTest.cmake index d20f5a6..879b38e 100644 --- a/Tests/RunCMake/XcodeProject/RunCMakeTest.cmake +++ b/Tests/RunCMake/XcodeProject/RunCMakeTest.cmake @@ -1,5 +1,13 @@ include(RunCMake) +function(RunClean) + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Clean-build) + run_cmake(Clean) + set(RunCMake_TEST_NO_CLEAN 1) + run_cmake_command(Clean-build xcodebuild clean) +endfunction() +RunClean() + run_cmake(ExplicitCMakeLists) run_cmake(ImplicitCMakeLists) run_cmake(InterfaceLibSources) -- cgit v0.12