Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
CMake
CMake
Commits
2628dec1
Commit
2628dec1
authored
Oct 09, 2016
by
Stephen Kelly
Browse files
cmLocalGenerator: Store variable replacements as state
These do not change over the lifetime of the cmLocalGenerator.
parent
315b9a31
Pipeline
#31158
passed with stage
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Source/cmLocalGenerator.cxx
View file @
2628dec1
...
...
@@ -40,6 +40,28 @@
#include
<StorageDefs.h>
#endif
// List of variables that are replaced when
// rules are expanced. These variables are
// replaced in the form <var> with GetSafeDefinition(var).
// ${LANG} is replaced in the variable first with all enabled
// languages.
static
const
char
*
ruleReplaceVars
[]
=
{
"CMAKE_${LANG}_COMPILER"
,
"CMAKE_SHARED_LIBRARY_CREATE_${LANG}_FLAGS"
,
"CMAKE_SHARED_MODULE_CREATE_${LANG}_FLAGS"
,
"CMAKE_SHARED_MODULE_${LANG}_FLAGS"
,
"CMAKE_SHARED_LIBRARY_${LANG}_FLAGS"
,
"CMAKE_${LANG}_LINK_FLAGS"
,
"CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG"
,
"CMAKE_${LANG}_ARCHIVE"
,
"CMAKE_AR"
,
"CMAKE_CURRENT_SOURCE_DIR"
,
"CMAKE_CURRENT_BINARY_DIR"
,
"CMAKE_RANLIB"
,
"CMAKE_LINKER"
,
"CMAKE_CL_SHOWINCLUDES_PREFIX"
};
cmLocalGenerator
::
cmLocalGenerator
(
cmGlobalGenerator
*
gg
,
cmMakefile
*
makefile
)
:
cmOutputConverter
(
makefile
->
GetStateSnapshot
())
,
StateSnapshot
(
makefile
->
GetStateSnapshot
())
...
...
@@ -56,6 +78,58 @@ cmLocalGenerator::cmLocalGenerator(cmGlobalGenerator* gg, cmMakefile* makefile)
this
->
BackwardsCompatibilityFinal
=
false
;
this
->
ComputeObjectMaxPath
();
std
::
vector
<
std
::
string
>
enabledLanguages
=
this
->
GetState
()
->
GetEnabledLanguages
();
this
->
CompilerSysroot
=
this
->
Makefile
->
GetSafeDefinition
(
"CMAKE_SYSROOT"
);
for
(
std
::
vector
<
std
::
string
>::
iterator
i
=
enabledLanguages
.
begin
();
i
!=
enabledLanguages
.
end
();
++
i
)
{
std
::
string
const
&
lang
=
*
i
;
if
(
lang
==
"NONE"
)
{
continue
;
}
this
->
Compilers
[
"CMAKE_"
+
lang
+
"_COMPILER"
]
=
lang
;
this
->
VariableMappings
[
"CMAKE_"
+
lang
+
"_COMPILER"
]
=
this
->
Makefile
->
GetSafeDefinition
(
"CMAKE_"
+
lang
+
"_COMPILER"
);
std
::
string
const
&
compilerArg1
=
"CMAKE_"
+
lang
+
"_COMPILER_ARG1"
;
std
::
string
const
&
compilerTarget
=
"CMAKE_"
+
lang
+
"_COMPILER_TARGET"
;
std
::
string
const
&
compilerOptionTarget
=
"CMAKE_"
+
lang
+
"_COMPILE_OPTIONS_TARGET"
;
std
::
string
const
&
compilerExternalToolchain
=
"CMAKE_"
+
lang
+
"_COMPILER_EXTERNAL_TOOLCHAIN"
;
std
::
string
const
&
compilerOptionExternalToolchain
=
"CMAKE_"
+
lang
+
"_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN"
;
std
::
string
const
&
compilerOptionSysroot
=
"CMAKE_"
+
lang
+
"_COMPILE_OPTIONS_SYSROOT"
;
this
->
VariableMappings
[
compilerArg1
]
=
this
->
Makefile
->
GetSafeDefinition
(
compilerArg1
);
this
->
VariableMappings
[
compilerTarget
]
=
this
->
Makefile
->
GetSafeDefinition
(
compilerTarget
);
this
->
VariableMappings
[
compilerOptionTarget
]
=
this
->
Makefile
->
GetSafeDefinition
(
compilerOptionTarget
);
this
->
VariableMappings
[
compilerExternalToolchain
]
=
this
->
Makefile
->
GetSafeDefinition
(
compilerExternalToolchain
);
this
->
VariableMappings
[
compilerOptionExternalToolchain
]
=
this
->
Makefile
->
GetSafeDefinition
(
compilerOptionExternalToolchain
);
this
->
VariableMappings
[
compilerOptionSysroot
]
=
this
->
Makefile
->
GetSafeDefinition
(
compilerOptionSysroot
);
for
(
const
char
*
const
*
replaceIter
=
cmArrayBegin
(
ruleReplaceVars
);
replaceIter
!=
cmArrayEnd
(
ruleReplaceVars
);
++
replaceIter
)
{
std
::
string
actualReplace
=
*
replaceIter
;
if
(
actualReplace
.
find
(
"${LANG}"
)
!=
actualReplace
.
npos
)
{
cmSystemTools
::
ReplaceString
(
actualReplace
,
"${LANG}"
,
lang
);
}
this
->
VariableMappings
[
actualReplace
]
=
this
->
Makefile
->
GetSafeDefinition
(
actualReplace
);
}
}
}
cmLocalGenerator
::~
cmLocalGenerator
()
...
...
@@ -486,28 +560,6 @@ cmState::Snapshot cmLocalGenerator::GetStateSnapshot() const
return
this
->
Makefile
->
GetStateSnapshot
();
}
// List of variables that are replaced when
// rules are expanced. These variables are
// replaced in the form <var> with GetSafeDefinition(var).
// ${LANG} is replaced in the variable first with all enabled
// languages.
static
const
char
*
ruleReplaceVars
[]
=
{
"CMAKE_${LANG}_COMPILER"
,
"CMAKE_SHARED_LIBRARY_CREATE_${LANG}_FLAGS"
,
"CMAKE_SHARED_MODULE_CREATE_${LANG}_FLAGS"
,
"CMAKE_SHARED_MODULE_${LANG}_FLAGS"
,
"CMAKE_SHARED_LIBRARY_${LANG}_FLAGS"
,
"CMAKE_${LANG}_LINK_FLAGS"
,
"CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG"
,
"CMAKE_${LANG}_ARCHIVE"
,
"CMAKE_AR"
,
"CMAKE_CURRENT_SOURCE_DIR"
,
"CMAKE_CURRENT_BINARY_DIR"
,
"CMAKE_RANLIB"
,
"CMAKE_LINKER"
,
"CMAKE_CL_SHOWINCLUDES_PREFIX"
};
std
::
string
cmLocalGenerator
::
ExpandRuleVariable
(
std
::
string
const
&
variable
,
const
RuleVariables
&
replaceValues
)
{
...
...
@@ -689,84 +741,29 @@ std::string cmLocalGenerator::ExpandRuleVariable(
cmSystemTools
::
CollapseFullPath
(
cmSystemTools
::
GetCMakeCommand
()),
SHELL
);
}
std
::
vector
<
std
::
string
>
enabledLanguages
=
this
->
GetState
()
->
GetEnabledLanguages
();
std
::
map
<
std
::
string
,
std
::
string
>
compilers
;
std
::
map
<
std
::
string
,
std
::
string
>
variableMappings
;
std
::
string
compilerSysroot
=
this
->
Makefile
->
GetSafeDefinition
(
"CMAKE_SYSROOT"
);
for
(
std
::
vector
<
std
::
string
>::
iterator
i
=
enabledLanguages
.
begin
();
i
!=
enabledLanguages
.
end
();
++
i
)
{
std
::
string
const
&
lang
=
*
i
;
if
(
lang
==
"NONE"
)
{
continue
;
}
compilers
[
"CMAKE_"
+
lang
+
"_COMPILER"
]
=
lang
;
variableMappings
[
"CMAKE_"
+
lang
+
"_COMPILER"
]
=
this
->
Makefile
->
GetSafeDefinition
(
"CMAKE_"
+
lang
+
"_COMPILER"
);
std
::
string
const
&
compilerArg1
=
"CMAKE_"
+
lang
+
"_COMPILER_ARG1"
;
std
::
string
const
&
compilerTarget
=
"CMAKE_"
+
lang
+
"_COMPILER_TARGET"
;
std
::
string
const
&
compilerOptionTarget
=
"CMAKE_"
+
lang
+
"_COMPILE_OPTIONS_TARGET"
;
std
::
string
const
&
compilerExternalToolchain
=
"CMAKE_"
+
lang
+
"_COMPILER_EXTERNAL_TOOLCHAIN"
;
std
::
string
const
&
compilerOptionExternalToolchain
=
"CMAKE_"
+
lang
+
"_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN"
;
std
::
string
const
&
compilerOptionSysroot
=
"CMAKE_"
+
lang
+
"_COMPILE_OPTIONS_SYSROOT"
;
variableMappings
[
compilerArg1
]
=
this
->
Makefile
->
GetSafeDefinition
(
compilerArg1
);
variableMappings
[
compilerTarget
]
=
this
->
Makefile
->
GetSafeDefinition
(
compilerTarget
);
variableMappings
[
compilerOptionTarget
]
=
this
->
Makefile
->
GetSafeDefinition
(
compilerOptionTarget
);
variableMappings
[
compilerExternalToolchain
]
=
this
->
Makefile
->
GetSafeDefinition
(
compilerExternalToolchain
);
variableMappings
[
compilerOptionExternalToolchain
]
=
this
->
Makefile
->
GetSafeDefinition
(
compilerOptionExternalToolchain
);
variableMappings
[
compilerOptionSysroot
]
=
this
->
Makefile
->
GetSafeDefinition
(
compilerOptionSysroot
);
for
(
const
char
*
const
*
replaceIter
=
cmArrayBegin
(
ruleReplaceVars
);
replaceIter
!=
cmArrayEnd
(
ruleReplaceVars
);
++
replaceIter
)
{
std
::
string
const
&
lang
=
*
i
;
std
::
string
actualReplace
=
*
replaceIter
;
if
(
actualReplace
.
find
(
"${LANG}"
)
!=
actualReplace
.
npos
)
{
cmSystemTools
::
ReplaceString
(
actualReplace
,
"${LANG}"
,
lang
);
}
variableMappings
[
actualReplace
]
=
this
->
Makefile
->
GetSafeDefinition
(
actualReplace
);
}
}
std
::
map
<
std
::
string
,
std
::
string
>::
iterator
compIt
=
c
ompilers
.
find
(
variable
);
this
->
C
ompilers
.
find
(
variable
);
if
(
compIt
!=
c
ompilers
.
end
())
{
if
(
compIt
!=
this
->
C
ompilers
.
end
())
{
std
::
string
ret
=
this
->
ConvertToOutputForExisting
(
v
ariableMappings
[
"CMAKE_"
+
compIt
->
second
+
"_COMPILER"
]);
this
->
V
ariableMappings
[
"CMAKE_"
+
compIt
->
second
+
"_COMPILER"
]);
std
::
string
const
&
compilerArg1
=
v
ariableMappings
[
compIt
->
first
+
"_COMPILER_ARG1"
];
this
->
V
ariableMappings
[
compIt
->
first
+
"_COMPILER_ARG1"
];
std
::
string
const
&
compilerTarget
=
v
ariableMappings
[
"CMAKE_"
+
compIt
->
second
+
"_COMPILER_TARGET"
];
this
->
V
ariableMappings
[
"CMAKE_"
+
compIt
->
second
+
"_COMPILER_TARGET"
];
std
::
string
const
&
compilerOptionTarget
=
variableMappings
[
"CMAKE_"
+
compIt
->
second
+
"_COMPILE_OPTIONS_TARGET"
];
this
->
VariableMappings
[
"CMAKE_"
+
compIt
->
second
+
"_COMPILE_OPTIONS_TARGET"
];
std
::
string
const
&
compilerExternalToolchain
=
v
ariableMappings
[
"CMAKE_"
+
compIt
->
second
+
"_COMPILER_EXTERNAL_TOOLCHAIN"
];
this
->
V
ariableMappings
[
"CMAKE_"
+
compIt
->
second
+
"_COMPILER_EXTERNAL_TOOLCHAIN"
];
std
::
string
const
&
compilerOptionExternalToolchain
=
v
ariableMappings
[
"CMAKE_"
+
compIt
->
second
+
"_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN"
];
this
->
V
ariableMappings
[
"CMAKE_"
+
compIt
->
second
+
"_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN"
];
std
::
string
const
&
compilerOptionSysroot
=
variableMappings
[
"CMAKE_"
+
compIt
->
second
+
"_COMPILE_OPTIONS_SYSROOT"
];
this
->
VariableMappings
[
"CMAKE_"
+
compIt
->
second
+
"_COMPILE_OPTIONS_SYSROOT"
];
// if there is a required first argument to the compiler add it
// to the compiler string
...
...
@@ -785,17 +782,17 @@ std::string cmLocalGenerator::ExpandRuleVariable(
ret
+=
compilerOptionExternalToolchain
;
ret
+=
this
->
EscapeForShell
(
compilerExternalToolchain
,
true
);
}
if
(
!
c
ompilerSysroot
.
empty
()
&&
!
compilerOptionSysroot
.
empty
())
{
if
(
!
this
->
C
ompilerSysroot
.
empty
()
&&
!
compilerOptionSysroot
.
empty
())
{
ret
+=
" "
;
ret
+=
compilerOptionSysroot
;
ret
+=
this
->
EscapeForShell
(
c
ompilerSysroot
,
true
);
ret
+=
this
->
EscapeForShell
(
this
->
C
ompilerSysroot
,
true
);
}
return
ret
;
}
std
::
map
<
std
::
string
,
std
::
string
>::
iterator
mapIt
=
v
ariableMappings
.
find
(
variable
);
if
(
mapIt
!=
v
ariableMappings
.
end
())
{
this
->
V
ariableMappings
.
find
(
variable
);
if
(
mapIt
!=
this
->
V
ariableMappings
.
end
())
{
if
(
variable
.
find
(
"_FLAG"
)
==
variable
.
npos
)
{
return
this
->
ConvertToOutputForExisting
(
mapIt
->
second
);
}
...
...
Source/cmLocalGenerator.h
View file @
2628dec1
...
...
@@ -390,6 +390,10 @@ protected:
std
::
vector
<
cmGeneratorTarget
*>
OwnedImportedGeneratorTargets
;
std
::
map
<
std
::
string
,
std
::
string
>
AliasTargets
;
std
::
map
<
std
::
string
,
std
::
string
>
Compilers
;
std
::
map
<
std
::
string
,
std
::
string
>
VariableMappings
;
std
::
string
CompilerSysroot
;
bool
EmitUniversalBinaryFlags
;
// Hack for ExpandRuleVariable until object-oriented version is
...
...
Brad King
@brad.king
Mentioned in commit
9a2048f1
·
Oct 17, 2016
Mentioned in commit
9a2048f1
Mentioned in commit 9a2048f1ea6687530e209992c3f5eafcbc02b2a9
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment