From 5bf9a290e74d14de7f0dc56bf31e273d7a02e282 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 5 Jun 2020 10:04:50 -0400 Subject: CUDA: Fix CUDA_ARCHITECTURES policy CMP0104 check in try_compile Since commit e98588aaba (CUDA: Add CUDA_ARCHITECTURES target property, 2020-03-12), `CMAKE_CUDA_ARCHITECTURES` is both initialized and required by policy CMP0104's `NEW` behavior. Inside a `try_compile` project we use `cmake_minimum_required(VERSION ...)` with the current running version of CMake. Now that our version number is 3.18, `CMP0104` gets set to `NEW` in the `try_compile`. If the outer projects does not set the policy then `CMAKE_CUDA_ARCHITECTURES` is not available and the `try_compile` fails to generate. Teach `try_compile` to check the outer project's policy status and set policy CMP0104 to `OLD` if needed to match. Fixes: #20794 --- Source/cmCoreTryCompile.cxx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index cc2cd01..a7acadc 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -567,6 +567,14 @@ int cmCoreTryCompile::TryCompileCode(std::vector const& argv, *msvcRuntimeLibraryDefault ? "NEW" : "OLD"); } + /* Set CUDA architectures policy to match outer project. */ + if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0104) != + cmPolicies::NEW && + testLangs.find("CUDA") != testLangs.end() && + this->Makefile->GetSafeDefinition(kCMAKE_CUDA_ARCHITECTURES).empty()) { + fprintf(fout, "cmake_policy(SET CMP0104 OLD)\n"); + } + std::string projectLangs; for (std::string const& li : testLangs) { projectLangs += " " + li; -- cgit v0.12