diff options
author | Cristian Le <cristian.le@mpsd.mpg.de> | 2023-10-16 16:26:12 (GMT) |
---|---|---|
committer | Cristian Le <cristian.le@mpsd.mpg.de> | 2023-10-16 18:22:23 (GMT) |
commit | 8f9f371668e5e9dec6c0992d51eb1c4bc793879f (patch) | |
tree | 18ce7f4394b01586004f0a2afa758a938d9400ca /Source/cmCoreTryCompile.cxx | |
parent | 9f8aa941924bb46ebb311dff06f6ef54bb16ffef (diff) | |
download | CMake-8f9f371668e5e9dec6c0992d51eb1c4bc793879f.zip CMake-8f9f371668e5e9dec6c0992d51eb1c4bc793879f.tar.gz CMake-8f9f371668e5e9dec6c0992d51eb1c4bc793879f.tar.bz2 |
try_compile: Add support for using ALIAS targets
Fixes: #25337
Signed-off-by: Cristian Le <cristian.le@mpsd.mpg.de>
Diffstat (limited to 'Source/cmCoreTryCompile.cxx')
-rw-r--r-- | Source/cmCoreTryCompile.cxx | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index 69d5ffc..4c93556 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -856,8 +856,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 */ |