Merge topic 'toolchain-CMP0126'

144be54dd3 try_compile: Propagate CMP0126 to the generated test project

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !6366
This commit is contained in:
Brad King
2021-07-21 15:31:16 +00:00
committed by Kitware Robot
12 changed files with 29 additions and 0 deletions

View File

@@ -570,6 +570,13 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv,
*cmp0123 == "NEW"_s ? "NEW" : "OLD");
}
/* Set cache/normal variable policy to match outer project.
It may affect toolchain files. */
if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0126) !=
cmPolicies::NEW) {
fprintf(fout, "cmake_policy(SET CMP0126 OLD)\n");
}
std::string projectLangs;
for (std::string const& li : testLangs) {
projectLangs += " " + li;

View File

@@ -0,0 +1 @@
^try_compile CMP0126='NEW' VAR='1'

View File

@@ -0,0 +1 @@
include("${CMAKE_CURRENT_LIST_DIR}/CMP0126-toolchain.cmake")

View File

@@ -0,0 +1,2 @@
cmake_policy(SET CMP0126 NEW)
enable_language(C)

View File

@@ -0,0 +1 @@
^try_compile CMP0126='OLD' VAR='2'

View File

@@ -0,0 +1 @@
include("${CMAKE_CURRENT_LIST_DIR}/CMP0126-toolchain.cmake")

View File

@@ -0,0 +1,2 @@
cmake_policy(SET CMP0126 OLD)
enable_language(C)

View File

@@ -0,0 +1 @@
^try_compile CMP0126='OLD' VAR='2'

View File

@@ -0,0 +1 @@
include("${CMAKE_CURRENT_LIST_DIR}/CMP0126-toolchain.cmake")

View File

@@ -0,0 +1,2 @@
# leave CMP0126 unset
enable_language(C)

View File

@@ -0,0 +1,7 @@
get_property(_IN_TC GLOBAL PROPERTY IN_TRY_COMPILE)
if(_IN_TC)
cmake_policy(GET CMP0126 cmp0126)
set(VAR 1)
set(VAR 2 CACHE STRING "")
message("try_compile CMP0126='${cmp0126}' VAR='${VAR}'")
endif()

View File

@@ -11,6 +11,9 @@ run_cmake_toolchain(CheckLanguage)
run_cmake_toolchain(FlagsInit)
run_cmake_toolchain(LangVars)
run_cmake_toolchain(LinkFlagsInit)
run_cmake_toolchain(CMP0126-NEW)
run_cmake_toolchain(CMP0126-OLD)
run_cmake_toolchain(CMP0126-WARN)
function(run_IncludeDirectories)
run_cmake_toolchain(IncludeDirectories)