mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
fileAPI: Expose CMAKE_<LANG>_COMPILER_ARG1
Compiler arguments coming from CC environment variables or multi-element CMAKE_<LANG>_COMPILER variables set by toolchain files were previously not exposed in the file API. Among other possible problems, this caused clients to determine wrong system include paths and built-in preprocessor macros by calling the compiler without these important arguments. This is fixed by adding an optional "commandFragment" attribute to the compiler description in the `toolchains` object, containing these arguments as a command line fragment. This is already the form in which they are internally stored in the CMAKE_<LANG>_COMPILER_ARG1 variable, so all that is required is adding this variable to the set of exported variables, besides some logic to omit it if empty. Issue: #22568
This commit is contained in:
@@ -24,6 +24,7 @@ struct ToolchainVariable
|
||||
std::string ObjectKey;
|
||||
std::string VariableSuffix;
|
||||
bool IsList;
|
||||
bool OmitEmpty;
|
||||
};
|
||||
|
||||
class Toolchains
|
||||
@@ -74,22 +75,23 @@ Json::Value Toolchains::DumpToolchains()
|
||||
Json::Value Toolchains::DumpToolchain(std::string const& lang)
|
||||
{
|
||||
static std::vector<ToolchainVariable> const CompilerVariables{
|
||||
{ "path", "COMPILER", false },
|
||||
{ "id", "COMPILER_ID", false },
|
||||
{ "version", "COMPILER_VERSION", false },
|
||||
{ "target", "COMPILER_TARGET", false },
|
||||
{ "path", "COMPILER", false, false },
|
||||
{ "commandFragment", "COMPILER_ARG1", false, true },
|
||||
{ "id", "COMPILER_ID", false, false },
|
||||
{ "version", "COMPILER_VERSION", false, false },
|
||||
{ "target", "COMPILER_TARGET", false, false },
|
||||
};
|
||||
|
||||
static std::vector<ToolchainVariable> const CompilerImplicitVariables{
|
||||
{ "includeDirectories", "IMPLICIT_INCLUDE_DIRECTORIES", true },
|
||||
{ "linkDirectories", "IMPLICIT_LINK_DIRECTORIES", true },
|
||||
{ "linkFrameworkDirectories", "IMPLICIT_LINK_FRAMEWORK_DIRECTORIES",
|
||||
true },
|
||||
{ "linkLibraries", "IMPLICIT_LINK_LIBRARIES", true },
|
||||
{ "includeDirectories", "IMPLICIT_INCLUDE_DIRECTORIES", true, false },
|
||||
{ "linkDirectories", "IMPLICIT_LINK_DIRECTORIES", true, false },
|
||||
{ "linkFrameworkDirectories", "IMPLICIT_LINK_FRAMEWORK_DIRECTORIES", true,
|
||||
false },
|
||||
{ "linkLibraries", "IMPLICIT_LINK_LIBRARIES", true, false },
|
||||
};
|
||||
|
||||
static ToolchainVariable const SourceFileExtensionsVariable{
|
||||
"sourceFileExtensions", "SOURCE_FILE_EXTENSIONS", true
|
||||
"sourceFileExtensions", "SOURCE_FILE_EXTENSIONS", true, false
|
||||
};
|
||||
|
||||
auto const& mf =
|
||||
@@ -128,15 +130,17 @@ void Toolchains::DumpToolchainVariable(cmMakefile const* mf,
|
||||
cmValue data = mf->GetDefinition(variableName);
|
||||
if (data) {
|
||||
cmList values(data);
|
||||
Json::Value jsonArray = Json::arrayValue;
|
||||
for (auto const& value : values) {
|
||||
jsonArray.append(value);
|
||||
if (!variable.OmitEmpty || !values.empty()) {
|
||||
Json::Value jsonArray = Json::arrayValue;
|
||||
for (auto const& value : values) {
|
||||
jsonArray.append(value);
|
||||
}
|
||||
object[variable.ObjectKey] = jsonArray;
|
||||
}
|
||||
object[variable.ObjectKey] = jsonArray;
|
||||
}
|
||||
} else {
|
||||
cmValue def = mf->GetDefinition(variableName);
|
||||
if (def) {
|
||||
if (def && (!variable.OmitEmpty || !def.IsEmpty())) {
|
||||
object[variable.ObjectKey] = *def;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user