From 702121c5f3eceeb6b74ede845f1e1297cf113c47 Mon Sep 17 00:00:00 2001 From: Fred Baksik Date: Sat, 5 Jan 2019 11:01:22 -0500 Subject: 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_ not used when -kernel is present Fixes issue where CMAKE_C_FLAGS_ 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= is used or if it is added as part of a link flag The variables CMAKE__GHS_KERNEL_FLAGS_ are removed NOTE: By default this only added the flag -ldebug which links in the debugger library. -- Separate compiler options by newlines --- Help/manual/cmake-variables.7.rst | 5 -- .../CMAKE_LANG_GHS_KERNEL_FLAGS_CONFIG.rst | 5 -- .../variable/CMAKE_LANG_GHS_KERNEL_FLAGS_DEBUG.rst | 5 -- .../CMAKE_LANG_GHS_KERNEL_FLAGS_MINSIZEREL.rst | 5 -- .../CMAKE_LANG_GHS_KERNEL_FLAGS_RELEASE.rst | 5 -- .../CMAKE_LANG_GHS_KERNEL_FLAGS_RELWITHDEBINFO.rst | 5 -- Modules/Compiler/GHS-C.cmake | 20 ------- Modules/Compiler/GHS-CXX.cmake | 24 --------- Source/cmGhsMultiTargetGenerator.cxx | 61 +++++++--------------- Source/cmGhsMultiTargetGenerator.h | 10 ++-- 10 files changed, 25 insertions(+), 120 deletions(-) delete mode 100644 Help/variable/CMAKE_LANG_GHS_KERNEL_FLAGS_CONFIG.rst delete mode 100644 Help/variable/CMAKE_LANG_GHS_KERNEL_FLAGS_DEBUG.rst delete mode 100644 Help/variable/CMAKE_LANG_GHS_KERNEL_FLAGS_MINSIZEREL.rst delete mode 100644 Help/variable/CMAKE_LANG_GHS_KERNEL_FLAGS_RELEASE.rst delete mode 100644 Help/variable/CMAKE_LANG_GHS_KERNEL_FLAGS_RELWITHDEBINFO.rst diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index e464b0c..122be3a 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -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 diff --git a/Help/variable/CMAKE_LANG_GHS_KERNEL_FLAGS_CONFIG.rst b/Help/variable/CMAKE_LANG_GHS_KERNEL_FLAGS_CONFIG.rst deleted file mode 100644 index 8ed1c02..0000000 --- a/Help/variable/CMAKE_LANG_GHS_KERNEL_FLAGS_CONFIG.rst +++ /dev/null @@ -1,5 +0,0 @@ -CMAKE__GHS_KERNEL_FLAGS_ --------------------------------------- - -GHS kernel flags for language ```` when building for the ```` -configuration. diff --git a/Help/variable/CMAKE_LANG_GHS_KERNEL_FLAGS_DEBUG.rst b/Help/variable/CMAKE_LANG_GHS_KERNEL_FLAGS_DEBUG.rst deleted file mode 100644 index 4fea67a..0000000 --- a/Help/variable/CMAKE_LANG_GHS_KERNEL_FLAGS_DEBUG.rst +++ /dev/null @@ -1,5 +0,0 @@ -CMAKE__GHS_KERNEL_FLAGS_DEBUG ------------------------------------ - -This variable is the ``Debug`` variant of the -:variable:`CMAKE__GHS_KERNEL_FLAGS_` variable. diff --git a/Help/variable/CMAKE_LANG_GHS_KERNEL_FLAGS_MINSIZEREL.rst b/Help/variable/CMAKE_LANG_GHS_KERNEL_FLAGS_MINSIZEREL.rst deleted file mode 100644 index 31f87f2..0000000 --- a/Help/variable/CMAKE_LANG_GHS_KERNEL_FLAGS_MINSIZEREL.rst +++ /dev/null @@ -1,5 +0,0 @@ -CMAKE__GHS_KERNEL_FLAGS_MINSIZEREL ----------------------------------------- - -This variable is the ``MinSizeRel`` variant of the -:variable:`CMAKE__GHS_KERNEL_FLAGS_` variable. diff --git a/Help/variable/CMAKE_LANG_GHS_KERNEL_FLAGS_RELEASE.rst b/Help/variable/CMAKE_LANG_GHS_KERNEL_FLAGS_RELEASE.rst deleted file mode 100644 index 1acd198..0000000 --- a/Help/variable/CMAKE_LANG_GHS_KERNEL_FLAGS_RELEASE.rst +++ /dev/null @@ -1,5 +0,0 @@ -CMAKE__GHS_KERNEL_FLAGS_RELEASE -------------------------------------- - -This variable is the ``Release`` variant of the -:variable:`CMAKE__GHS_KERNEL_FLAGS_` variable. diff --git a/Help/variable/CMAKE_LANG_GHS_KERNEL_FLAGS_RELWITHDEBINFO.rst b/Help/variable/CMAKE_LANG_GHS_KERNEL_FLAGS_RELWITHDEBINFO.rst deleted file mode 100644 index ac1b6bc..0000000 --- a/Help/variable/CMAKE_LANG_GHS_KERNEL_FLAGS_RELWITHDEBINFO.rst +++ /dev/null @@ -1,5 +0,0 @@ -CMAKE__GHS_KERNEL_FLAGS_RELWITHDEBINFO --------------------------------------------- - -This variable is the ``RelWithDebInfo`` variant of the -:variable:`CMAKE__GHS_KERNEL_FLAGS_` variable. diff --git a/Modules/Compiler/GHS-C.cmake b/Modules/Compiler/GHS-C.cmake index c30bdec..a825b0b 100644 --- a/Modules/Compiler/GHS-C.cmake +++ b/Modules/Compiler/GHS-C.cmake @@ -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() diff --git a/Modules/Compiler/GHS-CXX.cmake b/Modules/Compiler/GHS-CXX.cmake index b3018a7..07b5044 100644 --- a/Modules/Compiler/GHS-CXX.cmake +++ b/Modules/Compiler/GHS-CXX.cmake @@ -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() diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index 305e494..0cd6312 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -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 cmGhsMultiTargetGenerator::GetSources() const { std::vector 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::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 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 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) { diff --git a/Source/cmGhsMultiTargetGenerator.h b/Source/cmGhsMultiTargetGenerator.h index 358e1f4..343044a 100644 --- a/Source/cmGhsMultiTargetGenerator.h +++ b/Source/cmGhsMultiTargetGenerator.h @@ -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); -- cgit v0.12