This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "CMake".
The branch, master has been updated via c88cf48bbe775c45c36c23b990c89d85b7b9a220 (commit) via f30f1625c25afb44861eff1f69ca4fa966077c73 (commit) via 0672647e123670342d68827354610c747fe98004 (commit) via b2fd479df595394734ed1a830848cba2f57729f2 (commit) via 9d1a1bc495be41b035f61f9b707df8006da54160 (commit) via 587ccffe74638676090005ac6b7f799f15a0112c (commit) via 5a06efda05feda02511592c76134ee8ed3e8b650 (commit) via ea1bed34b2ba16f3971b90996dc345834f0d9699 (commit) via 91abf9f3c4a80f5a8417401d5277b3b66bc7d008 (commit) via f151a5770597dbe341fc6329a711f40e9195c773 (commit) from d608b2c6200afd9d732c30c862bda923139a8d08 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=c88cf48bbe775c45c36c23b990c89d85b7b9a220 commit c88cf48bbe775c45c36c23b990c89d85b7b9a220 Merge: f30f162 b2fd479 Author: Brad King <brad.k...@kitware.com> AuthorDate: Fri Sep 27 18:56:32 2019 +0000 Commit: Kitware Robot <kwro...@kitware.com> CommitDate: Fri Sep 27 14:56:53 2019 -0400 Merge topic 'FindBinUtils-ask-compiler' b2fd479df5 FindBinUtils: Use the compiler to get the path to compiler tools 587ccffe74 Tests: Add symbols to FortranModules static libraries Acked-by: Kitware Robot <kwro...@kitware.com> Acked-by: Alex Turbov <i.za...@gmail.com> Merge-request: !3854 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=f30f1625c25afb44861eff1f69ca4fa966077c73 commit f30f1625c25afb44861eff1f69ca4fa966077c73 Merge: 0672647 5a06efd Author: Brad King <brad.k...@kitware.com> AuthorDate: Fri Sep 27 18:54:39 2019 +0000 Commit: Kitware Robot <kwro...@kitware.com> CommitDate: Fri Sep 27 14:54:58 2019 -0400 Merge topic 'decompose-custom-command-creation' 5a06efda05 cmMakefile: Remove AddUtilityCommand overload without byproducts ea1bed34b2 cmMakefile: Extract utilities used for creation of custom commands 91abf9f3c4 cmCustomCommand: Move custom commands f151a57705 cmMakefile: Move enumerations into new header Acked-by: Kitware Robot <kwro...@kitware.com> Merge-request: !3846 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=0672647e123670342d68827354610c747fe98004 commit 0672647e123670342d68827354610c747fe98004 Merge: d608b2c 9d1a1bc Author: Brad King <brad.k...@kitware.com> AuthorDate: Fri Sep 27 18:51:46 2019 +0000 Commit: Kitware Robot <kwro...@kitware.com> CommitDate: Fri Sep 27 14:52:01 2019 -0400 Merge topic 'free-target-commands' 9d1a1bc495 cmTarget*: Port away from cmCommand Acked-by: Kitware Robot <kwro...@kitware.com> Merge-request: !3799 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b2fd479df595394734ed1a830848cba2f57729f2 commit b2fd479df595394734ed1a830848cba2f57729f2 Author: Isuru Fernando <isu...@gmail.com> AuthorDate: Sun Sep 22 12:50:44 2019 -0500 Commit: Isuru Fernando <isu...@gmail.com> CommitDate: Thu Sep 26 19:11:00 2019 -0500 FindBinUtils: Use the compiler to get the path to compiler tools Fixes: #19728 diff --git a/Modules/CMakeFindBinUtils.cmake b/Modules/CMakeFindBinUtils.cmake index 781b48c..3887b2d 100644 --- a/Modules/CMakeFindBinUtils.cmake +++ b/Modules/CMakeFindBinUtils.cmake @@ -57,6 +57,44 @@ endfunction() __resolve_tool_path(CMAKE_LINKER "${_CMAKE_TOOLCHAIN_LOCATION}" "Default Linker") __resolve_tool_path(CMAKE_MT "${_CMAKE_TOOLCHAIN_LOCATION}" "Default Manifest Tool") +function(__get_compiler_component CMAKE_TOOL NAME) + get_property(_CMAKE_TOOL_CACHED CACHE ${CMAKE_TOOL} PROPERTY TYPE) + # If CMAKE_TOOL is present in the CMake Cache, return + if(_CMAKE_TOOL_CACHED) + return() + endif() + + cmake_parse_arguments(_COMPILER_COMP_ARGS "" "DOC" "HINTS;NAMES" ${ARGN}) + + set(_LOCATION_FROM_COMPILER ) + set(_NAME_FROM_COMPILER ) + + if (NOT DEFINED ${CMAKE_TOOL}) + if("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xGNU" OR + "x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xClang") + execute_process( + COMMAND ${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER} -print-prog-name=${NAME} + RESULT_VARIABLE _CMAKE_TOOL_PROG_NAME_RESULT + OUTPUT_VARIABLE _CMAKE_TOOL_PROG_NAME_OUTPUT + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if (_CMAKE_TOOL_PROG_NAME_RESULT STREQUAL "0" AND IS_ABSOLUTE "${_CMAKE_TOOL_PROG_NAME_OUTPUT}") + get_filename_component(_LOCATION_FROM_COMPILER "${_CMAKE_TOOL_PROG_NAME_OUTPUT}" DIRECTORY) + get_filename_component(_NAME_FROM_COMPILER "${_CMAKE_TOOL_PROG_NAME_OUTPUT}" NAME) + endif() + endif() + endif() + + if (NOT _COMPILER_COMP_ARGS_DOC) + set(_COMPILER_COMP_ARGS_DOC "Path to ${NAME} program") + endif() + find_program(${CMAKE_TOOL} + NAMES ${_NAME_FROM_COMPILER} ${_COMPILER_COMP_ARGS_NAMES} + HINTS ${_LOCATION_FROM_COMPILER} ${_COMPILER_COMP_ARGS_HINTS} + DOC "${_COMPILER_COMP_ARGS_DOC}" + ) +endfunction() + set(_CMAKE_TOOL_VARS "") # if it's the MS C/CXX compiler, search for link @@ -101,22 +139,32 @@ else() set(_CMAKE_ADDITIONAL_ADDR2LINE_NAMES "llvm-addr2line") endif() - find_program(CMAKE_AR NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ar${_CMAKE_TOOLCHAIN_SUFFIX} ${_CMAKE_ADDITIONAL_AR_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) + __get_compiler_component(CMAKE_AR ar NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ar${_CMAKE_TOOLCHAIN_SUFFIX} ${_CMAKE_ADDITIONAL_AR_NAMES} + HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) - find_program(CMAKE_RANLIB NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ranlib ${_CMAKE_ADDITIONAL_RANLIB_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) + __get_compiler_component(CMAKE_RANLIB ranlib NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ranlib ${_CMAKE_ADDITIONAL_RANLIB_NAMES} + HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) if(NOT CMAKE_RANLIB) set(CMAKE_RANLIB : CACHE INTERNAL "noop for ranlib") endif() - find_program(CMAKE_STRIP NAMES ${_CMAKE_TOOLCHAIN_PREFIX}strip${_CMAKE_TOOLCHAIN_SUFFIX} ${_CMAKE_ADDITIONAL_STRIP_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) - find_program(CMAKE_LINKER NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ld ${_CMAKE_ADDITIONAL_LINKER_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) - find_program(CMAKE_NM NAMES ${_CMAKE_TOOLCHAIN_PREFIX}nm ${_CMAKE_ADDITIONAL_NM_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) - find_program(CMAKE_OBJDUMP NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objdump ${_CMAKE_ADDITIONAL_OBJDUMP_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) - find_program(CMAKE_OBJCOPY NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objcopy ${_CMAKE_ADDITIONAL_OBJCOPY_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) - find_program(CMAKE_READELF NAMES ${_CMAKE_TOOLCHAIN_PREFIX}readelf ${_CMAKE_ADDITIONAL_READELF_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) - find_program(CMAKE_DLLTOOL NAMES ${_CMAKE_TOOLCHAIN_PREFIX}dlltool ${_CMAKE_ADDITIONAL_DLLTOOL_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) - find_program(CMAKE_ADDR2LINE NAMES ${_CMAKE_TOOLCHAIN_PREFIX}addr2line ${_CMAKE_ADDITIONAL_ADDR2LINE_NAMES} HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) + __get_compiler_component(CMAKE_STRIP strip NAMES ${_CMAKE_TOOLCHAIN_PREFIX}strip${_CMAKE_TOOLCHAIN_SUFFIX} ${_CMAKE_ADDITIONAL_STRIP_NAMES} + HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) + __get_compiler_component(CMAKE_LINKER ld NAMES ${_CMAKE_TOOLCHAIN_PREFIX}ld ${_CMAKE_ADDITIONAL_LINKER_NAMES} + HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) + __get_compiler_component(CMAKE_NM nm NAMES ${_CMAKE_TOOLCHAIN_PREFIX}nm ${_CMAKE_ADDITIONAL_NM_NAMES} + HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) + __get_compiler_component(CMAKE_OBJDUMP objdump NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objdump ${_CMAKE_ADDITIONAL_OBJDUMP_NAMES} + HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) + __get_compiler_component(CMAKE_OBJCOPY objcopy NAMES ${_CMAKE_TOOLCHAIN_PREFIX}objcopy ${_CMAKE_ADDITIONAL_OBJCOPY_NAMES} + HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) + __get_compiler_component(CMAKE_READELF readelf NAMES ${_CMAKE_TOOLCHAIN_PREFIX}readelf ${_CMAKE_ADDITIONAL_READELF_NAMES} + HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) + __get_compiler_component(CMAKE_DLLTOOL dlltool NAMES ${_CMAKE_TOOLCHAIN_PREFIX}dlltool ${_CMAKE_ADDITIONAL_DLLTOOL_NAMES} + HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) + __get_compiler_component(CMAKE_ADDR2LINE addr2line NAMES ${_CMAKE_TOOLCHAIN_PREFIX}addr2line ${_CMAKE_ADDITIONAL_ADDR2LINE_NAMES} + HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) list(APPEND _CMAKE_TOOL_VARS AR RANLIB STRIP LINKER NM OBJDUMP OBJCOPY READELF DLLTOOL ADDR2LINE) @@ -134,7 +182,7 @@ else() endif() if(CMAKE_PLATFORM_HAS_INSTALLNAME) - find_program(CMAKE_INSTALL_NAME_TOOL NAMES ${_CMAKE_TOOLCHAIN_PREFIX}install_name_tool HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) + __get_compiler_component(CMAKE_INSTALL_NAME_TOOL install_name_tool NAMES ${_CMAKE_TOOLCHAIN_PREFIX}install_name_tool HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) if(NOT CMAKE_INSTALL_NAME_TOOL) message(FATAL_ERROR "Could not find install_name_tool, please check your installation.") diff --git a/Modules/Compiler/GNU-FindBinUtils.cmake b/Modules/Compiler/GNU-FindBinUtils.cmake index 097fbf3..a47b7ad 100644 --- a/Modules/Compiler/GNU-FindBinUtils.cmake +++ b/Modules/Compiler/GNU-FindBinUtils.cmake @@ -15,21 +15,27 @@ string(REGEX MATCH "^([0-9]+\\.[0-9]+)" __version_x_y get_filename_component(__gcc_hints "${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER}" DIRECTORY) # http://manpages.ubuntu.com/manpages/wily/en/man1/gcc-ar.1.html -find_program(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_AR NAMES - "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar-${__version_x_y}" - "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar-${__version_x}" - "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar${_CMAKE_COMPILER_SUFFIX}" - HINTS ${__gcc_hints} +__get_compiler_component( + CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_AR gcc-ar + HINTS + ${__gcc_hints} + NAMES + "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar-${__version_x_y}" + "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar-${__version_x}" + "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar" DOC "A wrapper around 'ar' adding the appropriate '--plugin' option for the GCC compiler" ) mark_as_advanced(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_AR) # http://manpages.ubuntu.com/manpages/wily/en/man1/gcc-ranlib.1.html -find_program(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_RANLIB NAMES - "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib-${__version_x_y}" - "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib-${__version_x}" - "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib${_CMAKE_COMPILER_SUFFIX}" - HINTS ${__gcc_hints} +__get_compiler_component( + CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_RANLIB gcc-ranlib + HINTS + ${__gcc_hints} + NAMES + "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib-${__version_x_y}" + "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib-${__version_x}" + "${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib" DOC "A wrapper around 'ranlib' adding the appropriate '--plugin' option for the GCC compiler" ) mark_as_advanced(CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_RANLIB) https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=9d1a1bc495be41b035f61f9b707df8006da54160 commit 9d1a1bc495be41b035f61f9b707df8006da54160 Author: Regina Pfeifer <reg...@mailbox.org> AuthorDate: Tue Sep 10 21:41:44 2019 +0200 Commit: Brad King <brad.k...@kitware.com> CommitDate: Thu Sep 26 13:27:55 2019 -0400 cmTarget*: Port away from cmCommand diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx index 88d17f1..b1f7db7 100644 --- a/Source/cmCommands.cxx +++ b/Source/cmCommands.cxx @@ -246,26 +246,22 @@ void GetProjectCommands(cmState* state) state->AddBuiltinCommand("set_tests_properties", cmSetTestsPropertiesCommand); state->AddBuiltinCommand("subdirs", cmSubdirCommand); - state->AddBuiltinCommand( - "target_compile_definitions", - cm::make_unique<cmTargetCompileDefinitionsCommand>()); + state->AddBuiltinCommand("target_compile_definitions", + cmTargetCompileDefinitionsCommand); state->AddBuiltinCommand("target_compile_features", - cm::make_unique<cmTargetCompileFeaturesCommand>()); + cmTargetCompileFeaturesCommand); state->AddBuiltinCommand("target_compile_options", - cm::make_unique<cmTargetCompileOptionsCommand>()); - state->AddBuiltinCommand( - "target_include_directories", - cm::make_unique<cmTargetIncludeDirectoriesCommand>()); + cmTargetCompileOptionsCommand); + state->AddBuiltinCommand("target_include_directories", + cmTargetIncludeDirectoriesCommand); state->AddBuiltinCommand("target_link_libraries", cmTargetLinkLibrariesCommand); - state->AddBuiltinCommand("target_sources", - cm::make_unique<cmTargetSourcesCommand>()); + state->AddBuiltinCommand("target_sources", cmTargetSourcesCommand); state->AddBuiltinCommand("try_compile", cm::make_unique<cmTryCompileCommand>()); state->AddBuiltinCommand("try_run", cm::make_unique<cmTryRunCommand>()); - state->AddBuiltinCommand( - "target_precompile_headers", - cm::make_unique<cmTargetPrecompileHeadersCommand>()); + state->AddBuiltinCommand("target_precompile_headers", + cmTargetPrecompileHeadersCommand); #if !defined(CMAKE_BOOTSTRAP) state->AddBuiltinCommand("add_compile_definitions", @@ -280,10 +276,9 @@ void GetProjectCommands(cmState* state) state->AddBuiltinCommand("install_programs", cmInstallProgramsCommand); state->AddBuiltinCommand("add_link_options", cmAddLinkOptionsCommand); state->AddBuiltinCommand("link_libraries", cmLinkLibrariesCommand); - state->AddBuiltinCommand("target_link_options", - cm::make_unique<cmTargetLinkOptionsCommand>()); + state->AddBuiltinCommand("target_link_options", cmTargetLinkOptionsCommand); state->AddBuiltinCommand("target_link_directories", - cm::make_unique<cmTargetLinkDirectoriesCommand>()); + cmTargetLinkDirectoriesCommand); state->AddBuiltinCommand("load_cache", cmLoadCacheCommand); state->AddBuiltinCommand("qt_wrap_cpp", cmQTWrapCPPCommand); state->AddBuiltinCommand("qt_wrap_ui", cmQTWrapUICommand); diff --git a/Source/cmTargetCompileDefinitionsCommand.cxx b/Source/cmTargetCompileDefinitionsCommand.cxx index 94e249f..edee167 100644 --- a/Source/cmTargetCompileDefinitionsCommand.cxx +++ b/Source/cmTargetCompileDefinitionsCommand.cxx @@ -6,43 +6,53 @@ #include "cmMessageType.h" #include "cmStringAlgorithms.h" #include "cmTarget.h" +#include "cmTargetPropCommandBase.h" -class cmExecutionStatus; +namespace { -bool cmTargetCompileDefinitionsCommand::InitialPass( - std::vector<std::string> const& args, cmExecutionStatus&) +class TargetCompileDefinitionsImpl : public cmTargetPropCommandBase { - return this->HandleArguments(args, "COMPILE_DEFINITIONS"); -} +public: + using cmTargetPropCommandBase::cmTargetPropCommandBase; -void cmTargetCompileDefinitionsCommand::HandleMissingTarget( - const std::string& name) -{ - this->Makefile->IssueMessage( - MessageType::FATAL_ERROR, - cmStrCat("Cannot specify compile definitions for target \"", name, - "\" which is not built by this project.")); -} +private: + void HandleMissingTarget(const std::string& name) override + { + this->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("Cannot specify compile definitions for target \"", name, + "\" which is not built by this project.")); + } -std::string cmTargetCompileDefinitionsCommand::Join( - const std::vector<std::string>& content) -{ - std::string defs; - std::string sep; - for (std::string const& it : content) { - if (cmHasLiteralPrefix(it, "-D")) { - defs += sep + it.substr(2); - } else { - defs += sep + it; + bool HandleDirectContent(cmTarget* tgt, + const std::vector<std::string>& content, + bool /*prepend*/, bool /*system*/) override + { + tgt->AppendProperty("COMPILE_DEFINITIONS", this->Join(content).c_str()); + return true; // Successfully handled. + } + + std::string Join(const std::vector<std::string>& content) override + { + std::string defs; + std::string sep; + for (std::string const& it : content) { + if (cmHasLiteralPrefix(it, "-D")) { + defs += sep + it.substr(2); + } else { + defs += sep + it; + } + sep = ";"; } - sep = ";"; + return defs; } - return defs; -} +}; + +} // namespace -bool cmTargetCompileDefinitionsCommand::HandleDirectContent( - cmTarget* tgt, const std::vector<std::string>& content, bool, bool) +bool cmTargetCompileDefinitionsCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { - tgt->AppendProperty("COMPILE_DEFINITIONS", this->Join(content).c_str()); - return true; // Successfully handled. + return TargetCompileDefinitionsImpl(status).HandleArguments( + args, "COMPILE_DEFINITIONS"); } diff --git a/Source/cmTargetCompileDefinitionsCommand.h b/Source/cmTargetCompileDefinitionsCommand.h index f85dc0a..05ff092 100644 --- a/Source/cmTargetCompileDefinitionsCommand.h +++ b/Source/cmTargetCompileDefinitionsCommand.h @@ -8,39 +8,9 @@ #include <string> #include <vector> -#include <cm/memory> - -#include "cmCommand.h" -#include "cmTargetPropCommandBase.h" - class cmExecutionStatus; -class cmTarget; - -class cmTargetCompileDefinitionsCommand : public cmTargetPropCommandBase -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmTargetCompileDefinitionsCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; - -private: - void HandleMissingTarget(const std::string& name) override; - bool HandleDirectContent(cmTarget* tgt, - const std::vector<std::string>& content, - bool prepend, bool system) override; - std::string Join(const std::vector<std::string>& content) override; -}; +bool cmTargetCompileDefinitionsCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmTargetCompileFeaturesCommand.cxx b/Source/cmTargetCompileFeaturesCommand.cxx index a22b94b..06be4f0 100644 --- a/Source/cmTargetCompileFeaturesCommand.cxx +++ b/Source/cmTargetCompileFeaturesCommand.cxx @@ -5,40 +5,51 @@ #include "cmMakefile.h" #include "cmMessageType.h" #include "cmStringAlgorithms.h" +#include "cmTargetPropCommandBase.h" -class cmExecutionStatus; class cmTarget; -bool cmTargetCompileFeaturesCommand::InitialPass( - std::vector<std::string> const& args, cmExecutionStatus&) -{ - return this->HandleArguments(args, "COMPILE_FEATURES", NO_FLAGS); -} +namespace { -void cmTargetCompileFeaturesCommand::HandleMissingTarget( - const std::string& name) +class TargetCompileFeaturesImpl : public cmTargetPropCommandBase { - this->Makefile->IssueMessage( - MessageType::FATAL_ERROR, - cmStrCat("Cannot specify compile features for target \"", name, - "\" which is not built by this project.")); -} +public: + using cmTargetPropCommandBase::cmTargetPropCommandBase; -std::string cmTargetCompileFeaturesCommand::Join( - const std::vector<std::string>& content) -{ - return cmJoin(content, ";"); -} +private: + void HandleMissingTarget(const std::string& name) override + { + this->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("Cannot specify compile features for target \"", name, + "\" which is not built by this project.")); + } -bool cmTargetCompileFeaturesCommand::HandleDirectContent( - cmTarget* tgt, const std::vector<std::string>& content, bool, bool) -{ - for (std::string const& it : content) { - std::string error; - if (!this->Makefile->AddRequiredTargetFeature(tgt, it, &error)) { - this->SetError(error); - return false; // Not (successfully) handled. + bool HandleDirectContent(cmTarget* tgt, + const std::vector<std::string>& content, + bool /*prepend*/, bool /*system*/) override + { + for (std::string const& it : content) { + std::string error; + if (!this->Makefile->AddRequiredTargetFeature(tgt, it, &error)) { + this->SetError(error); + return false; // Not (successfully) handled. + } } + return true; // Successfully handled. + } + + std::string Join(const std::vector<std::string>& content) override + { + return cmJoin(content, ";"); } - return true; // Successfully handled. +}; + +} // namespace + +bool cmTargetCompileFeaturesCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) +{ + return TargetCompileFeaturesImpl(status).HandleArguments(args, + "COMPILE_FEATURES"); } diff --git a/Source/cmTargetCompileFeaturesCommand.h b/Source/cmTargetCompileFeaturesCommand.h index 39597ca..db0c04b 100644 --- a/Source/cmTargetCompileFeaturesCommand.h +++ b/Source/cmTargetCompileFeaturesCommand.h @@ -8,31 +8,9 @@ #include <string> #include <vector> -#include <cm/memory> - -#include "cmCommand.h" -#include "cmTargetPropCommandBase.h" - class cmExecutionStatus; -class cmTarget; - -class cmTargetCompileFeaturesCommand : public cmTargetPropCommandBase -{ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmTargetCompileFeaturesCommand>(); - } - - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; - -private: - void HandleMissingTarget(const std::string& name) override; - bool HandleDirectContent(cmTarget* tgt, - const std::vector<std::string>& content, - bool prepend, bool system) override; - std::string Join(const std::vector<std::string>& content) override; -}; +bool cmTargetCompileFeaturesCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmTargetCompileOptionsCommand.cxx b/Source/cmTargetCompileOptionsCommand.cxx index ccc215a..e39b726 100644 --- a/Source/cmTargetCompileOptionsCommand.cxx +++ b/Source/cmTargetCompileOptionsCommand.cxx @@ -7,34 +7,44 @@ #include "cmMessageType.h" #include "cmStringAlgorithms.h" #include "cmTarget.h" +#include "cmTargetPropCommandBase.h" -class cmExecutionStatus; +namespace { -bool cmTargetCompileOptionsCommand::InitialPass( - std::vector<std::string> const& args, cmExecutionStatus&) +class TargetCompileOptionsImpl : public cmTargetPropCommandBase { - return this->HandleArguments(args, "COMPILE_OPTIONS", PROCESS_BEFORE); -} +public: + using cmTargetPropCommandBase::cmTargetPropCommandBase; -void cmTargetCompileOptionsCommand::HandleMissingTarget( - const std::string& name) -{ - this->Makefile->IssueMessage( - MessageType::FATAL_ERROR, - cmStrCat("Cannot specify compile options for target \"", name, - "\" which is not built by this project.")); -} +private: + void HandleMissingTarget(const std::string& name) override + { + this->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("Cannot specify compile options for target \"", name, + "\" which is not built by this project.")); + } -std::string cmTargetCompileOptionsCommand::Join( - const std::vector<std::string>& content) -{ - return cmJoin(content, ";"); -} + bool HandleDirectContent(cmTarget* tgt, + const std::vector<std::string>& content, + bool /*prepend*/, bool /*system*/) override + { + cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); + tgt->InsertCompileOption(this->Join(content), lfbt); + return true; // Successfully handled. + } + + std::string Join(const std::vector<std::string>& content) override + { + return cmJoin(content, ";"); + } +}; + +} // namespace -bool cmTargetCompileOptionsCommand::HandleDirectContent( - cmTarget* tgt, const std::vector<std::string>& content, bool, bool) +bool cmTargetCompileOptionsCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { - cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); - tgt->InsertCompileOption(this->Join(content), lfbt); - return true; // Successfully handled. + return TargetCompileOptionsImpl(status).HandleArguments( + args, "COMPILE_OPTIONS", TargetCompileOptionsImpl::PROCESS_BEFORE); } diff --git a/Source/cmTargetCompileOptionsCommand.h b/Source/cmTargetCompileOptionsCommand.h index b328ba2..3ab1a89 100644 --- a/Source/cmTargetCompileOptionsCommand.h +++ b/Source/cmTargetCompileOptionsCommand.h @@ -8,39 +8,9 @@ #include <string> #include <vector> -#include <cm/memory> - -#include "cmCommand.h" -#include "cmTargetPropCommandBase.h" - class cmExecutionStatus; -class cmTarget; - -class cmTargetCompileOptionsCommand : public cmTargetPropCommandBase -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmTargetCompileOptionsCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; - -private: - void HandleMissingTarget(const std::string& name) override; - bool HandleDirectContent(cmTarget* tgt, - const std::vector<std::string>& content, - bool prepend, bool system) override; - std::string Join(const std::vector<std::string>& content) override; -}; +bool cmTargetCompileOptionsCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmTargetIncludeDirectoriesCommand.cxx b/Source/cmTargetIncludeDirectoriesCommand.cxx index 7801ee8..95b69f3 100644 --- a/Source/cmTargetIncludeDirectoriesCommand.cxx +++ b/Source/cmTargetIncludeDirectoriesCommand.cxx @@ -11,26 +11,36 @@ #include "cmStringAlgorithms.h" #include "cmSystemTools.h" #include "cmTarget.h" +#include "cmTargetPropCommandBase.h" -class cmExecutionStatus; +namespace { -bool cmTargetIncludeDirectoriesCommand::InitialPass( - std::vector<std::string> const& args, cmExecutionStatus&) +class TargetIncludeDirectoriesImpl : public cmTargetPropCommandBase { - return this->HandleArguments(args, "INCLUDE_DIRECTORIES", - ArgumentFlags(PROCESS_BEFORE | PROCESS_SYSTEM)); -} +public: + using cmTargetPropCommandBase::cmTargetPropCommandBase; -void cmTargetIncludeDirectoriesCommand::HandleMissingTarget( - const std::string& name) -{ - this->Makefile->IssueMessage( - MessageType::FATAL_ERROR, - cmStrCat("Cannot specify include directories for target \"", name, - "\" which is not built by this project.")); -} +private: + void HandleMissingTarget(const std::string& name) override + { + this->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("Cannot specify include directories for target \"", name, + "\" which is not built by this project.")); + } + + bool HandleDirectContent(cmTarget* tgt, + const std::vector<std::string>& content, + bool prepend, bool system) override; + + void HandleInterfaceContent(cmTarget* tgt, + const std::vector<std::string>& content, + bool prepend, bool system) override; -std::string cmTargetIncludeDirectoriesCommand::Join( + std::string Join(const std::vector<std::string>& content) override; +}; + +std::string TargetIncludeDirectoriesImpl::Join( const std::vector<std::string>& content) { std::string dirs; @@ -48,7 +58,7 @@ std::string cmTargetIncludeDirectoriesCommand::Join( return dirs; } -bool cmTargetIncludeDirectoriesCommand::HandleDirectContent( +bool TargetIncludeDirectoriesImpl::HandleDirectContent( cmTarget* tgt, const std::vector<std::string>& content, bool prepend, bool system) { @@ -70,16 +80,27 @@ bool cmTargetIncludeDirectoriesCommand::HandleDirectContent( return true; // Successfully handled. } -void cmTargetIncludeDirectoriesCommand::HandleInterfaceContent( +void TargetIncludeDirectoriesImpl::HandleInterfaceContent( cmTarget* tgt, const std::vector<std::string>& content, bool prepend, bool system) { cmTargetPropCommandBase::HandleInterfaceContent(tgt, content, prepend, system); - if (system) { std::string joined = this->Join(content); tgt->AppendProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES", joined.c_str()); } } + +} // namespace + +bool cmTargetIncludeDirectoriesCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) +{ + return TargetIncludeDirectoriesImpl(status).HandleArguments( + args, "INCLUDE_DIRECTORIES", + TargetIncludeDirectoriesImpl::ArgumentFlags( + TargetIncludeDirectoriesImpl::PROCESS_BEFORE | + TargetIncludeDirectoriesImpl::PROCESS_SYSTEM)); +} diff --git a/Source/cmTargetIncludeDirectoriesCommand.h b/Source/cmTargetIncludeDirectoriesCommand.h index f6481db..9958f41 100644 --- a/Source/cmTargetIncludeDirectoriesCommand.h +++ b/Source/cmTargetIncludeDirectoriesCommand.h @@ -8,43 +8,9 @@ #include <string> #include <vector> -#include <cm/memory> - -#include "cmCommand.h" -#include "cmTargetPropCommandBase.h" - class cmExecutionStatus; -class cmTarget; - -class cmTargetIncludeDirectoriesCommand : public cmTargetPropCommandBase -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmTargetIncludeDirectoriesCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; - -private: - void HandleMissingTarget(const std::string& name) override; - - bool HandleDirectContent(cmTarget* tgt, - const std::vector<std::string>& content, - bool prepend, bool system) override; - void HandleInterfaceContent(cmTarget* tgt, - const std::vector<std::string>& content, - bool prepend, bool system) override; - std::string Join(const std::vector<std::string>& content) override; -}; +bool cmTargetIncludeDirectoriesCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmTargetLinkDirectoriesCommand.cxx b/Source/cmTargetLinkDirectoriesCommand.cxx index c2ef6c1..0c68d60 100644 --- a/Source/cmTargetLinkDirectoriesCommand.cxx +++ b/Source/cmTargetLinkDirectoriesCommand.cxx @@ -9,25 +9,37 @@ #include "cmStringAlgorithms.h" #include "cmSystemTools.h" #include "cmTarget.h" +#include "cmTargetPropCommandBase.h" -class cmExecutionStatus; +namespace { -bool cmTargetLinkDirectoriesCommand::InitialPass( - std::vector<std::string> const& args, cmExecutionStatus&) +class TargetLinkDirectoriesImpl : public cmTargetPropCommandBase { - return this->HandleArguments(args, "LINK_DIRECTORIES", PROCESS_BEFORE); -} +public: + using cmTargetPropCommandBase::cmTargetPropCommandBase; -void cmTargetLinkDirectoriesCommand::HandleMissingTarget( - const std::string& name) -{ - this->Makefile->IssueMessage( - MessageType::FATAL_ERROR, - cmStrCat("Cannot specify link directories for target \"", name, - "\" which is not built by this project.")); -} +private: + void HandleMissingTarget(const std::string& name) override + { + this->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("Cannot specify link directories for target \"", name, + "\" which is not built by this project.")); + } + + std::string Join(const std::vector<std::string>& content) override; -std::string cmTargetLinkDirectoriesCommand::Join( + bool HandleDirectContent(cmTarget* tgt, + const std::vector<std::string>& content, + bool prepend, bool /*system*/) override + { + cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); + tgt->InsertLinkDirectory(this->Join(content), lfbt, prepend); + return true; // Successfully handled. + } +}; + +std::string TargetLinkDirectoriesImpl::Join( const std::vector<std::string>& content) { std::vector<std::string> directories; @@ -48,12 +60,11 @@ std::string cmTargetLinkDirectoriesCommand::Join( return cmJoin(directories, ";"); } -bool cmTargetLinkDirectoriesCommand::HandleDirectContent( - cmTarget* tgt, const std::vector<std::string>& content, bool prepend, bool) -{ - cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); +} // namespace - tgt->InsertLinkDirectory(this->Join(content), lfbt, prepend); - - return true; // Successfully handled. +bool cmTargetLinkDirectoriesCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) +{ + return TargetLinkDirectoriesImpl(status).HandleArguments( + args, "LINK_DIRECTORIES", TargetLinkDirectoriesImpl::PROCESS_BEFORE); } diff --git a/Source/cmTargetLinkDirectoriesCommand.h b/Source/cmTargetLinkDirectoriesCommand.h index a651d73..3724d6c 100644 --- a/Source/cmTargetLinkDirectoriesCommand.h +++ b/Source/cmTargetLinkDirectoriesCommand.h @@ -8,39 +8,9 @@ #include <string> #include <vector> -#include <cm/memory> - -#include "cmCommand.h" -#include "cmTargetPropCommandBase.h" - class cmExecutionStatus; -class cmTarget; - -class cmTargetLinkDirectoriesCommand : public cmTargetPropCommandBase -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmTargetLinkDirectoriesCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; - -private: - void HandleMissingTarget(const std::string& name) override; - std::string Join(const std::vector<std::string>& content) override; - bool HandleDirectContent(cmTarget* tgt, - const std::vector<std::string>& content, - bool prepend, bool system) override; -}; +bool cmTargetLinkDirectoriesCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmTargetLinkOptionsCommand.cxx b/Source/cmTargetLinkOptionsCommand.cxx index dbd7bfe..df9416f 100644 --- a/Source/cmTargetLinkOptionsCommand.cxx +++ b/Source/cmTargetLinkOptionsCommand.cxx @@ -7,33 +7,44 @@ #include "cmMessageType.h" #include "cmStringAlgorithms.h" #include "cmTarget.h" +#include "cmTargetPropCommandBase.h" -class cmExecutionStatus; +namespace { -bool cmTargetLinkOptionsCommand::InitialPass( - std::vector<std::string> const& args, cmExecutionStatus&) +class TargetLinkOptionsImpl : public cmTargetPropCommandBase { - return this->HandleArguments(args, "LINK_OPTIONS", PROCESS_BEFORE); -} +public: + using cmTargetPropCommandBase::cmTargetPropCommandBase; -void cmTargetLinkOptionsCommand::HandleMissingTarget(const std::string& name) -{ - this->Makefile->IssueMessage( - MessageType::FATAL_ERROR, - cmStrCat("Cannot specify link options for target \"", name, - "\" which is not built by this project.")); -} +private: + void HandleMissingTarget(const std::string& name) override + { + this->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("Cannot specify link options for target \"", name, + "\" which is not built by this project.")); + } -std::string cmTargetLinkOptionsCommand::Join( - const std::vector<std::string>& content) -{ - return cmJoin(content, ";"); -} + bool HandleDirectContent(cmTarget* tgt, + const std::vector<std::string>& content, + bool prepend, bool /*system*/) override + { + cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); + tgt->InsertLinkOption(this->Join(content), lfbt, prepend); + return true; // Successfully handled. + } + + std::string Join(const std::vector<std::string>& content) override + { + return cmJoin(content, ";"); + } +}; + +} // namespace -bool cmTargetLinkOptionsCommand::HandleDirectContent( - cmTarget* tgt, const std::vector<std::string>& content, bool prepend, bool) +bool cmTargetLinkOptionsCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) { - cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); - tgt->InsertLinkOption(this->Join(content), lfbt, prepend); - return true; // Successfully handled. + return TargetLinkOptionsImpl(status).HandleArguments( + args, "LINK_OPTIONS", TargetLinkOptionsImpl::PROCESS_BEFORE); } diff --git a/Source/cmTargetLinkOptionsCommand.h b/Source/cmTargetLinkOptionsCommand.h index 918a8d7..13fb40c 100644 --- a/Source/cmTargetLinkOptionsCommand.h +++ b/Source/cmTargetLinkOptionsCommand.h @@ -8,39 +8,9 @@ #include <string> #include <vector> -#include <cm/memory> - -#include "cmCommand.h" -#include "cmTargetPropCommandBase.h" - class cmExecutionStatus; -class cmTarget; - -class cmTargetLinkOptionsCommand : public cmTargetPropCommandBase -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmTargetLinkOptionsCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; - -private: - void HandleMissingTarget(const std::string& name) override; - bool HandleDirectContent(cmTarget* tgt, - const std::vector<std::string>& content, - bool prepend, bool system) override; - std::string Join(const std::vector<std::string>& content) override; -}; +bool cmTargetLinkOptionsCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmTargetPrecompileHeadersCommand.cxx b/Source/cmTargetPrecompileHeadersCommand.cxx index 5751fff..887d973 100644 --- a/Source/cmTargetPrecompileHeadersCommand.cxx +++ b/Source/cmTargetPrecompileHeadersCommand.cxx @@ -8,51 +8,14 @@ #include "cmStringAlgorithms.h" #include "cmSystemTools.h" #include "cmTarget.h" +#include "cmTargetPropCommandBase.h" #include <utility> -bool cmTargetPrecompileHeadersCommand::InitialPass( - std::vector<std::string> const& args, cmExecutionStatus&) -{ - return this->HandleArguments(args, "PRECOMPILE_HEADERS", PROCESS_REUSE_FROM); -} - -void cmTargetPrecompileHeadersCommand::HandleInterfaceContent( - cmTarget* tgt, const std::vector<std::string>& content, bool prepend, - bool system) -{ - cmTargetPropCommandBase::HandleInterfaceContent( - tgt, ConvertToAbsoluteContent(tgt, content, true), prepend, system); -} - -void cmTargetPrecompileHeadersCommand::HandleMissingTarget( - const std::string& name) -{ - const std::string e = - cmStrCat("Cannot specify precompile headers for target \"", name, - "\" which is not built by this project."); - this->Makefile->IssueMessage(MessageType::FATAL_ERROR, e); -} - -std::string cmTargetPrecompileHeadersCommand::Join( - const std::vector<std::string>& content) -{ - return cmJoin(content, ";"); -} - -bool cmTargetPrecompileHeadersCommand::HandleDirectContent( - cmTarget* tgt, const std::vector<std::string>& content, bool, bool) -{ - tgt->AppendProperty( - "PRECOMPILE_HEADERS", - this->Join(ConvertToAbsoluteContent(tgt, content, false)).c_str()); - return true; -} +namespace { -std::vector<std::string> -cmTargetPrecompileHeadersCommand::ConvertToAbsoluteContent( - cmTarget* /*tgt*/, const std::vector<std::string>& content, - bool /*isInterfaceContent*/) +std::vector<std::string> ConvertToAbsoluteContent( + const std::vector<std::string>& content, std::string const& baseDir) { std::vector<std::string> absoluteContent; absoluteContent.reserve(content.size()); @@ -66,10 +29,59 @@ cmTargetPrecompileHeadersCommand::ConvertToAbsoluteContent( cmGeneratorExpression::Find(src) == 0) { absoluteSrc = src; } else { - absoluteSrc = - cmStrCat(this->Makefile->GetCurrentSourceDirectory(), '/', src); + absoluteSrc = cmStrCat(baseDir, '/', src); } absoluteContent.emplace_back(std::move(absoluteSrc)); } return absoluteContent; } + +class TargetPrecompileHeadersImpl : public cmTargetPropCommandBase +{ +public: + using cmTargetPropCommandBase::cmTargetPropCommandBase; + +private: + bool HandleDirectContent(cmTarget* tgt, + const std::vector<std::string>& content, + bool /*prepend*/, bool /*system*/) override + { + std::string const& base = this->Makefile->GetCurrentSourceDirectory(); + tgt->AppendProperty( + "PRECOMPILE_HEADERS", + this->Join(ConvertToAbsoluteContent(content, base)).c_str()); + return true; + } + + void HandleInterfaceContent(cmTarget* tgt, + const std::vector<std::string>& content, + bool prepend, bool system) override + { + std::string const& base = this->Makefile->GetCurrentSourceDirectory(); + cmTargetPropCommandBase::HandleInterfaceContent( + tgt, ConvertToAbsoluteContent(content, base), prepend, system); + } + + void HandleMissingTarget(const std::string& name) override + { + this->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("Cannot specify precompile headers for target \"", name, + "\" which is not built by this project.")); + } + + std::string Join(const std::vector<std::string>& content) override + { + return cmJoin(content, ";"); + } +}; + +} // namespace + +bool cmTargetPrecompileHeadersCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) +{ + return TargetPrecompileHeadersImpl(status).HandleArguments( + args, "PRECOMPILE_HEADERS", + TargetPrecompileHeadersImpl::PROCESS_REUSE_FROM); +} diff --git a/Source/cmTargetPrecompileHeadersCommand.h b/Source/cmTargetPrecompileHeadersCommand.h index 00dc928..8b0ac97 100644 --- a/Source/cmTargetPrecompileHeadersCommand.h +++ b/Source/cmTargetPrecompileHeadersCommand.h @@ -8,43 +8,9 @@ #include <string> #include <vector> -#include <cm/memory> - -#include "cmCommand.h" - -#include "cmTargetPropCommandBase.h" - class cmExecutionStatus; -class cmTarget; - -class cmTargetPrecompileHeadersCommand : public cmTargetPropCommandBase -{ -public: - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmTargetPrecompileHeadersCommand>(); - } - - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; - -protected: - void HandleInterfaceContent(cmTarget* tgt, - const std::vector<std::string>& content, - bool prepend, bool system) override; - -private: - void HandleMissingTarget(const std::string& name) override; - - bool HandleDirectContent(cmTarget* tgt, - const std::vector<std::string>& content, - bool prepend, bool system) override; - - std::string Join(const std::vector<std::string>& content) override; - std::vector<std::string> ConvertToAbsoluteContent( - cmTarget* tgt, const std::vector<std::string>& content, - bool isInterfaceContent); -}; +bool cmTargetPrecompileHeadersCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif diff --git a/Source/cmTargetPropCommandBase.cxx b/Source/cmTargetPropCommandBase.cxx index 4bc3125..bbc1e16 100644 --- a/Source/cmTargetPropCommandBase.cxx +++ b/Source/cmTargetPropCommandBase.cxx @@ -2,12 +2,24 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmTargetPropCommandBase.h" +#include "cmExecutionStatus.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" #include "cmStateTypes.h" #include "cmTarget.h" #include "cmake.h" +cmTargetPropCommandBase::cmTargetPropCommandBase(cmExecutionStatus& status) + : Makefile(&status.GetMakefile()) + , Status(status) +{ +} + +void cmTargetPropCommandBase::SetError(std::string const& e) +{ + this->Status.SetError(e); +} + bool cmTargetPropCommandBase::HandleArguments( std::vector<std::string> const& args, const std::string& prop, ArgumentFlags flags) diff --git a/Source/cmTargetPropCommandBase.h b/Source/cmTargetPropCommandBase.h index b244417..601ad01 100644 --- a/Source/cmTargetPropCommandBase.h +++ b/Source/cmTargetPropCommandBase.h @@ -8,13 +8,18 @@ #include <string> #include <vector> -#include "cmCommand.h" - +class cmExecutionStatus; +class cmMakefile; class cmTarget; -class cmTargetPropCommandBase : public cmCommand +class cmTargetPropCommandBase { public: + cmTargetPropCommandBase(cmExecutionStatus& status); + virtual ~cmTargetPropCommandBase() = default; + + void SetError(std::string const& e); + enum ArgumentFlags { NO_FLAGS = 0x0, @@ -30,6 +35,7 @@ public: protected: std::string Property; cmTarget* Target = nullptr; + cmMakefile* Makefile; virtual void HandleInterfaceContent(cmTarget* tgt, const std::vector<std::string>& content, @@ -49,6 +55,8 @@ private: bool PopulateTargetProperies(const std::string& scope, const std::vector<std::string>& content, bool prepend, bool system); + + cmExecutionStatus& Status; }; #endif diff --git a/Source/cmTargetSourcesCommand.cxx b/Source/cmTargetSourcesCommand.cxx index 7c9d03c..c2e0b28 100644 --- a/Source/cmTargetSourcesCommand.cxx +++ b/Source/cmTargetSourcesCommand.cxx @@ -11,47 +11,54 @@ #include "cmStringAlgorithms.h" #include "cmSystemTools.h" #include "cmTarget.h" +#include "cmTargetPropCommandBase.h" -class cmExecutionStatus; +namespace { -bool cmTargetSourcesCommand::InitialPass(std::vector<std::string> const& args, - cmExecutionStatus&) +class TargetSourcesImpl : public cmTargetPropCommandBase { - return this->HandleArguments(args, "SOURCES"); -} +public: + using cmTargetPropCommandBase::cmTargetPropCommandBase; -void cmTargetSourcesCommand::HandleInterfaceContent( - cmTarget* tgt, const std::vector<std::string>& content, bool prepend, - bool system) -{ - cmTargetPropCommandBase::HandleInterfaceContent( - tgt, ConvertToAbsoluteContent(tgt, content, true), prepend, system); -} +protected: + void HandleInterfaceContent(cmTarget* tgt, + const std::vector<std::string>& content, + bool prepend, bool system) override + { + cmTargetPropCommandBase::HandleInterfaceContent( + tgt, ConvertToAbsoluteContent(tgt, content, true), prepend, system); + } -void cmTargetSourcesCommand::HandleMissingTarget(const std::string& name) -{ - this->Makefile->IssueMessage( - MessageType::FATAL_ERROR, - cmStrCat("Cannot specify sources for target \"", name, - "\" which is not built by this project.")); -} +private: + void HandleMissingTarget(const std::string& name) override + { + this->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("Cannot specify sources for target \"", name, + "\" which is not built by this project.")); + } -std::string cmTargetSourcesCommand::Join( - const std::vector<std::string>& content) -{ - return cmJoin(content, ";"); -} + bool HandleDirectContent(cmTarget* tgt, + const std::vector<std::string>& content, + bool /*prepend*/, bool /*system*/) override + { + tgt->AppendProperty( + "SOURCES", + this->Join(ConvertToAbsoluteContent(tgt, content, false)).c_str()); + return true; // Successfully handled. + } -bool cmTargetSourcesCommand::HandleDirectContent( - cmTarget* tgt, const std::vector<std::string>& content, bool, bool) -{ - tgt->AppendProperty( - "SOURCES", - this->Join(ConvertToAbsoluteContent(tgt, content, false)).c_str()); - return true; // Successfully handled. -} + std::string Join(const std::vector<std::string>& content) override + { + return cmJoin(content, ";"); + } + + std::vector<std::string> ConvertToAbsoluteContent( + cmTarget* tgt, const std::vector<std::string>& content, + bool isInterfaceContent); +}; -std::vector<std::string> cmTargetSourcesCommand::ConvertToAbsoluteContent( +std::vector<std::string> TargetSourcesImpl::ConvertToAbsoluteContent( cmTarget* tgt, const std::vector<std::string>& content, bool isInterfaceContent) { @@ -120,3 +127,11 @@ std::vector<std::string> cmTargetSourcesCommand::ConvertToAbsoluteContent( return useAbsoluteContent ? absoluteContent : content; } + +} // namespace + +bool cmTargetSourcesCommand(std::vector<std::string> const& args, + cmExecutionStatus& status) +{ + return TargetSourcesImpl(status).HandleArguments(args, "SOURCES"); +} diff --git a/Source/cmTargetSourcesCommand.h b/Source/cmTargetSourcesCommand.h index 1cff8c3..5eecf34 100644 --- a/Source/cmTargetSourcesCommand.h +++ b/Source/cmTargetSourcesCommand.h @@ -8,49 +8,9 @@ #include <string> #include <vector> -#include <cm/memory> - -#include "cmCommand.h" -#include "cmTargetPropCommandBase.h" - class cmExecutionStatus; -class cmTarget; - -class cmTargetSourcesCommand : public cmTargetPropCommandBase -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmTargetSourcesCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; - -protected: - void HandleInterfaceContent(cmTarget* tgt, - const std::vector<std::string>& content, - bool prepend, bool system) override; - -private: - void HandleMissingTarget(const std::string& name) override; - - bool HandleDirectContent(cmTarget* tgt, - const std::vector<std::string>& content, - bool prepend, bool system) override; - - std::string Join(const std::vector<std::string>& content) override; - std::vector<std::string> ConvertToAbsoluteContent( - cmTarget* tgt, const std::vector<std::string>& content, - bool isInterfaceContent); -}; +bool cmTargetSourcesCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=587ccffe74638676090005ac6b7f799f15a0112c commit 587ccffe74638676090005ac6b7f799f15a0112c Author: Brad King <brad.k...@kitware.com> AuthorDate: Thu Sep 26 10:27:55 2019 -0400 Commit: Brad King <brad.k...@kitware.com> CommitDate: Thu Sep 26 10:31:44 2019 -0400 Tests: Add symbols to FortranModules static libraries When GNU `ar` creates an archive with no symbols it has only an empty header but no string table. On Solaris the OS-provided `ld` fails in this case: ld: elf error: file libfoo.a: elf_getarsym Update our test to actually provide symbols from its archives. diff --git a/Tests/FortranModules/Library/a.f90 b/Tests/FortranModules/Library/a.f90 index 3031c07..c180cc0 100644 --- a/Tests/FortranModules/Library/a.f90 +++ b/Tests/FortranModules/Library/a.f90 @@ -1,3 +1,6 @@ MODULE libraryModuleA USE libraryModuleB +CONTAINS + SUBROUTINE libA + END SUBROUTINE END MODULE diff --git a/Tests/FortranModules/Library/b.f90 b/Tests/FortranModules/Library/b.f90 index ae1edcb..f550996 100644 --- a/Tests/FortranModules/Library/b.f90 +++ b/Tests/FortranModules/Library/b.f90 @@ -1,2 +1,5 @@ MODULE libraryModuleB +CONTAINS + SUBROUTINE libB + END SUBROUTINE END MODULE diff --git a/Tests/FortranModules/Subdir/subdir.f90 b/Tests/FortranModules/Subdir/subdir.f90 index 68955f6..5288b06 100644 --- a/Tests/FortranModules/Subdir/subdir.f90 +++ b/Tests/FortranModules/Subdir/subdir.f90 @@ -1,2 +1,5 @@ MODULE subdirModuleA +CONTAINS + SUBROUTINE subdirLibA + END SUBROUTINE END MODULE https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=5a06efda05feda02511592c76134ee8ed3e8b650 commit 5a06efda05feda02511592c76134ee8ed3e8b650 Author: Daniel Eiband <daniel.eib...@brainlab.com> AuthorDate: Sat Sep 21 01:17:15 2019 +0200 Commit: Brad King <brad.k...@kitware.com> CommitDate: Thu Sep 26 10:04:03 2019 -0400 cmMakefile: Remove AddUtilityCommand overload without byproducts diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx index 29d2495..78a232e 100644 --- a/Source/cmCPluginAPI.cxx +++ b/Source/cmCPluginAPI.cxx @@ -220,8 +220,10 @@ void CCONV cmAddUtilityCommand(void* arg, const char* utilityName, } // Pass the call to the makefile instance. + std::vector<std::string> no_byproducts; mf->AddUtilityCommand(utilityName, cmCommandOrigin::Project, - (all ? false : true), nullptr, depends2, commandLines); + (all ? false : true), nullptr, no_byproducts, depends2, + commandLines); } void CCONV cmAddCustomCommand(void* arg, const char* source, const char* command, int numArgs, diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index 808bebd..8e6125b 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -96,17 +96,18 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget() return false; } - const char* no_working_directory = nullptr; - std::vector<std::string> no_depends; std::vector<cmLocalGenerator*> const& generators = this->LocalGenerators; cmLocalVisualStudio7Generator* lg = static_cast<cmLocalVisualStudio7Generator*>(generators[0]); cmMakefile* mf = lg->GetMakefile(); - cmCustomCommandLines noCommandLines; + const char* no_working_directory = nullptr; + std::vector<std::string> no_byproducts; + std::vector<std::string> no_depends; + cmCustomCommandLines no_commands; cmTarget* tgt = mf->AddUtilityCommand( CMAKE_CHECK_BUILD_SYSTEM_TARGET, cmCommandOrigin::Generator, false, - no_working_directory, no_depends, noCommandLines); + no_working_directory, no_byproducts, no_depends, no_commands); cmGeneratorTarget* gt = new cmGeneratorTarget(tgt, lg); lg->AddGeneratorTarget(gt); @@ -182,7 +183,6 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget() // file as the main dependency because it would get // overwritten by the CreateVCProjBuildRule. // (this could be avoided with per-target source files) - std::vector<std::string> no_byproducts; std::string no_main_dependency; cmImplicitDependsList no_implicit_depends; if (cmSourceFile* file = mf->AddCustomCommandToOutput( diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index 82219bd..0bc08a5 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -183,7 +183,8 @@ void cmGlobalVisualStudioGenerator::AddExtraIDETargets() { // Add a special target that depends on ALL projects for easy build // of one configuration only. - const char* no_working_dir = 0; + const char* no_working_dir = nullptr; + std::vector<std::string> no_byproducts; std::vector<std::string> no_depends; cmCustomCommandLines no_commands; for (auto const& it : this->ProjectMap) { @@ -194,7 +195,7 @@ void cmGlobalVisualStudioGenerator::AddExtraIDETargets() // considered always out of date. cmTarget* allBuild = gen[0]->GetMakefile()->AddUtilityCommand( "ALL_BUILD", cmCommandOrigin::Generator, true, no_working_dir, - no_depends, no_commands, false, "Build all projects"); + no_byproducts, no_depends, no_commands, false, "Build all projects"); cmGeneratorTarget* gt = new cmGeneratorTarget(allBuild, gen[0]); gen[0]->AddGeneratorTarget(gt); diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index e4dff78..4202175 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -497,12 +497,15 @@ void cmGlobalXCodeGenerator::AddExtraTargets( { cmMakefile* mf = root->GetMakefile(); - // Add ALL_BUILD const char* no_working_directory = nullptr; + std::vector<std::string> no_byproducts; std::vector<std::string> no_depends; + + // Add ALL_BUILD cmTarget* allbuild = mf->AddUtilityCommand( "ALL_BUILD", cmCommandOrigin::Generator, true, no_working_directory, - no_depends, cmMakeSingleCommandLine({ "echo", "Build all projects" })); + no_byproducts, no_depends, + cmMakeSingleCommandLine({ "echo", "Build all projects" })); cmGeneratorTarget* allBuildGt = new cmGeneratorTarget(allbuild, root); root->AddGeneratorTarget(allBuildGt); @@ -526,7 +529,7 @@ void cmGlobalXCodeGenerator::AddExtraTargets( cmSystemTools::ReplaceString(file, "\\ ", " "); cmTarget* check = mf->AddUtilityCommand( CMAKE_CHECK_BUILD_SYSTEM_TARGET, cmCommandOrigin::Generator, true, - no_working_directory, no_depends, + no_working_directory, no_byproducts, no_depends, cmMakeSingleCommandLine({ "make", "-f", file })); cmGeneratorTarget* checkGt = new cmGeneratorTarget(check, root); @@ -541,9 +544,8 @@ void cmGlobalXCodeGenerator::AddExtraTargets( continue; } - std::string targetName = target->GetName(); - - if (regenerate && (targetName != CMAKE_CHECK_BUILD_SYSTEM_TARGET)) { + if (regenerate && + (target->GetName() != CMAKE_CHECK_BUILD_SYSTEM_TARGET)) { target->Target->AddUtility(CMAKE_CHECK_BUILD_SYSTEM_TARGET); } @@ -554,7 +556,6 @@ void cmGlobalXCodeGenerator::AddExtraTargets( if (target->GetType() == cmStateEnums::OBJECT_LIBRARY) { commandLines.front().back() = // fill placeholder this->PostBuildMakeTarget(target->GetName(), "$(CONFIGURATION)"); - std::vector<std::string> no_byproducts; gen->GetMakefile()->AddCustomCommandToTarget( target->GetName(), no_byproducts, no_depends, commandLines, cmCustomCommandType::POST_BUILD, "Depend check for xcode", diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 2e1c821..a528fc6 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1213,20 +1213,6 @@ cmUtilityOutput cmMakefile::GetUtilityOutput(cmTarget* target) cmTarget* cmMakefile::AddUtilityCommand( const std::string& utilityName, cmCommandOrigin origin, bool excludeFromAll, - const char* workingDirectory, const std::vector<std::string>& depends, - const cmCustomCommandLines& commandLines, bool escapeOldStyle, - const char* comment, bool uses_terminal, bool command_expand_lists, - const std::string& job_pool) -{ - std::vector<std::string> no_byproducts; - return this->AddUtilityCommand( - utilityName, origin, excludeFromAll, workingDirectory, no_byproducts, - depends, commandLines, escapeOldStyle, comment, uses_terminal, - command_expand_lists, job_pool); -} - -cmTarget* cmMakefile::AddUtilityCommand( - const std::string& utilityName, cmCommandOrigin origin, bool excludeFromAll, const char* workingDirectory, const std::vector<std::string>& byproducts, const std::vector<std::string>& depends, const cmCustomCommandLines& commandLines, bool escapeOldStyle, @@ -1237,8 +1223,8 @@ cmTarget* cmMakefile::AddUtilityCommand( this->AddNewUtilityTarget(utilityName, origin, excludeFromAll); // Validate custom commands. - if (!this->ValidateCustomCommand(commandLines) || - (commandLines.empty() && depends.empty())) { + if ((commandLines.empty() && depends.empty()) || + !this->ValidateCustomCommand(commandLines)) { return target; } diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 5ea2cce..bb88bed 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -264,13 +264,6 @@ public: cmTarget* AddUtilityCommand( const std::string& utilityName, cmCommandOrigin origin, bool excludeFromAll, const char* workingDirectory, - const std::vector<std::string>& depends, - const cmCustomCommandLines& commandLines, bool escapeOldStyle = true, - const char* comment = nullptr, bool uses_terminal = false, - bool command_expand_lists = false, const std::string& job_pool = ""); - cmTarget* AddUtilityCommand( - const std::string& utilityName, cmCommandOrigin origin, - bool excludeFromAll, const char* workingDirectory, const std::vector<std::string>& byproducts, const std::vector<std::string>& depends, const cmCustomCommandLines& commandLines, bool escapeOldStyle = true, https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ea1bed34b2ba16f3971b90996dc345834f0d9699 commit ea1bed34b2ba16f3971b90996dc345834f0d9699 Author: Daniel Eiband <daniel.eib...@brainlab.com> AuthorDate: Sat Sep 21 00:55:34 2019 +0200 Commit: Brad King <brad.k...@kitware.com> CommitDate: Thu Sep 26 10:03:48 2019 -0400 cmMakefile: Extract utilities used for creation of custom commands Decompose creation of custom commands further into logical steps. diff --git a/Source/cmCustomCommandTypes.h b/Source/cmCustomCommandTypes.h index f3ecd6e..d4bf1f9 100644 --- a/Source/cmCustomCommandTypes.h +++ b/Source/cmCustomCommandTypes.h @@ -5,6 +5,8 @@ #include "cmConfigure.h" // IWYU pragma: keep +#include <string> + /** Target custom command type */ enum class cmCustomCommandType { @@ -27,4 +29,11 @@ enum class cmObjectLibraryCommands Accept }; +/** Utility target output source file name. */ +struct cmUtilityOutput +{ + std::string Name; + std::string NameCMP0049; +}; + #endif diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index d1235b2..2e1c821 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -838,13 +838,8 @@ bool cmMakefile::ValidateCustomCommand( return true; } -cmTarget* cmMakefile::AddCustomCommandToTarget( - const std::string& target, const std::vector<std::string>& byproducts, - const std::vector<std::string>& depends, - const cmCustomCommandLines& commandLines, cmCustomCommandType type, - const char* comment, const char* workingDir, bool escapeOldStyle, - bool uses_terminal, const std::string& depfile, const std::string& job_pool, - bool command_expand_lists, cmObjectLibraryCommands objLibCommands) +cmTarget* cmMakefile::GetCustomCommandTarget( + const std::string& target, cmObjectLibraryCommands objLibCommands) const { // Find the target to which to add the custom command. auto ti = this->Targets.find(target); @@ -903,8 +898,21 @@ cmTarget* cmMakefile::AddCustomCommandToTarget( return nullptr; } + return t; +} + +cmTarget* cmMakefile::AddCustomCommandToTarget( + const std::string& target, const std::vector<std::string>& byproducts, + const std::vector<std::string>& depends, + const cmCustomCommandLines& commandLines, cmCustomCommandType type, + const char* comment, const char* workingDir, bool escapeOldStyle, + bool uses_terminal, const std::string& depfile, const std::string& job_pool, + bool command_expand_lists, cmObjectLibraryCommands objLibCommands) +{ + cmTarget* t = this->GetCustomCommandTarget(target, objLibCommands); + // Validate custom commands. - if (!this->ValidateCustomCommand(commandLines)) { + if (!t || !this->ValidateCustomCommand(commandLines)) { return t; } @@ -947,37 +955,8 @@ void cmMakefile::CommitCustomCommandToTarget( target->AddPostBuildCommand(std::move(cc)); break; } - this->UpdateOutputToSourceMap(byproducts, target); -} -void cmMakefile::UpdateOutputToSourceMap( - std::vector<std::string> const& byproducts, cmTarget* target) -{ - for (std::string const& o : byproducts) { - this->UpdateOutputToSourceMap(o, target); - } -} - -void cmMakefile::UpdateOutputToSourceMap(std::string const& byproduct, - cmTarget* target) -{ - SourceEntry entry; - entry.Sources.Target = target; - - auto pr = this->OutputToSource.emplace(byproduct, entry); - if (!pr.second) { - SourceEntry& current = pr.first->second; - // Has the target already been set? - if (!current.Sources.Target) { - current.Sources.Target = target; - } else { - // Multiple custom commands/targets produce the same output (source file - // or target). See also comment in other UpdateOutputToSourceMap - // overload. - // - // TODO: Warn the user about this case. - } - } + this->AddTargetByproducts(target, byproducts); } cmSourceFile* cmMakefile::AddCustomCommandToOutput( @@ -1103,47 +1082,10 @@ cmSourceFile* cmMakefile::CommitCustomCommandToOutput( cc->SetDepfile(depfile); cc->SetJobPool(job_pool); file->SetCustomCommand(std::move(cc)); - this->UpdateOutputToSourceMap(outputs, file, false); - this->UpdateOutputToSourceMap(byproducts, file, true); - } - return file; -} -void cmMakefile::UpdateOutputToSourceMap( - std::vector<std::string> const& outputs, cmSourceFile* source, - bool byproduct) -{ - for (std::string const& o : outputs) { - this->UpdateOutputToSourceMap(o, source, byproduct); - } -} - -void cmMakefile::UpdateOutputToSourceMap(std::string const& output, - cmSourceFile* source, bool byproduct) -{ - SourceEntry entry; - entry.Sources.Source = source; - entry.Sources.SourceIsByproduct = byproduct; - - auto pr = this->OutputToSource.emplace(output, entry); - if (!pr.second) { - SourceEntry& current = pr.first->second; - // Outputs take precedence over byproducts - if (!current.Sources.Source || - (current.Sources.SourceIsByproduct && !byproduct)) { - current.Sources.Source = source; - current.Sources.SourceIsByproduct = false; - } else { - // Multiple custom commands produce the same output but may - // be attached to a different source file (MAIN_DEPENDENCY). - // LinearGetSourceFileWithOutput would return the first one, - // so keep the mapping for the first one. - // - // TODO: Warn the user about this case. However, the VS 8 generator - // triggers it for separate generate.stamp rules in ZERO_CHECK and - // individual targets. - } + this->AddSourceOutputs(file, outputs, byproducts); } + return file; } void cmMakefile::AddCustomCommandOldStyle( @@ -1248,6 +1190,27 @@ void cmMakefile::CommitAppendCustomCommandToOutput( } } +cmUtilityOutput cmMakefile::GetUtilityOutput(cmTarget* target) +{ + std::string force = cmStrCat(this->GetCurrentBinaryDirectory(), + "/CMakeFiles/", target->GetName()); + std::string forceCMP0049 = target->GetSourceCMP0049(force); + { + cmSourceFile* sf = nullptr; + if (!forceCMP0049.empty()) { + sf = this->GetOrCreateSource(forceCMP0049, false, + cmSourceFileLocationKind::Known); + } + // The output is not actually created so mark it symbolic. + if (sf) { + sf->SetProperty("SYMBOLIC", "1"); + } else { + cmSystemTools::Error("Could not get source file entry for " + force); + } + } + return { std::move(force), std::move(forceCMP0049) }; +} + cmTarget* cmMakefile::AddUtilityCommand( const std::string& utilityName, cmCommandOrigin origin, bool excludeFromAll, const char* workingDirectory, const std::vector<std::string>& depends, @@ -1270,12 +1233,8 @@ cmTarget* cmMakefile::AddUtilityCommand( const char* comment, bool uses_terminal, bool command_expand_lists, const std::string& job_pool) { - // Create a target instance for this utility. - cmTarget* target = this->AddNewTarget(cmStateEnums::UTILITY, utilityName); - target->SetIsGeneratorProvided(origin == cmCommandOrigin::Generator); - if (excludeFromAll || this->GetPropertyAsBool("EXCLUDE_FROM_ALL")) { - target->SetProperty("EXCLUDE_FROM_ALL", "TRUE"); - } + cmTarget* target = + this->AddNewUtilityTarget(utilityName, origin, excludeFromAll); // Validate custom commands. if (!this->ValidateCustomCommand(commandLines) || @@ -1283,50 +1242,35 @@ cmTarget* cmMakefile::AddUtilityCommand( return target; } + // Get the output name of the utility target and mark it generated. + cmUtilityOutput force = this->GetUtilityOutput(target); + this->GetOrCreateGeneratedSource(force.Name); + // Always create the byproduct sources and mark them generated. this->CreateGeneratedSources(byproducts); - std::string force = - cmStrCat(this->GetCurrentBinaryDirectory(), "/CMakeFiles/", utilityName); - this->CreateGeneratedSource(force); - std::string forceCMP0049 = target->GetSourceCMP0049(force); - { - cmSourceFile* sf = nullptr; - if (!forceCMP0049.empty()) { - sf = this->GetOrCreateSource(forceCMP0049, false, - cmSourceFileLocationKind::Known); - } - // The output is not actually created so mark it symbolic. - if (sf) { - sf->SetProperty("SYMBOLIC", "1"); - } else { - cmSystemTools::Error("Could not get source file entry for " + force); - } - } - if (!comment) { // Use an empty comment to avoid generation of default comment. comment = ""; } - this->CommitUtilityCommand(target, force, forceCMP0049, workingDirectory, - byproducts, depends, commandLines, escapeOldStyle, - comment, uses_terminal, command_expand_lists, - job_pool); + this->CommitUtilityCommand(target, force, workingDirectory, byproducts, + depends, commandLines, escapeOldStyle, comment, + uses_terminal, command_expand_lists, job_pool); return target; } void cmMakefile::CommitUtilityCommand( - cmTarget* target, const std::string& force, const std::string& forceCMP0049, - const char* workingDirectory, const std::vector<std::string>& byproducts, + cmTarget* target, const cmUtilityOutput& force, const char* workingDirectory, + const std::vector<std::string>& byproducts, const std::vector<std::string>& depends, const cmCustomCommandLines& commandLines, bool escapeOldStyle, const char* comment, bool uses_terminal, bool command_expand_lists, const std::string& job_pool) { std::vector<std::string> forced; - forced.push_back(force); + forced.push_back(force.Name); std::string no_main_dependency; cmImplicitDependsList no_implicit_depends; bool no_replace = false; @@ -1334,11 +1278,11 @@ void cmMakefile::CommitUtilityCommand( forced, byproducts, depends, no_main_dependency, no_implicit_depends, commandLines, comment, workingDirectory, no_replace, escapeOldStyle, uses_terminal, command_expand_lists, /*depfile=*/"", job_pool); - if (!forceCMP0049.empty()) { - target->AddSource(forceCMP0049); + if (!force.NameCMP0049.empty()) { + target->AddSource(force.NameCMP0049); } if (sf) { - this->UpdateOutputToSourceMap(byproducts, target); + this->AddTargetByproducts(target, byproducts); } } @@ -2157,6 +2101,18 @@ cmTarget* cmMakefile::AddNewTarget(cmStateEnums::TargetType type, return &it->second; } +cmTarget* cmMakefile::AddNewUtilityTarget(const std::string& utilityName, + cmCommandOrigin origin, + bool excludeFromAll) +{ + cmTarget* target = this->AddNewTarget(cmStateEnums::UTILITY, utilityName); + target->SetIsGeneratorProvided(origin == cmCommandOrigin::Generator); + if (excludeFromAll || this->GetPropertyAsBool("EXCLUDE_FROM_ALL")) { + target->SetProperty("EXCLUDE_FROM_ALL", "TRUE"); + } + return target; +} + namespace { bool AnyOutputMatches(const std::string& name, const std::vector<std::string>& outputs) @@ -2287,6 +2243,76 @@ bool cmMakefile::MightHaveCustomCommand(const std::string& name) const return false; } +void cmMakefile::AddTargetByproducts( + cmTarget* target, const std::vector<std::string>& byproducts) +{ + for (std::string const& o : byproducts) { + this->UpdateOutputToSourceMap(o, target); + } +} + +void cmMakefile::AddSourceOutputs(cmSourceFile* source, + const std::vector<std::string>& outputs, + const std::vector<std::string>& byproducts) +{ + for (std::string const& o : outputs) { + this->UpdateOutputToSourceMap(o, source, false); + } + for (std::string const& o : byproducts) { + this->UpdateOutputToSourceMap(o, source, true); + } +} + +void cmMakefile::UpdateOutputToSourceMap(std::string const& byproduct, + cmTarget* target) +{ + SourceEntry entry; + entry.Sources.Target = target; + + auto pr = this->OutputToSource.emplace(byproduct, entry); + if (!pr.second) { + SourceEntry& current = pr.first->second; + // Has the target already been set? + if (!current.Sources.Target) { + current.Sources.Target = target; + } else { + // Multiple custom commands/targets produce the same output (source file + // or target). See also comment in other UpdateOutputToSourceMap + // overload. + // + // TODO: Warn the user about this case. + } + } +} + +void cmMakefile::UpdateOutputToSourceMap(std::string const& output, + cmSourceFile* source, bool byproduct) +{ + SourceEntry entry; + entry.Sources.Source = source; + entry.Sources.SourceIsByproduct = byproduct; + + auto pr = this->OutputToSource.emplace(output, entry); + if (!pr.second) { + SourceEntry& current = pr.first->second; + // Outputs take precedence over byproducts + if (!current.Sources.Source || + (current.Sources.SourceIsByproduct && !byproduct)) { + current.Sources.Source = source; + current.Sources.SourceIsByproduct = false; + } else { + // Multiple custom commands produce the same output but may + // be attached to a different source file (MAIN_DEPENDENCY). + // LinearGetSourceFileWithOutput would return the first one, + // so keep the mapping for the first one. + // + // TODO: Warn the user about this case. However, the VS 8 generator + // triggers it for separate generate.stamp rules in ZERO_CHECK and + // individual targets. + } + } +} + #if !defined(CMAKE_BOOTSTRAP) cmSourceGroup* cmMakefile::GetSourceGroup( const std::vector<std::string>& name) const @@ -3531,19 +3557,20 @@ cmSourceFile* cmMakefile::GetOrCreateSource(const std::string& sourceName, return this->CreateSource(sourceName, generated, kind); } -void cmMakefile::CreateGeneratedSource(const std::string& output) +cmSourceFile* cmMakefile::GetOrCreateGeneratedSource( + const std::string& sourceName) { - if (cmSourceFile* out = this->GetOrCreateSource( - output, true, cmSourceFileLocationKind::Known)) { - out->SetProperty("GENERATED", "1"); - } + cmSourceFile* sf = + this->GetOrCreateSource(sourceName, true, cmSourceFileLocationKind::Known); + sf->SetProperty("GENERATED", "1"); + return sf; } void cmMakefile::CreateGeneratedSources( const std::vector<std::string>& outputs) { for (std::string const& output : outputs) { - this->CreateGeneratedSource(output); + this->GetOrCreateGeneratedSource(output); } } diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 6bac47c..5ea2cce 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -168,6 +168,12 @@ public: */ void FinalPass(); + /** + * Get the target for PRE_BUILD, PRE_LINK, or POST_BUILD commands. + */ + cmTarget* GetCustomCommandTarget( + const std::string& target, cmObjectLibraryCommands objLibCommands) const; + /** Add a custom command to the build. */ cmTarget* AddCustomCommandToTarget( const std::string& target, const std::vector<std::string>& byproducts, @@ -206,6 +212,19 @@ public: const cmCustomCommandLines& commandLines); /** + * Add target byproducts. + */ + void AddTargetByproducts(cmTarget* target, + const std::vector<std::string>& byproducts); + + /** + * Add source file outputs. + */ + void AddSourceOutputs(cmSourceFile* source, + const std::vector<std::string>& outputs, + const std::vector<std::string>& byproducts); + + /** * Add a define flag to the build. */ void AddDefineFlag(std::string const& definition); @@ -222,6 +241,10 @@ public: cmTarget* AddNewTarget(cmStateEnums::TargetType type, const std::string& name); + /** Create a target instance for the utility. */ + cmTarget* AddNewUtilityTarget(const std::string& utilityName, + cmCommandOrigin origin, bool excludeFromAll); + /** * Add an executable to the build. */ @@ -230,6 +253,11 @@ public: bool excludeFromAll = false); /** + * Return the utility target output source file name and the CMP0049 name. + */ + cmUtilityOutput GetUtilityOutput(cmTarget* target); + + /** * Add a utility to the build. A utility target is a command that * is run every time the target is built. */ @@ -447,6 +475,12 @@ public: const std::string& sourceName, bool generated = false, cmSourceFileLocationKind kind = cmSourceFileLocationKind::Ambiguous); + /** Get a cmSourceFile pointer for a given source name and always mark the + * file as generated, if the name is not found, then create the source file + * and return it. + */ + cmSourceFile* GetOrCreateGeneratedSource(const std::string& sourceName); + void AddTargetObject(std::string const& tgtName, std::string const& objFile); /** @@ -1028,13 +1062,12 @@ private: friend bool cmCMakePolicyCommand(std::vector<std::string> const& args, cmExecutionStatus& status); class IncludeScope; - friend class IncludeScope; - class ListFileScope; + class ListFileScope; friend class ListFileScope; - class BuildsystemFileScope; + class BuildsystemFileScope; friend class BuildsystemFileScope; // CMP0053 == old @@ -1053,6 +1086,8 @@ private: bool ValidateCustomCommand(const cmCustomCommandLines& commandLines) const; + void CreateGeneratedSources(const std::vector<std::string>& outputs); + void CommitCustomCommandToTarget( cmTarget* target, const std::vector<std::string>& byproducts, const std::vector<std::string>& depends, @@ -1075,8 +1110,7 @@ private: const cmImplicitDependsList& implicit_depends, const cmCustomCommandLines& commandLines); - void CommitUtilityCommand(cmTarget* target, const std::string& force, - const std::string& forceCMP0049, + void CommitUtilityCommand(cmTarget* target, const cmUtilityOutput& force, const char* workingDirectory, const std::vector<std::string>& byproducts, const std::vector<std::string>& depends, @@ -1085,9 +1119,6 @@ private: bool uses_terminal, bool command_expand_lists, const std::string& job_pool); - void CreateGeneratedSource(const std::string& output); - void CreateGeneratedSources(const std::vector<std::string>& outputs); - /** * See LinearGetSourceFileWithOutput for background information */ @@ -1112,12 +1143,7 @@ private: using OutputToSourceMap = std::unordered_map<std::string, SourceEntry>; OutputToSourceMap OutputToSource; - void UpdateOutputToSourceMap(std::vector<std::string> const& byproducts, - cmTarget* target); void UpdateOutputToSourceMap(std::string const& byproduct, cmTarget* target); - - void UpdateOutputToSourceMap(std::vector<std::string> const& outputs, - cmSourceFile* source, bool byproduct); void UpdateOutputToSourceMap(std::string const& output, cmSourceFile* source, bool byproduct); https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=91abf9f3c4a80f5a8417401d5277b3b66bc7d008 commit 91abf9f3c4a80f5a8417401d5277b3b66bc7d008 Author: Daniel Eiband <daniel.eib...@brainlab.com> AuthorDate: Fri Sep 20 22:47:50 2019 +0200 Commit: Brad King <brad.k...@kitware.com> CommitDate: Thu Sep 26 10:02:08 2019 -0400 cmCustomCommand: Move custom commands diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 2273c50..c4974f3 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -2582,7 +2582,7 @@ cmTarget cmGlobalGenerator::CreateGlobalTarget(GlobalTargetInfo const& gti, cmCustomCommand cc(nullptr, no_outputs, no_byproducts, no_depends, gti.CommandLines, nullptr, gti.WorkingDir.c_str()); cc.SetUsesTerminal(gti.UsesTerminal); - target.AddPostBuildCommand(cc); + target.AddPostBuildCommand(std::move(cc)); if (!gti.Message.empty()) { target.SetProperty("EchoString", gti.Message.c_str()); } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index e53851d..d1235b2 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -938,13 +938,13 @@ void cmMakefile::CommitCustomCommandToTarget( cc.SetJobPool(job_pool); switch (type) { case cmCustomCommandType::PRE_BUILD: - target->AddPreBuildCommand(cc); + target->AddPreBuildCommand(std::move(cc)); break; case cmCustomCommandType::PRE_LINK: - target->AddPreLinkCommand(cc); + target->AddPreLinkCommand(std::move(cc)); break; case cmCustomCommandType::POST_BUILD: - target->AddPostBuildCommand(cc); + target->AddPostBuildCommand(std::move(cc)); break; } this->UpdateOutputToSourceMap(byproducts, target); diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index 9dbd612..d7b9fa2 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -1086,7 +1086,7 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() this->Dir.Work.c_str()); cc.SetEscapeOldStyle(false); cc.SetEscapeAllowMakeVars(true); - this->GenTarget->Target->AddPreBuildCommand(cc); + this->GenTarget->Target->AddPreBuildCommand(std::move(cc)); } else { // Add link library target dependencies to the autogen target diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 1b88db6..ae77d9e 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -604,6 +604,11 @@ void cmTarget::AddPreBuildCommand(cmCustomCommand const& cmd) impl->PreBuildCommands.push_back(cmd); } +void cmTarget::AddPreBuildCommand(cmCustomCommand&& cmd) +{ + impl->PreBuildCommands.push_back(std::move(cmd)); +} + std::vector<cmCustomCommand> const& cmTarget::GetPreLinkCommands() const { return impl->PreLinkCommands; @@ -614,6 +619,11 @@ void cmTarget::AddPreLinkCommand(cmCustomCommand const& cmd) impl->PreLinkCommands.push_back(cmd); } +void cmTarget::AddPreLinkCommand(cmCustomCommand&& cmd) +{ + impl->PreLinkCommands.push_back(std::move(cmd)); +} + std::vector<cmCustomCommand> const& cmTarget::GetPostBuildCommands() const { return impl->PostBuildCommands; @@ -624,6 +634,11 @@ void cmTarget::AddPostBuildCommand(cmCustomCommand const& cmd) impl->PostBuildCommands.push_back(cmd); } +void cmTarget::AddPostBuildCommand(cmCustomCommand&& cmd) +{ + impl->PostBuildCommands.push_back(std::move(cmd)); +} + void cmTarget::AddTracedSources(std::vector<std::string> const& srcs) { if (!srcs.empty()) { diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 1b4f23a..65a1ce3 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -84,14 +84,17 @@ public: //! Get the list of the PRE_BUILD custom commands for this target std::vector<cmCustomCommand> const& GetPreBuildCommands() const; void AddPreBuildCommand(cmCustomCommand const& cmd); + void AddPreBuildCommand(cmCustomCommand&& cmd); //! Get the list of the PRE_LINK custom commands for this target std::vector<cmCustomCommand> const& GetPreLinkCommands() const; void AddPreLinkCommand(cmCustomCommand const& cmd); + void AddPreLinkCommand(cmCustomCommand&& cmd); //! Get the list of the POST_BUILD custom commands for this target std::vector<cmCustomCommand> const& GetPostBuildCommands() const; void AddPostBuildCommand(cmCustomCommand const& cmd); + void AddPostBuildCommand(cmCustomCommand&& cmd); //! Add sources to the target. void AddSources(std::vector<std::string> const& srcs); https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=f151a5770597dbe341fc6329a711f40e9195c773 commit f151a5770597dbe341fc6329a711f40e9195c773 Author: Daniel Eiband <daniel.eib...@brainlab.com> AuthorDate: Fri Sep 20 22:44:14 2019 +0200 Commit: Brad King <brad.k...@kitware.com> CommitDate: Thu Sep 26 10:02:06 2019 -0400 cmMakefile: Move enumerations into new header The enumerations will also be used in cmLocalGenerator. diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 71a7dbd..0c1f3b1 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -195,6 +195,7 @@ set(SRCS cmCustomCommandGenerator.h cmCustomCommandLines.cxx cmCustomCommandLines.h + cmCustomCommandTypes.h cmDefinitions.cxx cmDefinitions.h cmDepends.cxx diff --git a/Source/cmAddCustomCommandCommand.cxx b/Source/cmAddCustomCommandCommand.cxx index 94de851..6e04ce5 100644 --- a/Source/cmAddCustomCommandCommand.cxx +++ b/Source/cmAddCustomCommandCommand.cxx @@ -8,6 +8,7 @@ #include "cmCheckCustomOutputs.h" #include "cmCustomCommand.h" #include "cmCustomCommandLines.h" +#include "cmCustomCommandTypes.h" #include "cmExecutionStatus.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" @@ -15,7 +16,6 @@ #include "cmPolicies.h" #include "cmStringAlgorithms.h" #include "cmSystemTools.h" -#include "cmTarget.h" bool cmAddCustomCommandCommand(std::vector<std::string> const& args, cmExecutionStatus& status) @@ -55,7 +55,7 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, // Save all command lines. cmCustomCommandLines commandLines; - cmTarget::CustomCommandType cctype = cmTarget::POST_BUILD; + cmCustomCommandType cctype = cmCustomCommandType::POST_BUILD; enum tdoing { @@ -139,11 +139,11 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args, currentLine.clear(); } } else if (copy == keyPRE_BUILD) { - cctype = cmTarget::PRE_BUILD; + cctype = cmCustomCommandType::PRE_BUILD; } else if (copy == keyPRE_LINK) { - cctype = cmTarget::PRE_LINK; + cctype = cmCustomCommandType::PRE_LINK; } else if (copy == keyPOST_BUILD) { - cctype = cmTarget::POST_BUILD; + cctype = cmCustomCommandType::POST_BUILD; } else if (copy == keyVERBATIM) { verbatim = true; } else if (copy == keyAPPEND) { diff --git a/Source/cmAddCustomTargetCommand.cxx b/Source/cmAddCustomTargetCommand.cxx index b580c43..e27b126 100644 --- a/Source/cmAddCustomTargetCommand.cxx +++ b/Source/cmAddCustomTargetCommand.cxx @@ -6,6 +6,7 @@ #include "cmCheckCustomOutputs.h" #include "cmCustomCommandLines.h" +#include "cmCustomCommandTypes.h" #include "cmExecutionStatus.h" #include "cmGeneratorExpression.h" #include "cmGlobalGenerator.h" @@ -214,7 +215,7 @@ bool cmAddCustomTargetCommand(std::vector<std::string> const& args, // Add the utility target to the makefile. bool escapeOldStyle = !verbatim; cmTarget* target = mf.AddUtilityCommand( - targetName, cmMakefile::TargetOrigin::Project, excludeFromAll, + targetName, cmCommandOrigin::Project, excludeFromAll, working_directory.c_str(), byproducts, depends, commandLines, escapeOldStyle, comment, uses_terminal, command_expand_lists, job_pool); diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx index 1eaf48b..29d2495 100644 --- a/Source/cmCPluginAPI.cxx +++ b/Source/cmCPluginAPI.cxx @@ -220,7 +220,7 @@ void CCONV cmAddUtilityCommand(void* arg, const char* utilityName, } // Pass the call to the makefile instance. - mf->AddUtilityCommand(utilityName, cmMakefile::TargetOrigin::Project, + mf->AddUtilityCommand(utilityName, cmCommandOrigin::Project, (all ? false : true), nullptr, depends2, commandLines); } void CCONV cmAddCustomCommand(void* arg, const char* source, @@ -319,16 +319,16 @@ void CCONV cmAddCustomCommandToTarget(void* arg, const char* target, commandLines.push_back(commandLine); // Select the command type. - cmTarget::CustomCommandType cctype = cmTarget::POST_BUILD; + cmCustomCommandType cctype = cmCustomCommandType::POST_BUILD; switch (commandType) { case CM_PRE_BUILD: - cctype = cmTarget::PRE_BUILD; + cctype = cmCustomCommandType::PRE_BUILD; break; case CM_PRE_LINK: - cctype = cmTarget::PRE_LINK; + cctype = cmCustomCommandType::PRE_LINK; break; case CM_POST_BUILD: - cctype = cmTarget::POST_BUILD; + cctype = cmCustomCommandType::POST_BUILD; break; } diff --git a/Source/cmCustomCommandTypes.h b/Source/cmCustomCommandTypes.h new file mode 100644 index 0000000..f3ecd6e --- /dev/null +++ b/Source/cmCustomCommandTypes.h @@ -0,0 +1,30 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#ifndef cmCustomCommandTypes_h +#define cmCustomCommandTypes_h + +#include "cmConfigure.h" // IWYU pragma: keep + +/** Target custom command type */ +enum class cmCustomCommandType +{ + PRE_BUILD, + PRE_LINK, + POST_BUILD +}; + +/** Where the command originated from. */ +enum class cmCommandOrigin +{ + Project, + Generator +}; + +/** How to handle custom commands for object libraries */ +enum class cmObjectLibraryCommands +{ + Reject, + Accept +}; + +#endif diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index f25d2e2..808bebd 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -105,8 +105,8 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget() cmCustomCommandLines noCommandLines; cmTarget* tgt = mf->AddUtilityCommand( - CMAKE_CHECK_BUILD_SYSTEM_TARGET, cmMakefile::TargetOrigin::Generator, - false, no_working_directory, no_depends, noCommandLines); + CMAKE_CHECK_BUILD_SYSTEM_TARGET, cmCommandOrigin::Generator, false, + no_working_directory, no_depends, noCommandLines); cmGeneratorTarget* gt = new cmGeneratorTarget(tgt, lg); lg->AddGeneratorTarget(gt); @@ -152,10 +152,10 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget() std::vector<std::string> byproducts; byproducts.push_back(cm->GetGlobVerifyStamp()); - mf->AddCustomCommandToTarget(CMAKE_CHECK_BUILD_SYSTEM_TARGET, byproducts, - no_depends, verifyCommandLines, - cmTarget::PRE_BUILD, "Checking File Globs", - no_working_directory, false); + mf->AddCustomCommandToTarget( + CMAKE_CHECK_BUILD_SYSTEM_TARGET, byproducts, no_depends, + verifyCommandLines, cmCustomCommandType::PRE_BUILD, + "Checking File Globs", no_working_directory, false); // Ensure ZERO_CHECK always runs in Visual Studio using MSBuild, // otherwise the prebuild command will not be run. diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index 7a564ed..82219bd 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -193,7 +193,7 @@ void cmGlobalVisualStudioGenerator::AddExtraIDETargets() // Use no actual command lines so that the target itself is not // considered always out of date. cmTarget* allBuild = gen[0]->GetMakefile()->AddUtilityCommand( - "ALL_BUILD", cmMakefile::TargetOrigin::Generator, true, no_working_dir, + "ALL_BUILD", cmCommandOrigin::Generator, true, no_working_dir, no_depends, no_commands, false, "Build all projects"); cmGeneratorTarget* gt = new cmGeneratorTarget(allBuild, gen[0]); diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 2c3d3ad..e4dff78 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -501,9 +501,8 @@ void cmGlobalXCodeGenerator::AddExtraTargets( const char* no_working_directory = nullptr; std::vector<std::string> no_depends; cmTarget* allbuild = mf->AddUtilityCommand( - "ALL_BUILD", cmMakefile::TargetOrigin::Generator, true, - no_working_directory, no_depends, - cmMakeSingleCommandLine({ "echo", "Build all projects" })); + "ALL_BUILD", cmCommandOrigin::Generator, true, no_working_directory, + no_depends, cmMakeSingleCommandLine({ "echo", "Build all projects" })); cmGeneratorTarget* allBuildGt = new cmGeneratorTarget(allbuild, root); root->AddGeneratorTarget(allBuildGt); @@ -526,8 +525,8 @@ void cmGlobalXCodeGenerator::AddExtraTargets( this->ConvertToRelativeForMake(this->CurrentReRunCMakeMakefile); cmSystemTools::ReplaceString(file, "\\ ", " "); cmTarget* check = mf->AddUtilityCommand( - CMAKE_CHECK_BUILD_SYSTEM_TARGET, cmMakefile::TargetOrigin::Generator, - true, no_working_directory, no_depends, + CMAKE_CHECK_BUILD_SYSTEM_TARGET, cmCommandOrigin::Generator, true, + no_working_directory, no_depends, cmMakeSingleCommandLine({ "make", "-f", file })); cmGeneratorTarget* checkGt = new cmGeneratorTarget(check, root); @@ -558,8 +557,9 @@ void cmGlobalXCodeGenerator::AddExtraTargets( std::vector<std::string> no_byproducts; gen->GetMakefile()->AddCustomCommandToTarget( target->GetName(), no_byproducts, no_depends, commandLines, - cmTarget::POST_BUILD, "Depend check for xcode", dir.c_str(), true, - false, "", "", false, cmMakefile::AcceptObjectLibraryCommands); + cmCustomCommandType::POST_BUILD, "Depend check for xcode", + dir.c_str(), true, false, "", "", false, + cmObjectLibraryCommands::Accept); } if (!this->IsExcluded(target)) { diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 93e074d..7af3da5 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -7,6 +7,7 @@ #include "cmCustomCommand.h" #include "cmCustomCommandGenerator.h" #include "cmCustomCommandLines.h" +#include "cmCustomCommandTypes.h" #include "cmGeneratedFileStream.h" #include "cmGeneratorExpression.h" #include "cmGeneratorExpressionEvaluationFile.h" @@ -2356,7 +2357,7 @@ void cmLocalGenerator::AddPchDependencies(cmGeneratorTarget* target, if (this->GetGlobalGenerator()->IsMultiConfig()) { this->Makefile->AddCustomCommandToTarget( target->GetName(), outputs, no_deps, commandLines, - cmTarget::PRE_BUILD, no_message, no_current_dir); + cmCustomCommandType::PRE_BUILD, no_message, no_current_dir); } else { cmImplicitDependsList no_implicit_depends; cmSourceFile* copy_rule = this->Makefile->AddCustomCommandToOutput( diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 34081ed..e53851d 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -39,6 +39,7 @@ #include "cmStateDirectory.h" #include "cmStateTypes.h" #include "cmSystemTools.h" +#include "cmTarget.h" #include "cmTargetLinkLibraryType.h" #include "cmTest.h" #include "cmTestGenerator.h" // IWYU pragma: keep @@ -840,10 +841,10 @@ bool cmMakefile::ValidateCustomCommand( cmTarget* cmMakefile::AddCustomCommandToTarget( const std::string& target, const std::vector<std::string>& byproducts, const std::vector<std::string>& depends, - const cmCustomCommandLines& commandLines, cmTarget::CustomCommandType type, + const cmCustomCommandLines& commandLines, cmCustomCommandType type, const char* comment, const char* workingDir, bool escapeOldStyle, bool uses_terminal, const std::string& depfile, const std::string& job_pool, - bool command_expand_lists, ObjectLibraryCommands objLibraryCommands) + bool command_expand_lists, cmObjectLibraryCommands objLibCommands) { // Find the target to which to add the custom command. auto ti = this->Targets.find(target); @@ -884,7 +885,7 @@ cmTarget* cmMakefile::AddCustomCommandToTarget( } cmTarget* t = &ti->second; - if (objLibraryCommands == RejectObjectLibraryCommands && + if (objLibCommands == cmObjectLibraryCommands::Reject && t->GetType() == cmStateEnums::OBJECT_LIBRARY) { std::ostringstream e; e << "Target \"" << target @@ -920,7 +921,7 @@ cmTarget* cmMakefile::AddCustomCommandToTarget( void cmMakefile::CommitCustomCommandToTarget( cmTarget* target, const std::vector<std::string>& byproducts, const std::vector<std::string>& depends, - const cmCustomCommandLines& commandLines, cmTarget::CustomCommandType type, + const cmCustomCommandLines& commandLines, cmCustomCommandType type, const char* comment, const char* workingDir, bool escapeOldStyle, bool uses_terminal, const std::string& depfile, const std::string& job_pool, bool command_expand_lists) @@ -936,13 +937,13 @@ void cmMakefile::CommitCustomCommandToTarget( cc.SetDepfile(depfile); cc.SetJobPool(job_pool); switch (type) { - case cmTarget::PRE_BUILD: + case cmCustomCommandType::PRE_BUILD: target->AddPreBuildCommand(cc); break; - case cmTarget::PRE_LINK: + case cmCustomCommandType::PRE_LINK: target->AddPreLinkCommand(cc); break; - case cmTarget::POST_BUILD: + case cmCustomCommandType::POST_BUILD: target->AddPostBuildCommand(cc); break; } @@ -1157,9 +1158,9 @@ void cmMakefile::AddCustomCommandOldStyle( // same then it added a post-build rule to the target. Preserve // this behavior. std::vector<std::string> no_byproducts; - this->AddCustomCommandToTarget(target, no_byproducts, depends, - commandLines, cmTarget::POST_BUILD, comment, - nullptr); + this->AddCustomCommandToTarget( + target, no_byproducts, depends, commandLines, + cmCustomCommandType::POST_BUILD, comment, nullptr); return; } @@ -1248,7 +1249,7 @@ void cmMakefile::CommitAppendCustomCommandToOutput( } cmTarget* cmMakefile::AddUtilityCommand( - const std::string& utilityName, TargetOrigin origin, bool excludeFromAll, + const std::string& utilityName, cmCommandOrigin origin, bool excludeFromAll, const char* workingDirectory, const std::vector<std::string>& depends, const cmCustomCommandLines& commandLines, bool escapeOldStyle, const char* comment, bool uses_terminal, bool command_expand_lists, @@ -1262,7 +1263,7 @@ cmTarget* cmMakefile::AddUtilityCommand( } cmTarget* cmMakefile::AddUtilityCommand( - const std::string& utilityName, TargetOrigin origin, bool excludeFromAll, + const std::string& utilityName, cmCommandOrigin origin, bool excludeFromAll, const char* workingDirectory, const std::vector<std::string>& byproducts, const std::vector<std::string>& depends, const cmCustomCommandLines& commandLines, bool escapeOldStyle, @@ -1271,7 +1272,7 @@ cmTarget* cmMakefile::AddUtilityCommand( { // Create a target instance for this utility. cmTarget* target = this->AddNewTarget(cmStateEnums::UTILITY, utilityName); - target->SetIsGeneratorProvided(origin == TargetOrigin::Generator); + target->SetIsGeneratorProvided(origin == cmCommandOrigin::Generator); if (excludeFromAll || this->GetPropertyAsBool("EXCLUDE_FROM_ALL")) { target->SetProperty("EXCLUDE_FROM_ALL", "TRUE"); } diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index db37477..6bac47c 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -20,6 +20,7 @@ #include <cm/string_view> #include "cmAlgorithms.h" +#include "cmCustomCommandTypes.h" #include "cmListFileCache.h" #include "cmMessageType.h" #include "cmNewLineStyle.h" @@ -28,7 +29,10 @@ #include "cmStateSnapshot.h" #include "cmStateTypes.h" #include "cmStringAlgorithms.h" -#include "cmTarget.h" + +// IWYU does not see that 'std::unordered_map<std::string, cmTarget>' +// will not compile without the complete type. +#include "cmTarget.h" // IWYU pragma: keep #if !defined(CMAKE_BOOTSTRAP) # include "cmSourceGroup.h" @@ -164,22 +168,15 @@ public: */ void FinalPass(); - /** How to handle custom commands for object libraries */ - enum ObjectLibraryCommands - { - RejectObjectLibraryCommands, - AcceptObjectLibraryCommands - }; - /** Add a custom command to the build. */ cmTarget* AddCustomCommandToTarget( const std::string& target, const std::vector<std::string>& byproducts, const std::vector<std::string>& depends, - const cmCustomCommandLines& commandLines, cmTarget::CustomCommandType type, + const cmCustomCommandLines& commandLines, cmCustomCommandType type, const char* comment, const char* workingDir, bool escapeOldStyle = true, bool uses_terminal = false, const std::string& depfile = "", const std::string& job_pool = "", bool command_expand_lists = false, - ObjectLibraryCommands objLibraryCommands = RejectObjectLibraryCommands); + cmObjectLibraryCommands objLibCommands = cmObjectLibraryCommands::Reject); cmSourceFile* AddCustomCommandToOutput( const std::string& output, const std::vector<std::string>& depends, const std::string& main_dependency, @@ -232,26 +229,21 @@ public: const std::vector<std::string>& srcs, bool excludeFromAll = false); - /** Where the target originated from. */ - enum class TargetOrigin - { - Project, - Generator - }; - /** * Add a utility to the build. A utility target is a command that * is run every time the target is built. */ cmTarget* AddUtilityCommand( - const std::string& utilityName, TargetOrigin origin, bool excludeFromAll, - const char* workingDirectory, const std::vector<std::string>& depends, + const std::string& utilityName, cmCommandOrigin origin, + bool excludeFromAll, const char* workingDirectory, + const std::vector<std::string>& depends, const cmCustomCommandLines& commandLines, bool escapeOldStyle = true, const char* comment = nullptr, bool uses_terminal = false, bool command_expand_lists = false, const std::string& job_pool = ""); cmTarget* AddUtilityCommand( - const std::string& utilityName, TargetOrigin origin, bool excludeFromAll, - const char* workingDirectory, const std::vector<std::string>& byproducts, + const std::string& utilityName, cmCommandOrigin origin, + bool excludeFromAll, const char* workingDirectory, + const std::vector<std::string>& byproducts, const std::vector<std::string>& depends, const cmCustomCommandLines& commandLines, bool escapeOldStyle = true, const char* comment = nullptr, bool uses_terminal = false, @@ -1064,7 +1056,7 @@ private: void CommitCustomCommandToTarget( cmTarget* target, const std::vector<std::string>& byproducts, const std::vector<std::string>& depends, - const cmCustomCommandLines& commandLines, cmTarget::CustomCommandType type, + const cmCustomCommandLines& commandLines, cmCustomCommandType type, const char* comment, const char* workingDir, bool escapeOldStyle, bool uses_terminal, const std::string& depfile, const std::string& job_pool, bool command_expand_lists); diff --git a/Source/cmQtAutoGenGlobalInitializer.cxx b/Source/cmQtAutoGenGlobalInitializer.cxx index 576a034..751ad50 100644 --- a/Source/cmQtAutoGenGlobalInitializer.cxx +++ b/Source/cmQtAutoGenGlobalInitializer.cxx @@ -3,6 +3,7 @@ #include "cmQtAutoGenGlobalInitializer.h" #include "cmCustomCommandLines.h" +#include "cmCustomCommandTypes.h" #include "cmDuration.h" #include "cmGeneratorTarget.h" #include "cmLocalGenerator.h" @@ -154,7 +155,7 @@ void cmQtAutoGenGlobalInitializer::GetOrCreateGlobalTarget( // Create utility target cmTarget* target = makefile->AddUtilityCommand( - name, cmMakefile::TargetOrigin::Generator, true, + name, cmCommandOrigin::Generator, true, makefile->GetHomeOutputDirectory().c_str() /*work dir*/, std::vector<std::string>() /*output*/, std::vector<std::string>() /*depends*/, cmCustomCommandLines(), false, diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index 0d56fe1..9dbd612 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -8,6 +8,7 @@ #include "cmAlgorithms.h" #include "cmCustomCommand.h" #include "cmCustomCommandLines.h" +#include "cmCustomCommandTypes.h" #include "cmGeneratedFileStream.h" #include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" @@ -1117,7 +1118,7 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() // Create autogen target cmTarget* autogenTarget = this->Makefile->AddUtilityCommand( - this->AutogenTarget.Name, cmMakefile::TargetOrigin::Generator, true, + this->AutogenTarget.Name, cmCommandOrigin::Generator, true, this->Dir.Work.c_str(), /*byproducts=*/autogenProvides, std::vector<std::string>(this->AutogenTarget.DependFiles.begin(), this->AutogenTarget.DependFiles.end()), @@ -1199,9 +1200,8 @@ bool cmQtAutoGenInitializer::InitRccTargets() } cmTarget* autoRccTarget = this->Makefile->AddUtilityCommand( - ccName, cmMakefile::TargetOrigin::Generator, true, - this->Dir.Work.c_str(), ccOutput, ccDepends, commandLines, false, - ccComment.c_str()); + ccName, cmCommandOrigin::Generator, true, this->Dir.Work.c_str(), + ccOutput, ccDepends, commandLines, false, ccComment.c_str()); // Create autogen generator target this->LocalGen->AddGeneratorTarget( diff --git a/Source/cmTarget.h b/Source/cmTarget.h index f4726d3..1b4f23a 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -43,13 +43,6 @@ public: VisibilityImportedGlobally }; - enum CustomCommandType - { - PRE_BUILD, - PRE_LINK, - POST_BUILD - }; - cmTarget(std::string const& name, cmStateEnums::TargetType type, Visibility vis, cmMakefile* mf); ----------------------------------------------------------------------- Summary of changes: Modules/CMakeFindBinUtils.cmake | 70 ++++++- Modules/Compiler/GNU-FindBinUtils.cmake | 26 ++- Source/CMakeLists.txt | 1 + Source/cmAddCustomCommandCommand.cxx | 10 +- Source/cmAddCustomTargetCommand.cxx | 3 +- Source/cmCPluginAPI.cxx | 14 +- Source/cmCommands.cxx | 27 +-- Source/cmCustomCommandTypes.h | 39 ++++ Source/cmGlobalGenerator.cxx | 2 +- Source/cmGlobalVisualStudio8Generator.cxx | 20 +- Source/cmGlobalVisualStudioGenerator.cxx | 7 +- Source/cmGlobalXCodeGenerator.cxx | 23 ++- Source/cmLocalGenerator.cxx | 3 +- Source/cmMakefile.cxx | 298 ++++++++++++++------------- Source/cmMakefile.h | 85 ++++---- Source/cmQtAutoGenGlobalInitializer.cxx | 3 +- Source/cmQtAutoGenInitializer.cxx | 10 +- Source/cmTarget.cxx | 15 ++ Source/cmTarget.h | 10 +- Source/cmTargetCompileDefinitionsCommand.cxx | 70 ++++--- Source/cmTargetCompileDefinitionsCommand.h | 34 +-- Source/cmTargetCompileFeaturesCommand.cxx | 65 +++--- Source/cmTargetCompileFeaturesCommand.h | 26 +-- Source/cmTargetCompileOptionsCommand.cxx | 56 ++--- Source/cmTargetCompileOptionsCommand.h | 34 +-- Source/cmTargetIncludeDirectoriesCommand.cxx | 57 +++-- Source/cmTargetIncludeDirectoriesCommand.h | 38 +--- Source/cmTargetLinkDirectoriesCommand.cxx | 53 +++-- Source/cmTargetLinkDirectoriesCommand.h | 34 +-- Source/cmTargetLinkOptionsCommand.cxx | 55 +++-- Source/cmTargetLinkOptionsCommand.h | 34 +-- Source/cmTargetPrecompileHeadersCommand.cxx | 98 +++++---- Source/cmTargetPrecompileHeadersCommand.h | 38 +--- Source/cmTargetPropCommandBase.cxx | 12 ++ Source/cmTargetPropCommandBase.h | 14 +- Source/cmTargetSourcesCommand.cxx | 81 +++++--- Source/cmTargetSourcesCommand.h | 44 +--- Tests/FortranModules/Library/a.f90 | 3 + Tests/FortranModules/Library/b.f90 | 3 + Tests/FortranModules/Subdir/subdir.f90 | 3 + 40 files changed, 765 insertions(+), 753 deletions(-) create mode 100644 Source/cmCustomCommandTypes.h hooks/post-receive -- CMake _______________________________________________ Cmake-commits mailing list Cmake-commits@cmake.org https://cmake.org/mailman/listinfo/cmake-commits