diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2018-11-19 16:23:45 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2018-12-01 16:56:23 (GMT) |
commit | 29f9db5c63dbfa53acdb449fad78d716a4113a88 (patch) | |
tree | 6b6ba4b75a7e906a455024292fe9f5f25299c8a1 /Source/cmCoreTryCompile.cxx | |
parent | 78c2edb129594b198157799b3eb327f4a3915908 (diff) | |
download | CMake-29f9db5c63dbfa53acdb449fad78d716a4113a88.zip CMake-29f9db5c63dbfa53acdb449fad78d716a4113a88.tar.gz CMake-29f9db5c63dbfa53acdb449fad78d716a4113a88.tar.bz2 |
try_compile/try_run: Add support for LINK_OPTIONS option.
Diffstat (limited to 'Source/cmCoreTryCompile.cxx')
-rw-r--r-- | Source/cmCoreTryCompile.cxx | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index f6ec606..541ae76 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -121,6 +121,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, std::string cxxExtensions; std::string cudaExtensions; std::vector<std::string> targets; + std::vector<std::string> linkOptions; std::string libsToLink = " "; bool useOldLinkLibs = true; char targetNameBuf[64]; @@ -144,6 +145,7 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, DoingNone, DoingCMakeFlags, DoingCompileDefinitions, + DoingLinkOptions, DoingLinkLibraries, DoingOutputVariable, DoingCopyFile, @@ -165,6 +167,8 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, doing = DoingCMakeFlags; } else if (argv[i] == "COMPILE_DEFINITIONS") { doing = DoingCompileDefinitions; + } else if (argv[i] == "LINK_OPTIONS") { + doing = DoingLinkOptions; } else if (argv[i] == "LINK_LIBRARIES") { doing = DoingLinkLibraries; useOldLinkLibs = false; @@ -208,6 +212,8 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, cmakeFlags.push_back(argv[i]); } else if (doing == DoingCompileDefinitions) { compileDefs.push_back(argv[i]); + } else if (doing == DoingLinkOptions) { + linkOptions.push_back(argv[i]); } else if (doing == DoingLinkLibraries) { libsToLink += "\"" + cmSystemTools::TrimWhitespace(argv[i]) + "\" "; if (cmTarget* tgt = this->Makefile->FindTargetToUse(argv[i])) { @@ -814,6 +820,23 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, } } + if (!linkOptions.empty()) { + std::vector<std::string> options; + options.reserve(linkOptions.size()); + for (const auto& option : linkOptions) { + options.emplace_back(cmOutputConverter::EscapeForCMake(option)); + } + + if (targetType == cmStateEnums::STATIC_LIBRARY) { + fprintf(fout, + "set_property(TARGET %s PROPERTY STATIC_LIBRARY_OPTIONS %s)\n", + targetName.c_str(), cmJoin(options, " ").c_str()); + } else { + fprintf(fout, "target_link_options(%s PRIVATE %s)\n", + targetName.c_str(), cmJoin(options, " ").c_str()); + } + } + if (useOldLinkLibs) { fprintf(fout, "target_link_libraries(%s ${LINK_LIBRARIES})\n", targetName.c_str()); |