From 9c14f1484871fb667611e531b9a7139279924f74 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 28 Mar 2023 11:38:29 -0400 Subject: install(TARGETS): Do not apply installation tweaks to NAMELINK files These files are symlinks to the real binaries, and we already apply tweaks to those. Previously we generated installation tweak code guarded by a `NOT IS_SYMLINK` condition that is never true. Drop the code altogether. Add a test covering the motivating use case, in which a `POST_BUILD` step modifies the namelink file to not actually be a symlink. Fixes: #24647 --- Source/cmInstallTargetGenerator.cxx | 10 ++++++---- Tests/RunCMake/install/RunCMakeTest.cmake | 4 ++++ .../RunCMake/install/TARGETS-NAMELINK-No-Tweak.cmake | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 Tests/RunCMake/install/TARGETS-NAMELINK-No-Tweak.cmake diff --git a/Source/cmInstallTargetGenerator.cxx b/Source/cmInstallTargetGenerator.cxx index 6c31da6..9220123 100644 --- a/Source/cmInstallTargetGenerator.cxx +++ b/Source/cmInstallTargetGenerator.cxx @@ -529,7 +529,7 @@ void cmInstallTargetGenerator::AddInstallNamePatchRule( std::ostream& os, Indent indent, const std::string& config, std::string const& toDestDirPath) { - if (this->ImportLibrary || + if (this->ImportLibrary || this->NamelinkMode == NamelinkModeOnly || !(this->Target->GetType() == cmStateEnums::SHARED_LIBRARY || this->Target->GetType() == cmStateEnums::MODULE_LIBRARY || this->Target->GetType() == cmStateEnums::EXECUTABLE)) { @@ -626,7 +626,8 @@ void cmInstallTargetGenerator::AddRPathCheckRule( std::string const& toDestDirPath) { // Skip the chrpath if the target does not need it. - if (this->ImportLibrary || !this->Target->IsChrpathUsed(config)) { + if (this->ImportLibrary || this->NamelinkMode == NamelinkModeOnly || + !this->Target->IsChrpathUsed(config)) { return; } // Skip if on Apple @@ -677,7 +678,8 @@ void cmInstallTargetGenerator::AddChrpathPatchRule( std::string const& toDestDirPath) { // Skip the chrpath if the target does not need it. - if (this->ImportLibrary || !this->Target->IsChrpathUsed(config)) { + if (this->ImportLibrary || this->NamelinkMode == NamelinkModeOnly || + !this->Target->IsChrpathUsed(config)) { return; } @@ -816,7 +818,7 @@ void cmInstallTargetGenerator::AddStripRule(std::ostream& os, Indent indent, // don't strip static and import libraries, because it removes the only // symbol table they have so you can't link to them anymore if (this->Target->GetType() == cmStateEnums::STATIC_LIBRARY || - this->ImportLibrary) { + this->ImportLibrary || this->NamelinkMode == NamelinkModeOnly) { return; } diff --git a/Tests/RunCMake/install/RunCMakeTest.cmake b/Tests/RunCMake/install/RunCMakeTest.cmake index e5a0413..efafdd1 100644 --- a/Tests/RunCMake/install/RunCMakeTest.cmake +++ b/Tests/RunCMake/install/RunCMakeTest.cmake @@ -121,6 +121,10 @@ run_install_test(FILES-OPTIONAL) run_install_test(DIRECTORY-OPTIONAL) run_install_test(TARGETS-Defaults) +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + run_install_test(TARGETS-NAMELINK-No-Tweak) +endif() + set(RunCMake_TEST_OPTIONS "-DCMAKE_INSTALL_BINDIR:PATH=mybin" "-DCMAKE_INSTALL_LIBDIR:PATH=mylib" diff --git a/Tests/RunCMake/install/TARGETS-NAMELINK-No-Tweak.cmake b/Tests/RunCMake/install/TARGETS-NAMELINK-No-Tweak.cmake new file mode 100644 index 0000000..879f4b8 --- /dev/null +++ b/Tests/RunCMake/install/TARGETS-NAMELINK-No-Tweak.cmake @@ -0,0 +1,20 @@ +enable_language(C) + +add_library(foo SHARED obj1.c) +set_target_properties(foo PROPERTIES + VERSION 1.0 + SOVERSION 1 + INSTALL_RPATH "$ORIGIN" + ) +install(TARGETS foo DESTINATION lib) + +# Replace the .so "namelink" symlink with a linker script. +# It is no longer a symlink, so any install tweaks would break. +# This verifies that no install tweaks are added for the namelink. +set(linker_script "INPUT($)") +add_custom_command(TARGET foo POST_BUILD + COMMAND "${CMAKE_COMMAND}" -E remove "$" + COMMAND "${CMAKE_COMMAND}" -E echo "${linker_script}" > "$" + COMMENT "Generating linker script: '${linker_script}' as file $" + VERBATIM + ) -- cgit v0.12