diff options
| author | ruki <[email protected]> | 2022-08-16 12:33:47 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-08-16 12:33:47 +0800 |
| commit | 81aca6fbe9149b377cdd88e8ee4b8f045d5a46da (patch) | |
| tree | 0f138f960ab9fd95265ecbffca7c6ae27d65f4a3 /xmake/plugins | |
| parent | d46b16f8c40493bfc78764931bf7c3209442696b (diff) | |
| parent | d9f82e1bba29adc8b11dc1f7b3887717f03137d6 (diff) | |
Merge pull request #2641 from xmake-io/cxxmodules
Improve C++20 modules support
Diffstat (limited to 'xmake/plugins')
| -rw-r--r-- | xmake/plugins/project/clang/compile_commands.lua | 31 | ||||
| -rw-r--r-- | xmake/plugins/project/cmake/cmakelists.lua | 280 | ||||
| -rw-r--r-- | xmake/plugins/project/make/makefile.lua | 14 | ||||
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x.lua | 12 | ||||
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua | 21 | ||||
| -rw-r--r-- | xmake/plugins/project/vsxmake/getinfo.lua | 1 |
6 files changed, 249 insertions, 110 deletions
diff --git a/xmake/plugins/project/clang/compile_commands.lua b/xmake/plugins/project/clang/compile_commands.lua index ce2dfcd30..3145b71b6 100644 --- a/xmake/plugins/project/clang/compile_commands.lua +++ b/xmake/plugins/project/clang/compile_commands.lua @@ -113,6 +113,15 @@ function _make_arguments(jsonfile, arguments, sourcefile) table.insert(arguments_escape, _escape_path(arg)) end + -- remove repeat + -- this is because some rules will repeatedly bind the same sourcekind, e.g. `rule("c++.build.modules.builder")` + local key = hash.uuid(os.args(arguments_escape) .. sourcefile) + local map = _g.map or {} + _g.map = map + if map[key] then + return + end + -- make body jsonfile:printf( [[%s{ @@ -123,6 +132,26 @@ function _make_arguments(jsonfile, arguments, sourcefile) -- clear first line marks _g.firstline = false + map[key] = true +end + +-- make commands for target +function _make_commands_for_targetrules(jsonfile, target, suffix) + for _, ruleinst in ipairs(target:orderules()) do + local scriptname = "buildcmd" .. (suffix and ("_" .. suffix) or "") + local script = ruleinst:script(scriptname) + if script then + local batchcmds_ = batchcmds.new({target = target}) + script(target, batchcmds_, {}) + if not batchcmds_:empty() then + for _, cmd in ipairs(batchcmds_:cmds()) do + if cmd.program then + _make_arguments(jsonfile, table.join(cmd.program, cmd.argv)) + end + end + end + end + end end -- make commands for object rules @@ -183,11 +212,13 @@ end -- make objects function _make_objects(jsonfile, target, sourcebatch) + _make_commands_for_targetrules(jsonfile, target, "before") _make_commands_for_objectrules(jsonfile, target, sourcebatch, "before") if not _make_commands_for_objects(jsonfile, target, sourcebatch) then _make_commands_for_objectrules(jsonfile, target, sourcebatch) end _make_commands_for_objectrules(jsonfile, target, sourcebatch, "after") + _make_commands_for_targetrules(jsonfile, target, "after") end -- make target diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua index 09feb78e3..5154956e6 100644 --- a/xmake/plugins/project/cmake/cmakelists.lua +++ b/xmake/plugins/project/cmake/cmakelists.lua @@ -19,7 +19,9 @@ -- -- imports +import("core.base.colors") import("core.project.project") +import("core.project.config") import("core.tool.compiler") import("core.base.semver") import("core.base.hashset") @@ -109,6 +111,67 @@ function _get_configs_from_target(target, name) return table.unique(values) end +-- this sourcebatch is built? +function _sourcebatch_is_built(sourcebatch) + -- we can only use rulename to filter them because sourcekind may be bound to multiple rules + local rulename = sourcebatch.rulename + if rulename == "c.build" or rulename == "c++.build" or rulename == "asm.build" or rulename == "cuda.build" then + return true + end +end + +-- translate flag +function _translate_flag(flag, outputdir) + if flag then + if path.instance_of(flag) then + flag = flag:clone():set(_get_unix_path_relative_to_cmake(flag:rawstr(), outputdir)):str() + elseif path.is_absolute(flag) then + flag = _get_unix_path_relative_to_cmake(flag, outputdir) + elseif flag:startswith("-fmodule-file=") then + flag = "-fmodule-file=" .. _get_unix_path_relative_to_cmake(flag:sub(15), outputdir) + elseif flag:startswith("-fmodule-mapper=") then + flag = "-fmodule-mapper=" .. _get_unix_path_relative_to_cmake(flag:sub(17), outputdir) + elseif flag:match("(.+)=(.+)") then + local k, v = flag:match("(.+)=(.+)") + if v and v:endswith(".ifc") then -- e.g. hello=xxx/hello.ifc + flag = k .. "=" .. _get_unix_path_relative_to_cmake(v, outputdir) + end + end + end + return flag +end + +-- translate flags +function _translate_flags(flags, outputdir) + if not flags then + return + end + local result = {} + for _, flag in ipairs(flags) do + if type(flag) == "table" and not path.instance_of(flag) then + for _, v in ipairs(flag) do + table.insert(result, _translate_flag(v, outputdir)) + end + else + table.insert(result, _translate_flag(flag, outputdir)) + end + end + return result +end + +-- get flags from fileconfig +function _get_flags_from_fileconfig(fileconfig, outputdir, name) + local flags = {} + table.join2(flags, fileconfig[name]) + if fileconfig.force then + table.join2(flags, fileconfig.force[name]) + end + flags = _translate_flags(flags, outputdir) + if #flags > 0 then + return flags + end +end + -- add project info function _add_project(cmakelists, languages, outputdir) @@ -163,8 +226,34 @@ function _add_target_phony(cmakelists, target) cmakelists:print("") end +-- set compiler +function _set_target_compiler(cmakelists, target) + -- use custom toolchain? + if config.get("toolchain") or target:get("toolchains") then + local cc = target:tool("cc") + if cc then + cc = cc:gsub("\\", "/") + cmakelists:print("set(CMAKE_C_COMPILER \"%s\")", cc) + end + local cxx, cxx_name = target:tool("cxx") + if cxx then + if cxx_name == "clang" or cxx_name == "gcc" then + local dir = path.directory(cxx) + local name = path.filename(cxx) + name = name:gsub("clang$", "clang++") + name = name:gsub("clang%-", "clang++-") + name = name:gsub("gcc$", "g++") + name = name:gsub("gcc%-", "g++-") + cxx = path.join(dir, name):gsub("\\", "/") + end + cmakelists:print("set(CMAKE_CXX_COMPILER \"%s\")", cxx) + end + end +end + -- add target: binary function _add_target_binary(cmakelists, target, outputdir) + _set_target_compiler(cmakelists, target) cmakelists:print("add_executable(%s \"\")", target:name()) cmakelists:print("set_target_properties(%s PROPERTIES OUTPUT_NAME \"%s\")", target:name(), target:basename()) cmakelists:print("set_target_properties(%s PROPERTIES RUNTIME_OUTPUT_DIRECTORY \"%s\")", target:name(), _get_unix_path_relative_to_cmake(target:targetdir(), outputdir)) @@ -172,6 +261,7 @@ end -- add target: static function _add_target_static(cmakelists, target, outputdir) + _set_target_compiler(cmakelists, target) cmakelists:print("add_library(%s STATIC \"\")", target:name()) cmakelists:print("set_target_properties(%s PROPERTIES OUTPUT_NAME \"%s\")", target:name(), target:basename()) cmakelists:print("set_target_properties(%s PROPERTIES ARCHIVE_OUTPUT_DIRECTORY \"%s\")", target:name(), _get_unix_path_relative_to_cmake(target:targetdir(), outputdir)) @@ -179,6 +269,7 @@ end -- add target: shared function _add_target_shared(cmakelists, target, outputdir) + _set_target_compiler(cmakelists, target) cmakelists:print("add_library(%s SHARED \"\")", target:name()) cmakelists:print("set_target_properties(%s PROPERTIES OUTPUT_NAME \"%s\")", target:name(), target:basename()) if target:is_plat("windows") then @@ -212,13 +303,12 @@ function _add_target_sources(cmakelists, target, outputdir) local has_cuda = false cmakelists:print("target_sources(%s PRIVATE", target:name()) for _, sourcebatch in table.orderpairs(target:sourcebatches()) do - local sourcekind = sourcebatch.sourcekind - if sourcekind == "cc" or sourcekind == "cxx" or sourcekind == "as" or sourcekind == "cu" then + if _sourcebatch_is_built(sourcebatch) then for _, sourcefile in ipairs(sourcebatch.sourcefiles) do cmakelists:print(" " .. _get_unix_path(sourcefile, outputdir)) end end - if sourcekind == "cu" then + if sourcebatch.sourcekind == "cu" then has_cuda = true end end @@ -390,76 +480,66 @@ function _add_target_compile_definitions(cmakelists, target) end end +-- add target source files flags +function _add_target_sourcefiles_flags(cmakelists, target, sourcefile, name, outputdir) + local fileconfig = target:fileconfig(sourcefile) + if fileconfig then + local flags = _get_flags_from_fileconfig(fileconfig, outputdir, name) + if flags and #flags > 0 then + cmakelists:print("set_source_files_properties(" + .. _get_unix_path_relative_to_cmake(sourcefile, outputdir) + .. " PROPERTIES COMPILE_OPTIONS") + local flagstrs = {} + for _, flag in ipairs(flags) do + if name == "cxxflags" then + table.insert(flagstrs, "$<$<COMPILE_LANGUAGE:CXX>:" .. flag .. ">") + elseif name == "cflags" then + table.insert(flagstrs, "$<$<COMPILE_LANGUAGE:C>:" .. flag .. ">") + elseif name == "cxflags" then + table.insert(flagstrs, "$<$<COMPILE_LANGUAGE:C>:" .. flag .. ">") + table.insert(flagstrs, "$<$<COMPILE_LANGUAGE:CXX>:" .. flag .. ">") + elseif name == "cuflags" then + table.insert(flagstrs, "$<$<COMPILE_LANGUAGE:CUDA>:" .. flag .. ">") + end + end + cmakelists:print(" \"%s\"", table.concat(flagstrs, ";")) + cmakelists:print(")") + end + end +end + -- add target compile options -function _add_target_compile_options(cmakelists, target) +function _add_target_compile_options(cmakelists, target, outputdir) local cflags = _get_configs_from_target(target, "cflags") local cxflags = _get_configs_from_target(target, "cxflags") local cxxflags = _get_configs_from_target(target, "cxxflags") local cuflags = _get_configs_from_target(target, "cuflags") if #cflags > 0 or #cxflags > 0 or #cxxflags > 0 or #cuflags > 0 then cmakelists:print("target_compile_options(%s PRIVATE", target:name()) - for _, flag in ipairs(cflags) do + for _, flag in ipairs(_translate_flags(cflags, outputdir)) do cmakelists:print(" $<$<COMPILE_LANGUAGE:C>:" .. flag .. ">") end - for _, flag in ipairs(cxflags) do + for _, flag in ipairs(_translate_flags(cxflags, outputdir)) do cmakelists:print(" $<$<COMPILE_LANGUAGE:C>:" .. flag .. ">") cmakelists:print(" $<$<COMPILE_LANGUAGE:CXX>:" .. flag .. ">") end - for _, flag in ipairs(cxxflags) do + for _, flag in ipairs(_translate_flags(cxxflags, outputdir)) do cmakelists:print(" $<$<COMPILE_LANGUAGE:CXX>:" .. flag .. ">") end - for _, flag in ipairs(cuflags) do + for _, flag in ipairs(_translate_flags(cuflags, outputdir)) do cmakelists:print(" $<$<COMPILE_LANGUAGE:CUDA>:" .. flag .. ">") end cmakelists:print(")") end -end --- add target language standards -function _add_target_language_standards(cmakelists, target) - local cstds = - { - c89 = "90" - , gnu89 = "90" -- TODO add cflags -std=gnu90 if supported - , c99 = "99" - , gnu99 = "99" -- TODO - , c11 = "11" - , gnu11 = "11" -- TODO - } - local cxxstds = - { - cxx98 = "98" - , gnuxx98 = "98" -- TODO - , cxx11 = "11" - , gnuxx11 = "11" - , cxx14 = "14" - , gnuxx14 = "14" - , cxx17 = "17" - , gnuxx17 = "17" - , cxx1z = "17" - , gnuxx1z = "17" - , cxx2a = "20" - , gnuxx2a = "20" - , cxxlatest = "latest" - } - for _, lang in ipairs(target:get("languages")) do - local cstd = cstds[lang] - if cstd then - cmakelists:print("set_property(TARGET %s PROPERTY C_STANDARD %s)", target:name(), cstd) - if cstd == "99" or cstd == "11" then - cmakelists:print("if(MSVC)") - cmakelists:print(" target_compile_options(%s PRIVATE $<$<COMPILE_LANGUAGE:C>:-TP>)", target:name()) - cmakelists:print("endif()") - end - end - local cxxstd = cxxstds[lang] - if cxxstd then - if cxxstd == "latest" then - cmakelists:print("if (MSVC)") - cmakelists:print(" target_compile_options(%s PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/std:c++latest>)", target:name()) - cmakelists:print("endif()") - else - cmakelists:print("set_property(TARGET %s PROPERTY CXX_STANDARD %s)", target:name(), cxxstd) + -- add cflags/cxxflags for the specific source files + for _, sourcebatch in table.orderpairs(target:sourcebatches()) do + if _sourcebatch_is_built(sourcebatch) then + for _, sourcefile in ipairs(sourcebatch.sourcefiles) do + _add_target_sourcefiles_flags(cmakelists, target, sourcefile, "cxxflags", outputdir) + _add_target_sourcefiles_flags(cmakelists, target, sourcefile, "cflags", outputdir) + _add_target_sourcefiles_flags(cmakelists, target, sourcefile, "cxflags", outputdir) + _add_target_sourcefiles_flags(cmakelists, target, sourcefile, "cuflags", outputdir) end end end @@ -516,8 +596,14 @@ function _add_target_languages(cmakelists, target) local languages = target:get("languages") if languages then for _, lang in ipairs(languages) do + local has_ext = false + if lang:startswith("gnu") then + lang = lang:sub(4) + has_ext = true + end local feature = features[lang] or (features[lang:replace("++", "xx")]) if feature then + cmakelists:print("set_target_properties(%s PROPERTIES CXX_EXTENSIONS %s)", target:name(), has_ext and "ON" or "OFF") cmakelists:print("target_compile_features(%s PRIVATE %s)", target:name(), feature) end end @@ -615,7 +701,7 @@ function _add_target_vs_runtime(cmakelists, target) end -- add target link libraries -function _add_target_link_libraries(cmakelists, target) +function _add_target_link_libraries(cmakelists, target, outputdir) -- add links local links = _get_configs_from_target(target, "links") @@ -634,6 +720,25 @@ function _add_target_link_libraries(cmakelists, target) end cmakelists:print(")") end + + -- add other object files, maybe from custom rules + local objectfiles_set = hashset.new() + for _, sourcebatch in table.orderpairs(target:sourcebatches()) do + if _sourcebatch_is_built(sourcebatch) then + for _, objectfile in ipairs(sourcebatch.objectfiles) do + objectfiles_set:insert(objectfile) + end + end + end + if #target:objectfiles() > objectfiles_set:size() then + cmakelists:print("target_link_libraries(%s PRIVATE", target:name()) + for _, objectfile in ipairs(target:objectfiles()) do + if not objectfiles_set:has(objectfile) then + cmakelists:print(" " .. _get_unix_path_relative_to_cmake(objectfile, outputdir)) + end + end + cmakelists:print(")") + end end -- add target link directories @@ -699,12 +804,7 @@ function _get_command_string(cmd, outputdir) -- @see https://github.com/xmake-io/xmake/discussions/2156 local argv = {} for _, v in ipairs(cmd.argv) do - if path.instance_of(v) then - v = v:clone():set(_get_unix_path_relative_to_cmake(v:rawstr(), outputdir)):str() - elseif path.is_absolute(v) then - v = _get_unix_path_relative_to_cmake(v, outputdir) - end - table.insert(argv, v) + table.insert(argv, _translate_flag(v, outputdir)) end local command = _get_unix_path_relative_to_cmake(cmd.program) .. " " .. os.args(argv) if opt and opt.curdir then @@ -729,12 +829,12 @@ function _get_command_string(cmd, outputdir) elseif kind == "mkdir" then return string.format("${CMAKE_COMMAND} -E make_directory %s", _get_unix_path_relative_to_cmake(cmd.dir, outputdir)) elseif kind == "show" then - return string.format("echo %s", cmd.showtext) + return string.format("echo %s", colors.ignore(cmd.showtext)) 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. @@ -743,7 +843,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) @@ -755,7 +860,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 @@ -770,12 +880,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 @@ -795,12 +900,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 @@ -814,12 +914,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 @@ -830,8 +925,7 @@ end function _add_target_custom_commands(cmakelists, target, outputdir) _add_target_custom_commands_for_target(cmakelists, target, outputdir, "before") for _, sourcebatch in table.orderpairs(target:sourcebatches()) do - local sourcekind = sourcebatch.sourcekind - if sourcekind ~= "cc" and sourcekind ~= "cxx" and sourcekind ~= "as" then + if not _sourcebatch_is_built(sourcebatch) then _add_target_custom_commands_for_objectrules(cmakelists, target, sourcebatch, outputdir, "before") _add_target_custom_commands_for_objectrules(cmakelists, target, sourcebatch, outputdir) _add_target_custom_commands_for_objectrules(cmakelists, target, sourcebatch, outputdir, "after") @@ -885,6 +979,10 @@ function _add_target(cmakelists, target, outputdir) -- add target dependencies _add_target_dependencies(cmakelists, target) + -- add target custom commands + -- we need call it first for running all rules, these rules will change some flags, e.g. c++modules + _add_target_custom_commands(cmakelists, target, outputdir) + -- add target precompilied header _add_target_precompiled_header(cmakelists, target, outputdir) @@ -900,11 +998,8 @@ function _add_target(cmakelists, target, outputdir) -- add target compile definitions _add_target_compile_definitions(cmakelists, target) - -- add target language standards - _add_target_language_standards(cmakelists, target) - -- add target compile options - _add_target_compile_options(cmakelists, target) + _add_target_compile_options(cmakelists, target, outputdir) -- add target warnings _add_target_warnings(cmakelists, target) @@ -922,7 +1017,7 @@ function _add_target(cmakelists, target, outputdir) _add_target_vs_runtime(cmakelists, target) -- add target link libraries - _add_target_link_libraries(cmakelists, target) + _add_target_link_libraries(cmakelists, target, outputdir) -- add target link directories _add_target_link_directories(cmakelists, target, outputdir) @@ -930,9 +1025,6 @@ function _add_target(cmakelists, target, outputdir) -- add target link options _add_target_link_options(cmakelists, target) - -- add target custom commands - _add_target_custom_commands(cmakelists, target, outputdir) - -- add target sources _add_target_sources(cmakelists, target, outputdir) diff --git a/xmake/plugins/project/make/makefile.lua b/xmake/plugins/project/make/makefile.lua index 7b0ec8f60..87c3b6f55 100644 --- a/xmake/plugins/project/make/makefile.lua +++ b/xmake/plugins/project/make/makefile.lua @@ -192,10 +192,18 @@ end -- make objects function _make_objects(makefile, target, sourcekind, sourcebatch, sourceflags) - - -- make them + local handled_objects = target:data("makefile.handled_objects") + if not handled_objects then + handled_objects = {} + target:data_set("makefile.handled_objects", handled_objects) + end for index, objectfile in ipairs(sourcebatch.objectfiles) do - _make_object(makefile, target, sourcebatch.sourcefiles[index], objectfile, sourceflags) + -- remove repeat + -- this is because some rules will repeatedly bind the same sourcekind, e.g. `rule("c++.build.modules.builder")` + if not handled_objects[objectfile] then + _make_object(makefile, target, sourcebatch.sourcefiles[index], objectfile, sourceflags) + handled_objects[objectfile] = true + end end end diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index ce07549c0..5d0e730d9 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -20,6 +20,7 @@ -- imports import("core.base.option") +import("core.base.colors") import("core.project.rule") import("core.project.config") import("core.project.project") @@ -109,7 +110,7 @@ function _get_command_string(cmd, vcxprojdir) local dir = _translate_path(cmd.dir, vcxprojdir) return string.format("if not exist \"%s\" mkdir \"%s\"", dir, dir) elseif kind == "show" then - return string.format("echo %s", cmd.showtext) + return string.format("echo %s", colors.ignore(cmd.showtext)) end end @@ -213,8 +214,9 @@ function _make_custom_commands(target, vcxprojdir) _make_custom_commands_for_target(commands, target, vcxprojdir, "before") _make_custom_commands_for_target(commands, target, vcxprojdir) for _, sourcebatch in pairs(target:sourcebatches()) do + local rulename = sourcebatch.rulename local sourcekind = sourcebatch.sourcekind - if sourcekind ~= "cc" and sourcekind ~= "cxx" and sourcekind ~= "as" then + if rulename ~= "c.build" and rulename ~= "c++.build" and rulename ~= "asm.build" and rulename ~= "cuda.build" and sourcekind ~= "mrc" then _make_custom_commands_for_objectrules(commands, target, sourcebatch, vcxprojdir, "before") _make_custom_commands_for_objectrules(commands, target, sourcebatch, vcxprojdir, nil) _make_custom_commands_for_objectrules(commands, target, sourcebatch, vcxprojdir, "after") @@ -281,10 +283,11 @@ function _make_targetinfo(mode, arch, target, vcxprojdir) targetinfo.compargvs = {} for _, sourcebatch in pairs(target:sourcebatches()) do local sourcekind = sourcebatch.sourcekind + local rulename = sourcebatch.rulename if sourcekind then for idx, sourcefile in ipairs(sourcebatch.sourcefiles) do - local compflags = compiler.compflags(sourcefile, {target = target}) - if not firstcompflags and (sourcekind == "cc" or sourcekind == "cxx" or sourcekind == "cu") then + local compflags = compiler.compflags(sourcefile, {target = target, sourcekind = sourcekind}) + if not firstcompflags and (rulename == "c.build" or rulename == "c++.build" or rulename == "cuda.build") then firstcompflags = compflags end targetinfo.compflags[sourcefile] = compflags @@ -541,6 +544,7 @@ function make(outputdir, vsinfo) localcache.clear("option") localcache.clear("package") localcache.clear("toolchain") + localcache.clear("cxxmodules") -- check platform platform.load(config.plat(), arch):check() diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua index 452292abc..f9842bff1 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua @@ -713,18 +713,18 @@ function _make_custom_commands_item(vcxprojfile, commands, suffix) vcxprojfile:print("<PreLinkEvent>") end vcxprojfile:print("<Message></Message>") - vcxprojfile:print("<Command>setlocal") + local cmdstr = "setlocal" for _, command in ipairs(commands) do - vcxprojfile:print("%s", command) + cmdstr = cmdstr .. "\n" .. command + cmdstr = cmdstr .. "\nif %errorlevel% neq 0 goto :xmEnd" end - vcxprojfile:write([[if %errorlevel% neq 0 goto :xmEnd -:xmEnd + cmdstr = cmdstr .. "\n" .. [[:xmEnd endlocal & call :xmErrorLevel %errorlevel% & goto :xmDone :xmErrorLevel exit /b %1 :xmDone -if %errorlevel% neq 0 goto :VCEnd</Command> -]]) +if %errorlevel% neq 0 goto :VCEnd]] + vcxprojfile:print("<Command>%s</Command>", cmdstr) if suffix == "after" or suffix == "after_link" then vcxprojfile:print("</PostBuildEvent>") elseif suffix == "before" then @@ -957,7 +957,8 @@ function _build_common_items(vsinfo, target) targetinfo.sourceflags = {} for _, sourcebatch in pairs(targetinfo.sourcebatches) do local sourcekind = sourcebatch.sourcekind - if (sourcekind == "cc" or sourcekind == "cxx" or sourcekind == "as" or sourcekind == "mrc") then + local rulename = sourcebatch.rulename + if (rulename == "c.build" or rulename == "c++.build" or rulename == "asm.build" or sourcekind == "mrc") then for _, sourcefile in ipairs(sourcebatch.sourcefiles) do -- make compiler flags @@ -1020,12 +1021,13 @@ function _build_common_items(vsinfo, target) local sourceflags = {} for _, sourcebatch in pairs(targetinfo.sourcebatches) do local sourcekind = sourcebatch.sourcekind + local rulename = sourcebatch.rulename if (sourcekind == "as" or sourcekind == "mrc") then -- no common flags for as/mrc files for _, sourcefile in ipairs(sourcebatch.sourcefiles) do sourceflags[sourcefile] = targetinfo.sourceflags[sourcefile] end - elseif (sourcekind == "cc" or sourcekind == "cxx") then + elseif rulename == "c.build" or rulename == "c++.build" then -- sourcekind maybe bind multiple rules, e.g. c++modules for _, sourcefile in ipairs(sourcebatch.sourcefiles) do local flags = targetinfo.sourceflags[sourcefile] local otherflags = {} @@ -1313,7 +1315,8 @@ function _make_source_files(vcxprojfile, vsinfo, target) for _, targetinfo in ipairs(target.info) do for _, sourcebatch in pairs(targetinfo.sourcebatches) do local sourcekind = sourcebatch.sourcekind - if (sourcekind == "cc" or sourcekind == "cxx" or sourcekind == "as" or sourcekind == "mrc" or sourcekind == "cu") then + local rulename = sourcebatch.rulename + if (rulename == "c.build" or rulename == "c++.build" or sourcekind == "as" or sourcekind == "mrc" or sourcekind == "cu") then local objectfiles = sourcebatch.objectfiles for idx, sourcefile in ipairs(sourcebatch.sourcefiles) do local objectfile = objectfiles[idx] diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index e45947482..49bbfe745 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -468,6 +468,7 @@ function main(outputdir, vsinfo) localcache.clear("option") localcache.clear("package") localcache.clear("toolchain") + localcache.clear("cxxmodules") -- check platform platform.load(config.plat(), arch):check() |
