From 1980e47192eaea554fe521c7919fbf28684b1b4c Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 17 Sep 2025 14:23:15 -0400 Subject: [PATCH 1/2] Tests/IntermediateDirStrategy: test install paths when using SHORT See: #27233 --- .../IntermediateDirStrategy/CMakeLists.txt | 4 ++++ .../IntermediateDirStrategy/Inspect.cmake | 10 +++++++++ .../RunCMakeTest.cmake | 22 +++++++++++++++++++ ...ectDoesntChangeInstall-install-check.cmake | 11 ++++++++++ .../ShortObjectDoesntChangeInstall.cmake | 5 +++++ .../IntermediateDirStrategy/subdir/obj.c | 4 ++++ 6 files changed, 56 insertions(+) create mode 100644 Tests/RunCMake/IntermediateDirStrategy/Inspect.cmake create mode 100644 Tests/RunCMake/IntermediateDirStrategy/ShortObjectDoesntChangeInstall-install-check.cmake create mode 100644 Tests/RunCMake/IntermediateDirStrategy/ShortObjectDoesntChangeInstall.cmake create mode 100644 Tests/RunCMake/IntermediateDirStrategy/subdir/obj.c diff --git a/Tests/RunCMake/IntermediateDirStrategy/CMakeLists.txt b/Tests/RunCMake/IntermediateDirStrategy/CMakeLists.txt index 5d1e2985e2..dd1af9492d 100644 --- a/Tests/RunCMake/IntermediateDirStrategy/CMakeLists.txt +++ b/Tests/RunCMake/IntermediateDirStrategy/CMakeLists.txt @@ -1,2 +1,6 @@ cmake_minimum_required(VERSION 3.10) project(${RunCMake_TEST} NONE) + +if (NOT RunCMake_TEST MATCHES "IntDirStrategy") + include(${RunCMake_TEST}.cmake) +endif () diff --git a/Tests/RunCMake/IntermediateDirStrategy/Inspect.cmake b/Tests/RunCMake/IntermediateDirStrategy/Inspect.cmake new file mode 100644 index 0000000000..ec74ed8e36 --- /dev/null +++ b/Tests/RunCMake/IntermediateDirStrategy/Inspect.cmake @@ -0,0 +1,10 @@ +enable_language(C) + +set(info "") + +# Forward information about the C++ compile features. +string(APPEND info "\ +set(CMAKE_C_OUTPUT_EXTENSION \"${CMAKE_C_OUTPUT_EXTENSION}\") +") + +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/info.cmake" "${info}") diff --git a/Tests/RunCMake/IntermediateDirStrategy/RunCMakeTest.cmake b/Tests/RunCMake/IntermediateDirStrategy/RunCMakeTest.cmake index b719dfd0dd..eb2a5f5c03 100644 --- a/Tests/RunCMake/IntermediateDirStrategy/RunCMakeTest.cmake +++ b/Tests/RunCMake/IntermediateDirStrategy/RunCMakeTest.cmake @@ -27,3 +27,25 @@ foreach (kind IN ITEMS Object Autogen) run_cmake_intdir_strategy(IntDirStrategyEnv ${strategy} ${kind}) endforeach () endforeach () + +# The following tests perform installation of `OBJECT` libraries which does not +# work with multi-arch compilation under Xcode. +if (RunCMake_GENERATOR STREQUAL "Xcode" AND "$ENV{CMAKE_OSX_ARCHITECTURES}" MATCHES "[;$]") + return () +endif () + +run_cmake(Inspect) +include("${RunCMake_BINARY_DIR}/Inspect-build/info.cmake") + +function(run_install_test case) + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${case}-build) + set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE:STRING=Debug "-DCMAKE_INSTALL_PREFIX:PATH=${RunCMake_TEST_BINARY_DIR}/fake_install") + run_cmake(${case}) + set(RunCMake_TEST_NO_CLEAN 1) + run_cmake_command(${case}-build ${CMAKE_COMMAND} --build . --config Debug) + run_cmake_command(${case}-install ${CMAKE_COMMAND} --install . --config Debug --prefix "${RunCMake_TEST_BINARY_DIR}/real_install") +endfunction() + +if (RunCMake_GENERATOR MATCHES "(Ninja|Makefiles|Visual Studio)") + run_install_test(ShortObjectDoesntChangeInstall) +endif () diff --git a/Tests/RunCMake/IntermediateDirStrategy/ShortObjectDoesntChangeInstall-install-check.cmake b/Tests/RunCMake/IntermediateDirStrategy/ShortObjectDoesntChangeInstall-install-check.cmake new file mode 100644 index 0000000000..8fb33086f3 --- /dev/null +++ b/Tests/RunCMake/IntermediateDirStrategy/ShortObjectDoesntChangeInstall-install-check.cmake @@ -0,0 +1,11 @@ +set(subdir "subdir/") +set(ext_suffix ".c") +if (RunCMake_GENERATOR MATCHES "(Visual Studio|Xcode)") + set(ext_suffix "") + set(subdir "") +endif () +set(path "${RunCMake_TEST_BINARY_DIR}/real_install/lib/objlib/objects-Debug/objlib/${subdir}obj${ext_suffix}${CMAKE_C_OUTPUT_EXTENSION}") +if (NOT EXISTS "${path}") + list(APPEND RunCMake_TEST_FAILED + "Expected install object '${path}' does not exist") +endif () diff --git a/Tests/RunCMake/IntermediateDirStrategy/ShortObjectDoesntChangeInstall.cmake b/Tests/RunCMake/IntermediateDirStrategy/ShortObjectDoesntChangeInstall.cmake new file mode 100644 index 0000000000..6fcce47b8e --- /dev/null +++ b/Tests/RunCMake/IntermediateDirStrategy/ShortObjectDoesntChangeInstall.cmake @@ -0,0 +1,5 @@ +set(CMAKE_INTERMEDIATE_DIR_STRATEGY SHORT CACHE STRING "" FORCE) +enable_language(C) + +add_library(objlib OBJECT subdir/obj.c) +install(TARGETS objlib OBJECTS DESTINATION lib/objlib) diff --git a/Tests/RunCMake/IntermediateDirStrategy/subdir/obj.c b/Tests/RunCMake/IntermediateDirStrategy/subdir/obj.c new file mode 100644 index 0000000000..a482372785 --- /dev/null +++ b/Tests/RunCMake/IntermediateDirStrategy/subdir/obj.c @@ -0,0 +1,4 @@ +int f(int a) +{ + return a; +} From b2ebfd7709e20095dee5a899a1123eaa4ab8ba48 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 17 Sep 2025 14:36:29 -0400 Subject: [PATCH 2/2] shortobj: properly force long names when computing long names The arguments need to be able to force a long name computation so that install paths can use the intended long paths. Use this computed state rather than asking the generator for its base state. Also force long paths for Visual Studio generators when computing it. Fixes: #27233 --- Source/cmLocalGenerator.cxx | 2 +- Source/cmLocalVisualStudioGenerator.cxx | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index ec9cd1a8ca..50a55d849b 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -4507,7 +4507,7 @@ std::string cmLocalGenerator::GetObjectFileNameWithoutTarget( } // Strip source file extension when shortening object file paths - if (this->UseShortObjectNames()) { + if (useShortObjectNames) { objectName = cmSystemTools::GetFilenameWithoutExtension(objectName); } // Store the new extension. diff --git a/Source/cmLocalVisualStudioGenerator.cxx b/Source/cmLocalVisualStudioGenerator.cxx index c45a957976..b699e1f698 100644 --- a/Source/cmLocalVisualStudioGenerator.cxx +++ b/Source/cmLocalVisualStudioGenerator.cxx @@ -99,8 +99,9 @@ void cmLocalVisualStudioGenerator::ComputeObjectFilenames( if (counts[cmSystemTools::LowerCase(longObjectName)] > 1) { const_cast(gt)->AddExplicitObjectName(sf); bool keptSourceExtension; + bool forceShortObjectName = false; longObjectName = this->GetObjectFileNameWithoutTarget( - *sf, dir_max, &keptSourceExtension, custom_ext); + *sf, dir_max, &keptSourceExtension, custom_ext, &forceShortObjectName); } si.second.ShortLoc.emplace(shortObjectName); si.second.LongLoc.Update(longObjectName);