Skip to content
Snippets Groups Projects
Commit 144be54d authored by Brad King's avatar Brad King
Browse files

try_compile: Propagate CMP0126 to the generated test project

Set policy CMP0126 to the value used in the calling project.
It may affect toolchain file behavior.
parent 4ff651eb
No related branches found
No related tags found
No related merge requests found
Showing
with 29 additions and 0 deletions
......@@ -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;
......
^try_compile CMP0126='NEW' VAR='1'
include("${CMAKE_CURRENT_LIST_DIR}/CMP0126-toolchain.cmake")
cmake_policy(SET CMP0126 NEW)
enable_language(C)
^try_compile CMP0126='OLD' VAR='2'
include("${CMAKE_CURRENT_LIST_DIR}/CMP0126-toolchain.cmake")
cmake_policy(SET CMP0126 OLD)
enable_language(C)
^try_compile CMP0126='OLD' VAR='2'
include("${CMAKE_CURRENT_LIST_DIR}/CMP0126-toolchain.cmake")
# leave CMP0126 unset
enable_language(C)
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()
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment