summaryrefslogtreecommitdiffstats
path: root/Source/cmCoreTryCompile.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-10-17 14:22:43 (GMT)
committerKitware Robot <kwrobot@kitware.com>2023-10-17 14:22:54 (GMT)
commitdd78592ba1f6b90b5310f18de9cac8efefcebb40 (patch)
treeee7e63b73d6d0c15da836a3ab45789f35fcb90a2 /Source/cmCoreTryCompile.cxx
parent3de46de11a2e98184c445f728f438939eb7a8519 (diff)
parent8f9f371668e5e9dec6c0992d51eb1c4bc793879f (diff)
downloadCMake-dd78592ba1f6b90b5310f18de9cac8efefcebb40.zip
CMake-dd78592ba1f6b90b5310f18de9cac8efefcebb40.tar.gz
CMake-dd78592ba1f6b90b5310f18de9cac8efefcebb40.tar.bz2
Merge topic 'try_compile-alias-targets'
8f9f371668 try_compile: Add support for using ALIAS targets 9f8aa94192 Add missing `OUTPUT` in ExportImport test Acked-by: Kitware Robot <kwrobot@kitware.com> Tested-by: buildbot <buildbot@kitware.com> Merge-request: !8877
Diffstat (limited to 'Source/cmCoreTryCompile.cxx')
-rw-r--r--Source/cmCoreTryCompile.cxx24
1 files changed, 23 insertions, 1 deletions
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx
index 3596d47..7f7c747 100644
--- a/Source/cmCoreTryCompile.cxx
+++ b/Source/cmCoreTryCompile.cxx
@@ -857,8 +857,30 @@ cm::optional<cmTryCompileResult> cmCoreTryCompile::TryCompileCode(
fclose(fout);
return cm::nullopt;
}
- fprintf(fout, "\ninclude(\"${CMAKE_CURRENT_LIST_DIR}/%s\")\n\n",
+ fprintf(fout, "\ninclude(\"${CMAKE_CURRENT_LIST_DIR}/%s\")\n",
fname.c_str());
+ // Create all relevant alias targets
+ if (arguments.LinkLibraries) {
+ const auto& aliasTargets = this->Makefile->GetAliasTargets();
+ for (std::string const& i : *arguments.LinkLibraries) {
+ auto alias = aliasTargets.find(i);
+ if (alias != aliasTargets.end()) {
+ const auto& aliasTarget =
+ this->Makefile->FindTargetToUse(alias->second);
+ // Create equivalent library/executable alias
+ if (aliasTarget->GetType() == cmStateEnums::EXECUTABLE) {
+ fprintf(fout, "add_executable(\"%s\" ALIAS \"%s\")\n", i.c_str(),
+ alias->second.c_str());
+ } else {
+ // Other cases like UTILITY and GLOBAL_TARGET are excluded when
+ // arguments.LinkLibraries is initially parsed in this function.
+ fprintf(fout, "add_library(\"%s\" ALIAS \"%s\")\n", i.c_str(),
+ alias->second.c_str());
+ }
+ }
+ }
+ }
+ fprintf(fout, "\n");
}
/* Set the appropriate policy information for ENABLE_EXPORTS */