From a894334e3c80f9c13a0e64f5ce2f96b57726f186 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 10 Nov 2020 22:37:23 +0800 Subject: impl nd_sysincludedir --- xmake/modules/core/tools/cl.lua | 16 ++++++++++++++-- xmake/plugins/project/cmake/cmakelists.lua | 23 +++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index 8e69319e1..d24ef5901 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -258,7 +258,19 @@ end -- make the sysincludedir flag function nf_sysincludedir(self, dir) - return nf_includedir(self, dir) + local has_external_includedir = _g._HAS_EXTERNAL_INCLUDEDIR + if has_external_includedir == nil then + if self:has_flags({"-experimental:external", "-external:W0", "-external:I" .. os.args(path.translate(dir))}, "cxflags", {flagskey = "cl_external_includedir"}) then + has_external_includedir = true + end + has_external_includedir = has_external_includedir or false + _g._HAS_EXTERNAL_INCLUDEDIR = has_external_includedir + end + if has_external_includedir then + return {"-experimental:external", "-external:W0", "-external:I" .. os.args(path.translate(dir))} + else + return nf_includedir(self, dir) + end end -- make the c precompiled header flag @@ -341,7 +353,7 @@ function _has_source_dependencies(self) local has_source_dependencies = _g._HAS_SOURCE_DEPENDENCIES if has_source_dependencies == nil then local source_dependencies_jsonfile = os.tmpfile() .. ".json" - if self:has_flags("/sourceDependencies " .. source_dependencies_jsonfile, "cl_sourceDependencies") and os.isfile(source_dependencies_jsonfile) then + if self:has_flags("/sourceDependencies " .. source_dependencies_jsonfile, "cxflags", {flagskey = "cl_sourceDependencies"}) and os.isfile(source_dependencies_jsonfile) then has_source_dependencies = true end has_source_dependencies = has_source_dependencies or false diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua index fe8a66871..8dc3416b0 100644 --- a/xmake/plugins/project/cmake/cmakelists.lua +++ b/xmake/plugins/project/cmake/cmakelists.lua @@ -182,6 +182,26 @@ function _add_target_include_directories(cmakelists, target) end end +-- add target system include directories +function _add_target_sysinclude_directories(cmakelists, target) + local includedirs = _get_configs_from_target(target, "sysincludedirs") + if #includedirs > 0 then + cmakelists:print("target_include_directories(%s SYSTEM PRIVATE", target:name()) + for _, includedir in ipairs(includedirs) do + cmakelists:print(" " .. _get_unix_path(includedir)) + end + cmakelists:print(")") + end + local includedirs_interface = target:get("sysincludedirs", {interface = true}) + if includedirs_interface then + cmakelists:print("target_include_directories(%s SYSTEM INTERFACE", target:name()) + for _, headerdir in ipairs(includedirs_interface) do + cmakelists:print(" " .. _get_unix_path(headerdir)) + end + cmakelists:print(")") + end +end + -- add target compile definitions function _add_target_compile_definitions(cmakelists, target) local defines = _get_configs_from_target(target, "defines") @@ -470,6 +490,9 @@ function _add_target(cmakelists, target) -- add target include directories _add_target_include_directories(cmakelists, target) + -- add target system include directories + _add_target_sysinclude_directories(cmakelists, target) + -- add target compile definitions _add_target_compile_definitions(cmakelists, target) -- cgit v1.3.1