summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Modules/CMakeFindBinUtils.cmake10
-rw-r--r--Source/CMakeVersion.cmake2
-rw-r--r--Source/cmGlobalGenerator.cxx29
-rw-r--r--Source/cmGlobalGenerator.h11
-rw-r--r--Source/cmInstallRuntimeDependencySetGenerator.cxx3
-rw-r--r--Source/cmInstallTargetGenerator.cxx17
6 files changed, 61 insertions, 11 deletions
diff --git a/Modules/CMakeFindBinUtils.cmake b/Modules/CMakeFindBinUtils.cmake
index 190117c..10e8ff3 100644
--- a/Modules/CMakeFindBinUtils.cmake
+++ b/Modules/CMakeFindBinUtils.cmake
@@ -186,7 +186,15 @@ else()
list(PREPEND _CMAKE_RANLIB_NAMES "llvm-ranlib")
if("${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_VERSION}" VERSION_GREATER_EQUAL 11)
# llvm-strip versions prior to 11 require additional flags we do not yet add.
- list(PREPEND _CMAKE_STRIP_NAMES "llvm-strip")
+ if(APPLE)
+ # llvm-strip does not seem to support chained fixup format correctly.
+ # FIXME(#23333): We still need to consider 'llvm-strip' as a fallback
+ # because the 'APPLE' definition may be based on the host in this context,
+ # and a cross-compiling toolchain may not have 'strip'.
+ list(APPEND _CMAKE_STRIP_NAMES "llvm-strip")
+ else()
+ list(PREPEND _CMAKE_STRIP_NAMES "llvm-strip")
+ endif()
endif()
list(PREPEND _CMAKE_NM_NAMES "llvm-nm")
if("${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_VERSION}" VERSION_GREATER_EQUAL 9)
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake
index 281a8a9..5706762 100644
--- a/Source/CMakeVersion.cmake
+++ b/Source/CMakeVersion.cmake
@@ -1,7 +1,7 @@
# CMake version number components.
set(CMake_VERSION_MAJOR 3)
set(CMake_VERSION_MINOR 26)
-set(CMake_VERSION_PATCH 20230330)
+set(CMake_VERSION_PATCH 20230331)
#set(CMake_VERSION_RC 0)
set(CMake_VERSION_IS_DIRTY 0)
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 0e9f78e..08022b3 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -3542,3 +3542,32 @@ cmInstallRuntimeDependencySet* cmGlobalGenerator::GetNamedRuntimeDependencySet(
}
return it->second;
}
+
+cmGlobalGenerator::StripCommandStyle cmGlobalGenerator::GetStripCommandStyle(
+ std::string const& strip)
+{
+#ifdef __APPLE__
+ auto i = this->StripCommandStyleMap.find(strip);
+ if (i == this->StripCommandStyleMap.end()) {
+ StripCommandStyle style = StripCommandStyle::Default;
+
+ // Try running strip tool with Apple-specific options.
+ std::vector<std::string> cmd{ strip, "-u", "-r" };
+ std::string out;
+ std::string err;
+ int ret;
+ if (cmSystemTools::RunSingleCommand(cmd, &out, &err, &ret, nullptr,
+ cmSystemTools::OUTPUT_NONE) &&
+ // Check for Apple-specific output.
+ ret != 0 && cmHasLiteralPrefix(err, "fatal error: /") &&
+ err.find("/usr/bin/strip: no files specified") != std::string::npos) {
+ style = StripCommandStyle::Apple;
+ }
+ i = this->StripCommandStyleMap.emplace(strip, style).first;
+ }
+ return i->second;
+#else
+ static_cast<void>(strip);
+ return StripCommandStyle::Default;
+#endif
+}
diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h
index 4d321b5..4bbbdfa 100644
--- a/Source/cmGlobalGenerator.h
+++ b/Source/cmGlobalGenerator.h
@@ -607,6 +607,13 @@ public:
cmInstallRuntimeDependencySet* GetNamedRuntimeDependencySet(
const std::string& name);
+ enum class StripCommandStyle
+ {
+ Default,
+ Apple,
+ };
+ StripCommandStyle GetStripCommandStyle(std::string const& strip);
+
protected:
// for a project collect all its targets by following depend
// information, and also collect all the targets
@@ -737,6 +744,10 @@ private:
std::map<std::string, int> LanguageToLinkerPreference;
std::map<std::string, std::string> LanguageToOriginalSharedLibFlags;
+#ifdef __APPLE__
+ std::map<std::string, StripCommandStyle> StripCommandStyleMap;
+#endif
+
mutable bool DiagnosedCxxModuleSupport = false;
// Deferral id generation.
diff --git a/Source/cmInstallRuntimeDependencySetGenerator.cxx b/Source/cmInstallRuntimeDependencySetGenerator.cxx
index 44f03e1..1e2e663 100644
--- a/Source/cmInstallRuntimeDependencySetGenerator.cxx
+++ b/Source/cmInstallRuntimeDependencySetGenerator.cxx
@@ -256,8 +256,7 @@ void cmInstallRuntimeDependencySetGenerator::GenerateStripFixup(
if (!strip.empty()) {
os << indent << "if(CMAKE_INSTALL_DO_STRIP)\n"
<< indent.Next() << "execute_process(COMMAND \"" << strip << "\" ";
- if (this->LocalGenerator->GetMakefile()->GetSafeDefinition(
- "CMAKE_HOST_SYSTEM_NAME") == "Darwin") {
+ if (this->LocalGenerator->GetMakefile()->IsOn("APPLE")) {
os << "-x ";
}
os << "\""
diff --git a/Source/cmInstallTargetGenerator.cxx b/Source/cmInstallTargetGenerator.cxx
index 9220123..3ac100d 100644
--- a/Source/cmInstallTargetGenerator.cxx
+++ b/Source/cmInstallTargetGenerator.cxx
@@ -828,26 +828,29 @@ void cmInstallTargetGenerator::AddStripRule(std::ostream& os, Indent indent,
return;
}
- if (!this->Target->Target->GetMakefile()->IsSet("CMAKE_STRIP")) {
+ std::string const& strip =
+ this->Target->Target->GetMakefile()->GetSafeDefinition("CMAKE_STRIP");
+ if (strip.empty()) {
return;
}
std::string stripArgs;
-
- // macOS 'strip' is picky, executables need '-u -r' and dylibs need '-x'.
if (this->Target->IsApple()) {
if (this->Target->GetType() == cmStateEnums::SHARED_LIBRARY ||
this->Target->GetType() == cmStateEnums::MODULE_LIBRARY) {
+ // Strip tools need '-x' to strip Apple dylibs correctly.
stripArgs = "-x ";
- } else if (this->Target->GetType() == cmStateEnums::EXECUTABLE) {
+ } else if (this->Target->GetType() == cmStateEnums::EXECUTABLE &&
+ this->Target->GetGlobalGenerator()->GetStripCommandStyle(
+ strip) == cmGlobalGenerator::StripCommandStyle::Apple) {
+ // Apple's strip tool needs '-u -r' to strip executables correctly.
stripArgs = "-u -r ";
}
}
os << indent << "if(CMAKE_INSTALL_DO_STRIP)\n";
- os << indent << " execute_process(COMMAND \""
- << this->Target->Target->GetMakefile()->GetSafeDefinition("CMAKE_STRIP")
- << "\" " << stripArgs << "\"" << toDestDirPath << "\")\n";
+ os << indent << " execute_process(COMMAND \"" << strip << "\" " << stripArgs
+ << "\"" << toDestDirPath << "\")\n";
os << indent << "endif()\n";
}