diff options
author | Brad King <brad.king@kitware.com> | 2022-05-05 15:03:51 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-05-05 15:23:12 (GMT) |
commit | c6b0657f5b13bfe4cdb26cab1008cb83510e7fb0 (patch) | |
tree | 1947612ccc4ba9e8a6b946370afcf0f9e0330340 /Source/cmCoreTryCompile.cxx | |
parent | 7d78dcbebbb028c17de38e337942e0df061c6f20 (diff) | |
download | CMake-c6b0657f5b13bfe4cdb26cab1008cb83510e7fb0.zip CMake-c6b0657f5b13bfe4cdb26cab1008cb83510e7fb0.tar.gz CMake-c6b0657f5b13bfe4cdb26cab1008cb83510e7fb0.tar.bz2 |
cmCoreTryCompile: Move platform variable forwarding to dedicated block
Prepare to enable the behavior under more conditions.
Issue: #23219
Diffstat (limited to 'Source/cmCoreTryCompile.cxx')
-rw-r--r-- | Source/cmCoreTryCompile.cxx | 190 |
1 files changed, 93 insertions, 97 deletions
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index 324ce87..27a47aa 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -720,103 +720,6 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, fname.c_str()); } - // Forward a set of variables to the inner project cache. - { - std::set<std::string> vars; - vars.insert(&c_properties[lang_property_start], - &c_properties[lang_property_start + lang_property_size]); - vars.insert(&cxx_properties[lang_property_start], - &cxx_properties[lang_property_start + lang_property_size]); - vars.insert(&cuda_properties[lang_property_start], - &cuda_properties[lang_property_start + lang_property_size]); - vars.insert( - &fortran_properties[lang_property_start], - &fortran_properties[lang_property_start + lang_property_size]); - vars.insert(&hip_properties[lang_property_start], - &hip_properties[lang_property_start + lang_property_size]); - vars.insert(&objc_properties[lang_property_start], - &objc_properties[lang_property_start + lang_property_size]); - vars.insert( - &objcxx_properties[lang_property_start], - &objcxx_properties[lang_property_start + lang_property_size]); - vars.insert(&ispc_properties[lang_property_start], - &ispc_properties[lang_property_start + lang_property_size]); - vars.insert(&swift_properties[lang_property_start], - &swift_properties[lang_property_start + lang_property_size]); - vars.insert(kCMAKE_CUDA_ARCHITECTURES); - vars.insert(kCMAKE_CUDA_RUNTIME_LIBRARY); - vars.insert(kCMAKE_ENABLE_EXPORTS); - vars.insert(kCMAKE_HIP_ARCHITECTURES); - vars.insert(kCMAKE_HIP_RUNTIME_LIBRARY); - vars.insert(kCMAKE_ISPC_INSTRUCTION_SETS); - vars.insert(kCMAKE_ISPC_HEADER_SUFFIX); - vars.insert(kCMAKE_LINK_SEARCH_END_STATIC); - vars.insert(kCMAKE_LINK_SEARCH_START_STATIC); - vars.insert(kCMAKE_OSX_ARCHITECTURES); - vars.insert(kCMAKE_OSX_DEPLOYMENT_TARGET); - vars.insert(kCMAKE_OSX_SYSROOT); - vars.insert(kCMAKE_APPLE_ARCH_SYSROOTS); - vars.insert(kCMAKE_POSITION_INDEPENDENT_CODE); - vars.insert(kCMAKE_SYSROOT); - vars.insert(kCMAKE_SYSROOT_COMPILE); - vars.insert(kCMAKE_SYSROOT_LINK); - vars.insert(kCMAKE_WARN_DEPRECATED); - vars.emplace("CMAKE_MSVC_RUNTIME_LIBRARY"_s); - - if (cmValue varListStr = this->Makefile->GetDefinition( - kCMAKE_TRY_COMPILE_PLATFORM_VARIABLES)) { - std::vector<std::string> varList = cmExpandedList(*varListStr); - vars.insert(varList.begin(), varList.end()); - } - - if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0083) == - cmPolicies::NEW) { - // To ensure full support of PIE, propagate cache variables - // driving the link options - vars.insert(&c_properties[pie_property_start], - &c_properties[pie_property_start + pie_property_size]); - vars.insert(&cxx_properties[pie_property_start], - &cxx_properties[pie_property_start + pie_property_size]); - vars.insert(&cuda_properties[pie_property_start], - &cuda_properties[pie_property_start + pie_property_size]); - vars.insert( - &fortran_properties[pie_property_start], - &fortran_properties[pie_property_start + pie_property_size]); - vars.insert(&hip_properties[pie_property_start], - &hip_properties[pie_property_start + pie_property_size]); - vars.insert(&objc_properties[pie_property_start], - &objc_properties[pie_property_start + pie_property_size]); - vars.insert( - &objcxx_properties[pie_property_start], - &objcxx_properties[pie_property_start + pie_property_size]); - vars.insert(&ispc_properties[pie_property_start], - &ispc_properties[pie_property_start + pie_property_size]); - vars.insert(&swift_properties[pie_property_start], - &swift_properties[pie_property_start + pie_property_size]); - } - - /* for the TRY_COMPILEs we want to be able to specify the architecture. - So the user can set CMAKE_OSX_ARCHITECTURES to i386;ppc and then set - CMAKE_TRY_COMPILE_OSX_ARCHITECTURES first to i386 and then to ppc to - have the tests run for each specific architecture. Since - cmLocalGenerator doesn't allow building for "the other" - architecture only via CMAKE_OSX_ARCHITECTURES. - */ - if (cmValue tcArchs = this->Makefile->GetDefinition( - kCMAKE_TRY_COMPILE_OSX_ARCHITECTURES)) { - vars.erase(kCMAKE_OSX_ARCHITECTURES); - std::string flag = "-DCMAKE_OSX_ARCHITECTURES=" + *tcArchs; - cmakeFlags.push_back(std::move(flag)); - } - - for (std::string const& var : vars) { - if (cmValue val = this->Makefile->GetDefinition(var)) { - std::string flag = "-D" + var + "=" + *val; - cmakeFlags.push_back(std::move(flag)); - } - } - } - /* Set the appropriate policy information for ENABLE_EXPORTS */ fprintf(fout, "cmake_policy(SET CMP0065 %s)\n", this->Makefile->GetPolicyStatus(cmPolicies::CMP0065) == @@ -959,6 +862,99 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, projectName = "CMAKE_TRY_COMPILE"; } + // Forward a set of variables to the inner project cache. + if (this->SrcFileSignature) { + std::set<std::string> vars; + vars.insert(&c_properties[lang_property_start], + &c_properties[lang_property_start + lang_property_size]); + vars.insert(&cxx_properties[lang_property_start], + &cxx_properties[lang_property_start + lang_property_size]); + vars.insert(&cuda_properties[lang_property_start], + &cuda_properties[lang_property_start + lang_property_size]); + vars.insert(&fortran_properties[lang_property_start], + &fortran_properties[lang_property_start + lang_property_size]); + vars.insert(&hip_properties[lang_property_start], + &hip_properties[lang_property_start + lang_property_size]); + vars.insert(&objc_properties[lang_property_start], + &objc_properties[lang_property_start + lang_property_size]); + vars.insert(&objcxx_properties[lang_property_start], + &objcxx_properties[lang_property_start + lang_property_size]); + vars.insert(&ispc_properties[lang_property_start], + &ispc_properties[lang_property_start + lang_property_size]); + vars.insert(&swift_properties[lang_property_start], + &swift_properties[lang_property_start + lang_property_size]); + vars.insert(kCMAKE_CUDA_ARCHITECTURES); + vars.insert(kCMAKE_CUDA_RUNTIME_LIBRARY); + vars.insert(kCMAKE_ENABLE_EXPORTS); + vars.insert(kCMAKE_HIP_ARCHITECTURES); + vars.insert(kCMAKE_HIP_RUNTIME_LIBRARY); + vars.insert(kCMAKE_ISPC_INSTRUCTION_SETS); + vars.insert(kCMAKE_ISPC_HEADER_SUFFIX); + vars.insert(kCMAKE_LINK_SEARCH_END_STATIC); + vars.insert(kCMAKE_LINK_SEARCH_START_STATIC); + vars.insert(kCMAKE_OSX_ARCHITECTURES); + vars.insert(kCMAKE_OSX_DEPLOYMENT_TARGET); + vars.insert(kCMAKE_OSX_SYSROOT); + vars.insert(kCMAKE_APPLE_ARCH_SYSROOTS); + vars.insert(kCMAKE_POSITION_INDEPENDENT_CODE); + vars.insert(kCMAKE_SYSROOT); + vars.insert(kCMAKE_SYSROOT_COMPILE); + vars.insert(kCMAKE_SYSROOT_LINK); + vars.insert(kCMAKE_WARN_DEPRECATED); + vars.emplace("CMAKE_MSVC_RUNTIME_LIBRARY"_s); + + if (cmValue varListStr = this->Makefile->GetDefinition( + kCMAKE_TRY_COMPILE_PLATFORM_VARIABLES)) { + std::vector<std::string> varList = cmExpandedList(*varListStr); + vars.insert(varList.begin(), varList.end()); + } + + if (this->Makefile->GetPolicyStatus(cmPolicies::CMP0083) == + cmPolicies::NEW) { + // To ensure full support of PIE, propagate cache variables + // driving the link options + vars.insert(&c_properties[pie_property_start], + &c_properties[pie_property_start + pie_property_size]); + vars.insert(&cxx_properties[pie_property_start], + &cxx_properties[pie_property_start + pie_property_size]); + vars.insert(&cuda_properties[pie_property_start], + &cuda_properties[pie_property_start + pie_property_size]); + vars.insert(&fortran_properties[pie_property_start], + &fortran_properties[pie_property_start + pie_property_size]); + vars.insert(&hip_properties[pie_property_start], + &hip_properties[pie_property_start + pie_property_size]); + vars.insert(&objc_properties[pie_property_start], + &objc_properties[pie_property_start + pie_property_size]); + vars.insert(&objcxx_properties[pie_property_start], + &objcxx_properties[pie_property_start + pie_property_size]); + vars.insert(&ispc_properties[pie_property_start], + &ispc_properties[pie_property_start + pie_property_size]); + vars.insert(&swift_properties[pie_property_start], + &swift_properties[pie_property_start + pie_property_size]); + } + + /* for the TRY_COMPILEs we want to be able to specify the architecture. + So the user can set CMAKE_OSX_ARCHITECTURES to i386;ppc and then set + CMAKE_TRY_COMPILE_OSX_ARCHITECTURES first to i386 and then to ppc to + have the tests run for each specific architecture. Since + cmLocalGenerator doesn't allow building for "the other" + architecture only via CMAKE_OSX_ARCHITECTURES. + */ + if (cmValue tcArchs = this->Makefile->GetDefinition( + kCMAKE_TRY_COMPILE_OSX_ARCHITECTURES)) { + vars.erase(kCMAKE_OSX_ARCHITECTURES); + std::string flag = "-DCMAKE_OSX_ARCHITECTURES=" + *tcArchs; + cmakeFlags.push_back(std::move(flag)); + } + + for (std::string const& var : vars) { + if (cmValue val = this->Makefile->GetDefinition(var)) { + std::string flag = "-D" + var + "=" + *val; + cmakeFlags.push_back(std::move(flag)); + } + } + } + if (this->Makefile->GetState()->UseGhsMultiIDE()) { // Forward the GHS variables to the inner project cache. for (std::string const& var : ghs_platform_vars) { |