Files
CMake/Tests/RunCMake/LinkLibrariesStrategy/RunCMakeTest.cmake
Brad King 39fd396421 LINK_LIBRARIES_STRATEGY: Rename strategies to clarify expectations
Since commit 7abd3137b7 (Linking: Optionally reorder direct dependencies
from LINK_LIBRARIES, 2024-09-19, v3.31.0-rc1~53^2) the strategy name
`PRESERVE_ORDER` has led users to expect that it strictly preserves
order.  While the part of the link line generation logic controlled by
`LINK_LIBRARIES_STRATEGY` does preserve order, it is not the last step.
Toolchain-specific de-duplication can cause the order to change on the
actual link line generated in the build system.

Rename the strategies:

* `PRESERVE_ORDER` => `REORDER_MINIMALLY`
* `REORDER`        => `REORDER_FREELY`

The new names make it clear that reordering is always possible, just to
varying degrees.  Update the `LINK_LIBRARIES_STRATEGY` documentation to
clarify that the strategies do not directly control the final link line.

Fixes: #26400
Issue: #26271
2024-10-25 10:23:37 -04:00

52 lines
1.8 KiB
CMake

cmake_minimum_required(VERSION 3.30)
include(RunCMake)
if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
set(RunCMake_TEST_OPTIONS -DCMAKE_CONFIGURATION_TYPES=Debug)
else()
set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
endif()
# Detect information from the toolchain:
# - CMAKE_C_LINK_LIBRARIES_PROCESSING
run_cmake(Inspect)
include("${RunCMake_BINARY_DIR}/Inspect-build/info.cmake")
run_cmake(Unknown)
function(run_strategy case exe)
foreach(cmp0179 OLD NEW)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${case}-CMP0179-${cmp0179}-build)
set(RunCMake_TEST_VARIANT_DESCRIPTION "...CMP0179-${cmp0179}")
if("DEDUPLICATION=ALL" IN_LIST CMAKE_C_LINK_LIBRARIES_PROCESSING)
if("ORDER=REVERSE" IN_LIST CMAKE_C_LINK_LIBRARIES_PROCESSING AND cmp0179 STREQUAL "OLD")
set(RunCMake-stderr-file ${case}-stderr-dedup-reverse.txt)
else()
set(RunCMake-stderr-file ${case}-stderr-dedup.txt)
endif()
endif()
run_cmake_with_options(${case} -DCMAKE_POLICY_DEFAULT_CMP0179=${cmp0179})
unset(RunCMake-stderr-file)
set(RunCMake_TEST_NO_CLEAN 1)
run_cmake_command(${case}-build ${CMAKE_COMMAND} --build . --config Debug)
if(exe)
if("DEDUPLICATION=ALL" IN_LIST CMAKE_C_LINK_LIBRARIES_PROCESSING)
if("ORDER=REVERSE" IN_LIST CMAKE_C_LINK_LIBRARIES_PROCESSING AND cmp0179 STREQUAL "OLD")
set(RunCMake-stdout-file ${case}-run-stdout-dedup-reverse.txt)
else()
set(RunCMake-stdout-file ${case}-run-stdout-dedup.txt)
endif()
endif()
run_cmake_command(${case}-run ${RunCMake_TEST_BINARY_DIR}/${exe})
unset(RunCMake-stdout-file)
endif()
endforeach()
endfunction()
run_strategy(Basic-REORDER_MINIMALLY "main")
run_strategy(Basic-REORDER_FREELY "main")
run_cmake(Duplicate-REORDER_MINIMALLY)
run_cmake(Duplicate-REORDER_FREELY)