Merge topic 'cmp0181-trycompile-policy-order'

5e52f92a2a try_compile: Add support for toolchain files to query CMP0181

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12540
This commit is contained in:
Brad King
2026-09-23 13:47:31 -04:00
committed by Kitware Robot
13 changed files with 30 additions and 9 deletions
+4
View File
@@ -38,4 +38,8 @@ expand the ``LINKER:`` prefix.
.. |WARNS_OR_DOES_NOT_WARN| replace:: does *not* warn
.. include:: include/STANDARD_ADVICE.rst
.. versionchanged:: 4.5
The policy is now set in :command:`try_compile` test projects early enough
to be queried by :variable:`toolchain files <CMAKE_TOOLCHAIN_FILE>`.
.. include:: include/DEPRECATED.rst
+6 -9
View File
@@ -687,6 +687,12 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
fprintf(fout, "cmake_policy(SET CMP0128 OLD)\n");
}
// Set LINKER: prefix expansion to match outer project.
if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0181) !=
cmPolicies::NEW) {
fprintf(fout, "cmake_policy(SET CMP0181 OLD)\n");
}
/* Set MSVC link -machine: policy to match outer project. */
if (cmValue cmp0197 = this->Makefile->GetDefinition(kCMAKE_MSVC_CMP0197)) {
fprintf(fout, "cmake_policy(SET CMP0197 %s)\n",
@@ -907,15 +913,6 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
? "OLD"
: "NEW");
/* Set the appropriate policy information for the LINKER: prefix
* expansion
*/
fprintf(fout, "cmake_policy(SET CMP0181 %s)\n",
this->Makefile->GetPolicyStatus(cmPolicies::CMP0181) ==
cmPolicies::NEW
? "NEW"
: "OLD");
// Honor CMAKE_EXE_LINKER_FLAGS in Swift if the outer project does.
fprintf(fout, "cmake_policy(SET CMP0214 %s)\n",
this->Makefile->GetPolicyStatus(cmPolicies::CMP0214) ==
@@ -0,0 +1 @@
^try_compile CMP0181='NEW'
@@ -0,0 +1 @@
include("${CMAKE_CURRENT_LIST_DIR}/CMP0181-toolchain.cmake")
@@ -0,0 +1,2 @@
cmake_policy(SET CMP0181 NEW)
enable_language(C)
@@ -0,0 +1 @@
^try_compile CMP0181='OLD'
@@ -0,0 +1 @@
include("${CMAKE_CURRENT_LIST_DIR}/CMP0181-toolchain.cmake")
@@ -0,0 +1,2 @@
cmake_policy(SET CMP0181 OLD)
enable_language(C)
@@ -0,0 +1 @@
^try_compile CMP0181='OLD'
@@ -0,0 +1 @@
include("${CMAKE_CURRENT_LIST_DIR}/CMP0181-toolchain.cmake")
@@ -0,0 +1,2 @@
# leave CMP0181 unset
enable_language(C)
@@ -0,0 +1,5 @@
get_property(_IN_TC GLOBAL PROPERTY IN_TRY_COMPILE)
if(_IN_TC)
cmake_policy(GET CMP0181 cmp0181)
message("try_compile CMP0181='${cmp0181}'")
endif()
@@ -14,6 +14,9 @@ run_cmake_toolchain(LinkFlagsInit)
run_cmake_toolchain(CMP0126-NEW)
run_cmake_toolchain(CMP0126-OLD)
run_cmake_toolchain(CMP0126-WARN)
run_cmake_toolchain(CMP0181-NEW)
run_cmake_toolchain(CMP0181-OLD)
run_cmake_toolchain(CMP0181-WARN)
run_cmake_toolchain(CMP0210-NEW)
run_cmake_toolchain(CMP0210-OLD)
run_cmake_toolchain(CMP0210-WARN)