summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorRobert Maynard <rmaynard@nvidia.com>2021-07-12 17:26:36 (GMT)
committerBrad King <brad.king@kitware.com>2021-07-19 16:55:18 (GMT)
commitaa3ab3eb925a601e3acd2d9f569fc3183fab2f8b (patch)
tree2c373c1699c38a2b4383f73af7cc843b52f25308 /Source
parenta42b753c419136e3593042c62129bcaa36b50146 (diff)
downloadCMake-aa3ab3eb925a601e3acd2d9f569fc3183fab2f8b.zip
CMake-aa3ab3eb925a601e3acd2d9f569fc3183fab2f8b.tar.gz
CMake-aa3ab3eb925a601e3acd2d9f569fc3183fab2f8b.tar.bz2
find_library: Infer library prefix and suffix when in script mode
This aligns `find_library` with the documentation that states it can be called from script mode. This is done by infering the proper prefix and suffix values when `find_library` is called when the `CMAKE_FIND_LIBRARY*` are not set. This also means that `find_library` won't produce obscure error messages about unset definitions. Fixes: #22027
Diffstat (limited to 'Source')
-rw-r--r--Source/cmFindLibraryCommand.cxx35
1 files changed, 31 insertions, 4 deletions
diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx
index 0cbe637..ef960d1 100644
--- a/Source/cmFindLibraryCommand.cxx
+++ b/Source/cmFindLibraryCommand.cxx
@@ -259,6 +259,34 @@ struct cmFindLibraryHelper
};
};
+namespace {
+
+std::string const& get_prefixes(cmMakefile* mf)
+{
+#ifdef _WIN32
+ static std::string defaultPrefix = ";lib";
+#else
+ static std::string defaultPrefix = "lib";
+#endif
+ cmProp prefixProp = mf->GetDefinition("CMAKE_FIND_LIBRARY_PREFIXES");
+ return (prefixProp) ? *prefixProp : defaultPrefix;
+}
+
+std::string const& get_suffixes(cmMakefile* mf)
+{
+#ifdef _WIN32
+ static std::string defaultSuffix = ".lib;.dll.a;.a";
+#elif defined(__APPLE__)
+ static std::string defaultSuffix = ".tbd;.dylib;.so;.a";
+#elif defined(__hpux)
+ static std::string defaultSuffix = ".sl;.so;.a";
+#else
+ static std::string defaultSuffix = ".so;.a";
+#endif
+ cmProp suffixProp = mf->GetDefinition("CMAKE_FIND_LIBRARY_SUFFIXES");
+ return (suffixProp) ? *suffixProp : defaultSuffix;
+}
+}
cmFindLibraryHelper::cmFindLibraryHelper(std::string debugName, cmMakefile* mf,
cmFindBase const* base)
: Makefile(mf)
@@ -268,10 +296,9 @@ cmFindLibraryHelper::cmFindLibraryHelper(std::string debugName, cmMakefile* mf,
this->GG = this->Makefile->GetGlobalGenerator();
// Collect the list of library name prefixes/suffixes to try.
- std::string const& prefixes_list =
- this->Makefile->GetRequiredDefinition("CMAKE_FIND_LIBRARY_PREFIXES");
- std::string const& suffixes_list =
- this->Makefile->GetRequiredDefinition("CMAKE_FIND_LIBRARY_SUFFIXES");
+ std::string const& prefixes_list = get_prefixes(this->Makefile);
+ std::string const& suffixes_list = get_suffixes(this->Makefile);
+
cmExpandList(prefixes_list, this->Prefixes, true);
cmExpandList(suffixes_list, this->Suffixes, true);
this->RegexFromList(this->PrefixRegexStr, this->Prefixes);