diff options
| author | ruki <[email protected]> | 2022-08-14 21:43:38 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-08-14 21:43:38 +0800 |
| commit | 44b5b95dd66578f3ea8c14c96bb36dadb5938a8a (patch) | |
| tree | c00cc7d4735877a0c9a9b36d6e8540d4ed4f4cb1 | |
| parent | dc58599ef5524ab5bd54126b992a3b2d19be0d30 (diff) | |
optimizate cmakelist
| -rw-r--r-- | tests/projects/c++/modules/dependence/CMakeLists.txt | 43 | ||||
| -rw-r--r-- | xmake/plugins/project/cmake/cmakelists.lua | 39 |
2 files changed, 21 insertions, 61 deletions
diff --git a/tests/projects/c++/modules/dependence/CMakeLists.txt b/tests/projects/c++/modules/dependence/CMakeLists.txt index fe09acca6..4d7715c93 100644 --- a/tests/projects/c++/modules/dependence/CMakeLists.txt +++ b/tests/projects/c++/modules/dependence/CMakeLists.txt @@ -11,54 +11,19 @@ project(dependence LANGUAGES CXX C) add_executable(dependence "") set_target_properties(dependence PROPERTIES OUTPUT_NAME "dependence") set_target_properties(dependence PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/linux/x86_64/release") -add_custom_command(OUTPUT output_dependence_932361E8 +add_custom_command(OUTPUT output_dependence_957D597F COMMAND echo ${color.build.progress}[ 0%]:${clear} ${color.build.object}generating.cxx.module.bmi mod - VERBATIM -) -add_custom_target(target_dependence_932361E8 - DEPENDS output_dependence_932361E8 -) -add_dependencies(dependence target_dependence_932361E8) -add_custom_command(OUTPUT output_dependence_981BF74C COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_SOURCE_DIR}/build/.objs/dependence/linux/x86_64/release/src - VERBATIM -) -add_custom_target(target_dependence_981BF74C - DEPENDS output_dependence_981BF74C -) -add_dependencies(dependence target_dependence_981BF74C) -add_custom_command(OUTPUT output_dependence_812F1CA0 COMMAND /usr/bin/gcc -m64 -std=c++20 -fmodules-ts -fmodule-mapper=${CMAKE_SOURCE_DIR}/build/mapper.txt -x c++ -o ${CMAKE_SOURCE_DIR}/build/.objs/dependence/linux/x86_64/release/src/mod.mpp.o -c ${CMAKE_SOURCE_DIR}/src/mod.mpp - VERBATIM -) -add_custom_target(target_dependence_812F1CA0 - DEPENDS output_dependence_812F1CA0 -) -add_dependencies(dependence target_dependence_812F1CA0) -add_custom_command(OUTPUT output_dependence_A56A2AC8 COMMAND echo ${color.build.progress}[ 0%]:${clear} ${color.build.object}generating.cxx.module.bmi hello - VERBATIM -) -add_custom_target(target_dependence_A56A2AC8 - DEPENDS output_dependence_A56A2AC8 -) -add_dependencies(dependence target_dependence_A56A2AC8) -add_custom_command(OUTPUT output_dependence_E41992DB COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_SOURCE_DIR}/build/.objs/dependence/linux/x86_64/release/src - VERBATIM -) -add_custom_target(target_dependence_E41992DB - DEPENDS output_dependence_E41992DB -) -add_dependencies(dependence target_dependence_E41992DB) -add_custom_command(OUTPUT output_dependence_EAE69E5A COMMAND /usr/bin/gcc -m64 -std=c++20 -fmodules-ts -fmodule-mapper=${CMAKE_SOURCE_DIR}/build/mapper.txt -x c++ -o ${CMAKE_SOURCE_DIR}/build/.objs/dependence/linux/x86_64/release/src/hello.mpp.o -c ${CMAKE_SOURCE_DIR}/src/hello.mpp VERBATIM ) -add_custom_target(target_dependence_EAE69E5A - DEPENDS output_dependence_EAE69E5A +add_custom_target(target_dependence_957D597F + DEPENDS output_dependence_957D597F ) -add_dependencies(dependence target_dependence_EAE69E5A) +add_dependencies(dependence target_dependence_957D597F) target_compile_options(dependence PRIVATE $<$<COMPILE_LANGUAGE:C>:-m64> $<$<COMPILE_LANGUAGE:CXX>:-m64> diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua index 9565bcb40..153e3c4ad 100644 --- a/xmake/plugins/project/cmake/cmakelists.lua +++ b/xmake/plugins/project/cmake/cmakelists.lua @@ -826,8 +826,8 @@ function _get_command_string(cmd, outputdir) end end --- add custom command -function _add_target_custom_command(cmakelists, target, command, suffix) +-- add target custom commands for batchcmds +function _add_target_custom_commands_for_batchcmds(cmakelists, target, outputdir, suffix, batchcmds) if suffix == "before" then -- ADD_CUSTOM_COMMAND and PRE_BUILD did not work as I expected, -- so we need use add_dependencies and fake target to support it. @@ -836,7 +836,12 @@ function _add_target_custom_command(cmakelists, target, command, suffix) -- local key = target:name() .. "_" .. hash.uuid():split("-", {plain = true})[1] cmakelists:print("add_custom_command(OUTPUT output_%s", key) - cmakelists:print(" COMMAND %s", command) + for _, cmd in ipairs(batchcmds:cmds()) do + local command = _get_command_string(cmd, outputdir) + if command then + cmakelists:print(" COMMAND %s", command) + end + end cmakelists:print(" VERBATIM") cmakelists:print(")") cmakelists:print("add_custom_target(target_%s", key) @@ -848,7 +853,12 @@ function _add_target_custom_command(cmakelists, target, command, suffix) if suffix == "after" then cmakelists:print(" POST_BUILD") end - cmakelists:print(" COMMAND %s", command) + for _, cmd in ipairs(batchcmds:cmds()) do + local command = _get_command_string(cmd, outputdir) + if command then + cmakelists:print(" COMMAND %s", command) + end + end cmakelists:print(" VERBATIM") cmakelists:print(")") end @@ -863,12 +873,7 @@ function _add_target_custom_commands_for_target(cmakelists, target, outputdir, s local batchcmds_ = batchcmds.new({target = target}) script(target, batchcmds_, {}) if not batchcmds_:empty() then - for _, cmd in ipairs(batchcmds_:cmds()) do - local command = _get_command_string(cmd, outputdir) - if command then - _add_target_custom_command(cmakelists, target, command, suffix) - end - end + _add_target_custom_commands_for_batchcmds(cmakelists, target, outputdir, suffix, batchcmds_) end end end @@ -888,12 +893,7 @@ function _add_target_custom_commands_for_objectrules(cmakelists, target, sourceb local batchcmds_ = batchcmds.new({target = target}) script(target, batchcmds_, sourcebatch, {}) if not batchcmds_:empty() then - for _, cmd in ipairs(batchcmds_:cmds()) do - local command = _get_command_string(cmd, outputdir) - if command then - _add_target_custom_command(cmakelists, target, command, suffix) - end - end + _add_target_custom_commands_for_batchcmds(cmakelists, target, outputdir, suffix, batchcmds_) end end @@ -907,12 +907,7 @@ function _add_target_custom_commands_for_objectrules(cmakelists, target, sourceb local batchcmds_ = batchcmds.new({target = target}) script(target, batchcmds_, sourcefile, {}) if not batchcmds_:empty() then - for _, cmd in ipairs(batchcmds_:cmds()) do - local command = _get_command_string(cmd, outputdir) - if command then - _add_target_custom_command(cmakelists, target, command, suffix) - end - end + _add_target_custom_commands_for_batchcmds(cmakelists, target, outputdir, suffix, batchcmds_) end end end |
