mirror of
https://github.com/Kitware/CMake.git
synced 2026-06-30 19:57:41 +00:00
GHS: Use the correct compiler flags for CMAKE_BUILD_TYPE
-- Do not use CMAKE_C_FLAGS_RELEASE flags when CMAKE_BUILD_TYPE is empty if CMAKE_BUILD_TYPE was not set the generator would use Release settings this does not match the documented behavior of CMAKE_BUILD_TYPE -- CMAKE_C_FLAGS_<CONFIG> not used when -kernel is present Fixes issue where CMAKE_C_FLAGS_<CONFIG> is ignored when -kernel option is present as a compiler option When the -kernel option is added to an executable it uses a different set of language flags This does not occur -kernel=<type> is used or if it is added as part of a link flag The variables CMAKE_<LANG>_GHS_KERNEL_FLAGS_<CONFIG> are removed NOTE: By default this only added the flag -ldebug which links in the debugger library. -- Separate compiler options by newlines
This commit is contained in:
@@ -482,11 +482,6 @@ Variables for Languages
|
||||
/variable/CMAKE_LANG_FLAGS_RELEASE_INIT
|
||||
/variable/CMAKE_LANG_FLAGS_RELWITHDEBINFO
|
||||
/variable/CMAKE_LANG_FLAGS_RELWITHDEBINFO_INIT
|
||||
/variable/CMAKE_LANG_GHS_KERNEL_FLAGS_CONFIG
|
||||
/variable/CMAKE_LANG_GHS_KERNEL_FLAGS_DEBUG
|
||||
/variable/CMAKE_LANG_GHS_KERNEL_FLAGS_MINSIZEREL
|
||||
/variable/CMAKE_LANG_GHS_KERNEL_FLAGS_RELEASE
|
||||
/variable/CMAKE_LANG_GHS_KERNEL_FLAGS_RELWITHDEBINFO
|
||||
/variable/CMAKE_LANG_IGNORE_EXTENSIONS
|
||||
/variable/CMAKE_LANG_IMPLICIT_INCLUDE_DIRECTORIES
|
||||
/variable/CMAKE_LANG_IMPLICIT_LINK_DIRECTORIES
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
CMAKE_<LANG>_GHS_KERNEL_FLAGS_<CONFIG>
|
||||
--------------------------------------
|
||||
|
||||
GHS kernel flags for language ``<LANG>`` when building for the ``<CONFIG>``
|
||||
configuration.
|
||||
@@ -1,5 +0,0 @@
|
||||
CMAKE_<LANG>_GHS_KERNEL_FLAGS_DEBUG
|
||||
-----------------------------------
|
||||
|
||||
This variable is the ``Debug`` variant of the
|
||||
:variable:`CMAKE_<LANG>_GHS_KERNEL_FLAGS_<CONFIG>` variable.
|
||||
@@ -1,5 +0,0 @@
|
||||
CMAKE_<LANG>_GHS_KERNEL_FLAGS_MINSIZEREL
|
||||
----------------------------------------
|
||||
|
||||
This variable is the ``MinSizeRel`` variant of the
|
||||
:variable:`CMAKE_<LANG>_GHS_KERNEL_FLAGS_<CONFIG>` variable.
|
||||
@@ -1,5 +0,0 @@
|
||||
CMAKE_<LANG>_GHS_KERNEL_FLAGS_RELEASE
|
||||
-------------------------------------
|
||||
|
||||
This variable is the ``Release`` variant of the
|
||||
:variable:`CMAKE_<LANG>_GHS_KERNEL_FLAGS_<CONFIG>` variable.
|
||||
@@ -1,5 +0,0 @@
|
||||
CMAKE_<LANG>_GHS_KERNEL_FLAGS_RELWITHDEBINFO
|
||||
--------------------------------------------
|
||||
|
||||
This variable is the ``RelWithDebInfo`` variant of the
|
||||
:variable:`CMAKE_<LANG>_GHS_KERNEL_FLAGS_<CONFIG>` variable.
|
||||
@@ -8,23 +8,3 @@ string(APPEND CMAKE_C_FLAGS_DEBUG_INIT " -Odebug -g")
|
||||
string(APPEND CMAKE_C_FLAGS_MINSIZEREL_INIT " -Ospace")
|
||||
string(APPEND CMAKE_C_FLAGS_RELEASE_INIT " -O")
|
||||
string(APPEND CMAKE_C_FLAGS_RELWITHDEBINFO_INIT " -O -g")
|
||||
|
||||
set(CMAKE_C_GHS_KERNEL_FLAGS_DEBUG_INIT "-ldebug ${CMAKE_C_FLAGS_DEBUG_INIT}")
|
||||
set(CMAKE_C_GHS_KERNEL_FLAGS_MINSIZEREL_INIT "${CMAKE_C_FLAGS_MINSIZEREL_INIT}")
|
||||
set(CMAKE_C_GHS_KERNEL_FLAGS_RELEASE_INIT "${CMAKE_C_FLAGS_RELEASE_INIT}")
|
||||
set(CMAKE_C_GHS_KERNEL_FLAGS_RELWITHDEBINFO_INIT
|
||||
"-ldebug ${CMAKE_C_FLAGS_RELWITHDEBINFO_INIT}")
|
||||
|
||||
if(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
|
||||
set (CMAKE_C_GHS_KERNEL_FLAGS_DEBUG "${CMAKE_C_GHS_KERNEL_FLAGS_DEBUG_INIT}"
|
||||
CACHE STRING "Kernel flags used by the compiler during debug builds.")
|
||||
set (CMAKE_C_GHS_KERNEL_FLAGS_MINSIZEREL
|
||||
"${CMAKE_C_GHS_KERNEL_FLAGS_MINSIZEREL_INIT}" CACHE STRING
|
||||
"Kernel flags used by the compiler during release builds for minimum size.")
|
||||
set (CMAKE_C_GHS_KERNEL_FLAGS_RELEASE
|
||||
"${CMAKE_C_GHS_KERNEL_FLAGS_RELEASE_INIT}"
|
||||
CACHE STRING "Kernel flags used by the compiler during release builds.")
|
||||
set (CMAKE_C_GHS_KERNEL_FLAGS_RELWITHDEBINFO
|
||||
"${CMAKE_C_GHS_KERNEL_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
|
||||
"Kernel flags used by the compiler during release builds with debug info.")
|
||||
endif()
|
||||
|
||||
@@ -8,27 +8,3 @@ string(APPEND CMAKE_CXX_FLAGS_DEBUG_INIT " -Odebug -g")
|
||||
string(APPEND CMAKE_CXX_FLAGS_MINSIZEREL_INIT " -Ospace")
|
||||
string(APPEND CMAKE_CXX_FLAGS_RELEASE_INIT " -O")
|
||||
string(APPEND CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT " -O -g")
|
||||
|
||||
set(CMAKE_CXX_GHS_KERNEL_FLAGS_DEBUG_INIT
|
||||
"-ldebug ${CMAKE_CXX_FLAGS_DEBUG_INIT}")
|
||||
set(CMAKE_CXX_GHS_KERNEL_FLAGS_MINSIZEREL_INIT
|
||||
"${CMAKE_CXX_FLAGS_MINSIZEREL_INIT}")
|
||||
set(CMAKE_CXX_GHS_KERNEL_FLAGS_RELEASE_INIT
|
||||
"${CMAKE_CXX_FLAGS_RELEASE_INIT}")
|
||||
set(CMAKE_CXX_GHS_KERNEL_FLAGS_RELWITHDEBINFO_INIT
|
||||
"-ldebug ${CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT}")
|
||||
|
||||
if(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
|
||||
set (CMAKE_CXX_GHS_KERNEL_FLAGS_DEBUG
|
||||
"${CMAKE_CXX_GHS_KERNEL_FLAGS_DEBUG_INIT}"
|
||||
CACHE STRING "Kernel flags used by the compiler during debug builds.")
|
||||
set (CMAKE_CXX_GHS_KERNEL_FLAGS_MINSIZEREL
|
||||
"${CMAKE_CXX_GHS_KERNEL_FLAGS_MINSIZEREL_INIT}" CACHE STRING
|
||||
"Kernel flags used by the compiler during release builds for minimum size.")
|
||||
set (CMAKE_CXX_GHS_KERNEL_FLAGS_RELEASE
|
||||
"${CMAKE_CXX_GHS_KERNEL_FLAGS_RELEASE_INIT}"
|
||||
CACHE STRING "Kernel flags used by the compiler during release builds.")
|
||||
set (CMAKE_CXX_GHS_KERNEL_FLAGS_RELWITHDEBINFO
|
||||
"${CMAKE_CXX_GHS_KERNEL_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
|
||||
"Kernel flags used by the compiler during release builds with debug info.")
|
||||
endif()
|
||||
|
||||
@@ -121,25 +121,19 @@ void cmGhsMultiTargetGenerator::GenerateTarget()
|
||||
|
||||
this->GetGlobalGenerator()->WriteFileHeader(fout);
|
||||
GhsMultiGpj::WriteGpjTag(this->TagType, fout);
|
||||
|
||||
std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
|
||||
if (0 == config.length()) {
|
||||
config = "RELEASE";
|
||||
}
|
||||
const std::string language(
|
||||
this->GeneratorTarget->GetLinkerLanguage(config));
|
||||
config = cmSystemTools::UpperCase(config);
|
||||
this->DynamicDownload = this->DetermineIfDynamicDownload(config, language);
|
||||
this->GeneratorTarget->GetLinkerLanguage(this->ConfigName));
|
||||
this->DynamicDownload =
|
||||
this->DetermineIfDynamicDownload(this->ConfigName, language);
|
||||
if (this->DynamicDownload) {
|
||||
fout << "#component integrity_dynamic_download" << std::endl;
|
||||
}
|
||||
bool const notKernel = this->IsNotKernel(config, language);
|
||||
this->WriteTargetSpecifics(fout, config, notKernel);
|
||||
this->SetCompilerFlags(config, language, notKernel);
|
||||
this->WriteCompilerFlags(fout, config, language);
|
||||
this->WriteCompilerDefinitions(fout, config, language);
|
||||
this->WriteIncludes(fout, config, language);
|
||||
this->WriteTargetLinkLine(fout, config);
|
||||
this->WriteTargetSpecifics(fout, this->ConfigName);
|
||||
this->SetCompilerFlags(this->ConfigName, language);
|
||||
this->WriteCompilerFlags(fout, this->ConfigName, language);
|
||||
this->WriteCompilerDefinitions(fout, this->ConfigName, language);
|
||||
this->WriteIncludes(fout, this->ConfigName, language);
|
||||
this->WriteTargetLinkLine(fout, this->ConfigName);
|
||||
this->WriteCustomCommands(fout);
|
||||
this->WriteSources(fout);
|
||||
|
||||
@@ -162,8 +156,7 @@ bool cmGhsMultiTargetGenerator::IncludeThisTarget()
|
||||
std::vector<cmSourceFile*> cmGhsMultiTargetGenerator::GetSources() const
|
||||
{
|
||||
std::vector<cmSourceFile*> output;
|
||||
std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE");
|
||||
this->GeneratorTarget->GetSourceFiles(output, config);
|
||||
this->GeneratorTarget->GetSourceFiles(output, this->ConfigName);
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -175,8 +168,7 @@ cmGlobalGhsMultiGenerator* cmGhsMultiTargetGenerator::GetGlobalGenerator()
|
||||
}
|
||||
|
||||
void cmGhsMultiTargetGenerator::WriteTargetSpecifics(std::ostream& fout,
|
||||
const std::string& config,
|
||||
bool const notKernel)
|
||||
const std::string& config)
|
||||
{
|
||||
std::string outpath;
|
||||
std::string rootpath = this->LocalGenerator->GetCurrentBinaryDirectory();
|
||||
@@ -193,8 +185,7 @@ void cmGhsMultiTargetGenerator::WriteTargetSpecifics(std::ostream& fout,
|
||||
}
|
||||
|
||||
void cmGhsMultiTargetGenerator::SetCompilerFlags(std::string const& config,
|
||||
const std::string& language,
|
||||
bool const notKernel)
|
||||
const std::string& language)
|
||||
{
|
||||
std::map<std::string, std::string>::iterator i =
|
||||
this->FlagsByLanguage.find(language);
|
||||
@@ -202,14 +193,9 @@ void cmGhsMultiTargetGenerator::SetCompilerFlags(std::string const& config,
|
||||
std::string flags;
|
||||
const char* lang = language.c_str();
|
||||
|
||||
if (notKernel) {
|
||||
this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget,
|
||||
lang, config);
|
||||
} else {
|
||||
this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget,
|
||||
lang + std::string("_GHS_KERNEL"),
|
||||
config);
|
||||
}
|
||||
this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget, lang,
|
||||
config);
|
||||
|
||||
this->LocalGenerator->AddCMP0018Flags(flags, this->GeneratorTarget, lang,
|
||||
config);
|
||||
this->LocalGenerator->AddVisibilityPresetFlags(
|
||||
@@ -260,7 +246,11 @@ void cmGhsMultiTargetGenerator::WriteCompilerFlags(std::ostream& fout,
|
||||
this->FlagsByLanguage.find(language);
|
||||
if (flagsByLangI != this->FlagsByLanguage.end()) {
|
||||
if (!flagsByLangI->second.empty()) {
|
||||
fout << " " << flagsByLangI->second << std::endl;
|
||||
std::vector<std::string> ghsCompFlags =
|
||||
cmSystemTools::ParseArguments(flagsByLangI->second.c_str());
|
||||
for (auto& f : ghsCompFlags) {
|
||||
fout << " " << f << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -618,17 +608,6 @@ std::string cmGhsMultiTargetGenerator::ComputeLongestObjectDirectory(
|
||||
return dir_max;
|
||||
}
|
||||
|
||||
bool cmGhsMultiTargetGenerator::IsNotKernel(std::string const& config,
|
||||
const std::string& language)
|
||||
{
|
||||
bool output;
|
||||
std::vector<std::string> options;
|
||||
this->GeneratorTarget->GetCompileOptions(options, config, language);
|
||||
output =
|
||||
options.end() == std::find(options.begin(), options.end(), "-kernel");
|
||||
return output;
|
||||
}
|
||||
|
||||
bool cmGhsMultiTargetGenerator::DetermineIfTargetGroup(
|
||||
const cmGeneratorTarget* target)
|
||||
{
|
||||
|
||||
@@ -34,15 +34,16 @@ private:
|
||||
|
||||
bool IsTargetGroup() const { return this->TargetGroup; }
|
||||
|
||||
void WriteTargetSpecifics(std::ostream& fout, const std::string& config,
|
||||
bool notKernel);
|
||||
void WriteTargetSpecifics(std::ostream& fout, const std::string& config);
|
||||
|
||||
void WriteCompilerFlags(std::ostream& fout, const std::string& config,
|
||||
const std::string& language);
|
||||
void WriteCompilerDefinitions(std::ostream& fout, const std::string& config,
|
||||
const std::string& language);
|
||||
|
||||
void SetCompilerFlags(std::string const& config, const std::string& language,
|
||||
bool const notKernel);
|
||||
void SetCompilerFlags(std::string const& config,
|
||||
const std::string& language);
|
||||
|
||||
std::string GetDefines(const std::string& langugae,
|
||||
std::string const& config);
|
||||
|
||||
@@ -65,7 +66,6 @@ private:
|
||||
cmLocalGhsMultiGenerator const* localGhsMultiGenerator,
|
||||
cmGeneratorTarget* generatorTarget, cmSourceFile* const sourceFile);
|
||||
|
||||
bool IsNotKernel(std::string const& config, const std::string& language);
|
||||
static bool DetermineIfTargetGroup(const cmGeneratorTarget* target);
|
||||
bool DetermineIfDynamicDownload(std::string const& config,
|
||||
const std::string& language);
|
||||
|
||||
Reference in New Issue
Block a user