summaryrefslogtreecommitdiff
path: root/xmake/plugins/project/vstudio/impl
diff options
context:
space:
mode:
authorruki <[email protected]>2017-08-04 15:37:44 +0800
committerruki <[email protected]>2017-08-04 15:37:44 +0800
commitfada840909bf5e61e3d5c8bed84722166f5adda0 (patch)
tree2872417ab3ef455ae7fa746b8188ea1df83f1596 /xmake/plugins/project/vstudio/impl
parentb9f40db69152c3458b2a0dcd1b99eb094e578a0d (diff)
improve precompiled header
Diffstat (limited to 'xmake/plugins/project/vstudio/impl')
-rw-r--r--xmake/plugins/project/vstudio/impl/vs200x.lua3
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x.lua15
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua95
-rw-r--r--xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua23
4 files changed, 76 insertions, 60 deletions
diff --git a/xmake/plugins/project/vstudio/impl/vs200x.lua b/xmake/plugins/project/vstudio/impl/vs200x.lua
index 6a14613d7..10207467b 100644
--- a/xmake/plugins/project/vstudio/impl/vs200x.lua
+++ b/xmake/plugins/project/vstudio/impl/vs200x.lua
@@ -42,7 +42,8 @@ function make(outputdir, vsinfo)
-- TODO
-- disable precompiled header first
for _, target in pairs(project.targets()) do
- target:set("precompiled_header", nil)
+ target:set("pcheader", nil)
+ target:set("pcxxheader", nil)
end
-- make vsprojs
diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua
index 7b470e94e..bf638d031 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x.lua
@@ -47,9 +47,11 @@ function _make_targetinfo(mode, arch, target)
targetinfo.sdkver = (vcvarsall[arch] or {}).sdkver
end
- -- save precompiled header file (.pch)
- targetinfo.pcheaderfile = target:pcheaderfile()
- target:set("precompiled_header", nil)
+ -- save c/c++ precompiled output file (.pch)
+ targetinfo.pcoutputfile = target:pcoutputfile("c")
+ targetinfo.pcxxoutputfile = target:pcoutputfile("cxx")
+ target:set("pcheader", nil)
+ target:set("pcxxheader", nil)
-- save symbols
targetinfo.symbols = target:get("symbols")
@@ -197,10 +199,9 @@ function make(outputdir, vsinfo)
targets[targetname] = targets[targetname] or {}
local _target = targets[targetname]
- -- save precompiled header and source
- local precompiled_header, precompiled_source = target:pcsourcefile()
- _target.pcheader = precompiled_header -- header.h
- _target.pcsourcefile = precompiled_source -- header.cpp
+ -- save c/c++ precompiled header
+ _target.pcheader = target:pcheaderfile("c") -- header.h
+ _target.pcxxheader = target:pcheaderfile("cxx") -- header.[hpp|inl]
-- init target info
_target.name = targetname
diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
index d302b1bf4..7abe20a54 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua
@@ -24,6 +24,7 @@
-- imports
import("core.project.config")
+import("core.language.language")
import("vsfile")
-- make compiling flags
@@ -376,26 +377,16 @@ function _make_common_item(vcxprojfile, vsinfo, target, targetinfo, vcxprojdir)
vcxprojfile:print("<ProgramDatabaseFile>%s</ProgramDatabaseFile>", path.relative(path.absolute(symbolfile), vcxprojdir))
end
- -- use precompiled header
- if target.pcheader then
+ -- use c or c++ precompiled header
+ local pcheader = target.pcxxheader or target.pcheader
+ if pcheader then
- -- get precompiled header file
- local pcheader = path.filename(target.pcheader)
- if target.pcsourcefile and os.isfile(target.pcsourcefile) then
- local sourcedata = io.readfile(target.pcsourcefile)
- if sourcedata then
- local includefile = sourcedata:match("#include%s+[<\"](.+)[>\"]")
- if includefile then
- pcheader = includefile
- end
- end
- end
-
-- make precompiled header and outputfile
vcxprojfile:print("<PrecompiledHeader>Use</PrecompiledHeader>")
- vcxprojfile:print("<PrecompiledHeaderFile>%s</PrecompiledHeaderFile>", pcheader)
- if targetinfo.pcheaderfile then
- vcxprojfile:print("<PrecompiledHeaderOutputFile>%s</PrecompiledHeaderOutputFile>", path.relative(path.absolute(targetinfo.pcheaderfile), vcxprojdir))
+ vcxprojfile:print("<PrecompiledHeaderFile>%s</PrecompiledHeaderFile>", path.filename(pcheader))
+ local pcoutputfile = targetinfo.pcxxoutputfile or targetinfo.pcoutputfile
+ if pcoutputfile then
+ vcxprojfile:print("<PrecompiledHeaderOutputFile>%s</PrecompiledHeaderOutputFile>", path.relative(path.absolute(pcoutputfile), vcxprojdir))
end
end
@@ -476,7 +467,7 @@ function _make_header_file(vcxprojfile, includefile, vcxprojdir)
end
-- make source file for all modes
-function _make_source_file_forall(vcxprojfile, vsinfo, sourcefile, sourceinfo, vcxprojdir)
+function _make_source_file_forall(vcxprojfile, vsinfo, target, sourcefile, sourceinfo, vcxprojdir)
-- get object file and source kind
local sourcekind = nil
@@ -542,10 +533,20 @@ function _make_source_file_forall(vcxprojfile, vsinfo, sourcefile, sourceinfo, v
end
end
+ -- disable the precompiled header if sourcekind ~= headerkind
+ local pcheader = target.pcxxheader or target.pcheader
+ local pcheader_disable = false
+ if pcheader and language.sourcekind_of(sourcefile) ~= ifelse(target.pcxxheader, "cxx", "cc") then
+ pcheader_disable = true
+ end
+
-- all modes and archs exist?
if count == #vsinfo.modes then
if #key > 0 then
vcxprojfile:print("<%s>%s</%s>", itemname, iteminfo.value(key), itemname)
+ if pcheader_disable then
+ vcxprojfile:print("<PrecompiledHeader>NotUsing</PrecompiledHeader>")
+ end
end
else
for cond, _ in pairs(mergeinfos) do
@@ -553,11 +554,17 @@ function _make_source_file_forall(vcxprojfile, vsinfo, sourcefile, sourceinfo, v
-- for mode | arch
if #key > 0 then
vcxprojfile:print("<%s Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s\'\">%s</%s>", itemname, cond, iteminfo.value(key), itemname)
+ if pcheader_disable then
+ vcxprojfile:print("<PrecompiledHeader Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s\'\">NotUsing</PrecompiledHeader>", cond)
+ end
end
else
-- only for mode
if #key > 0 then
vcxprojfile:print("<%s Condition=\"\'%$(Configuration)\'==\'%s\'\">%s</%s>", itemname, cond, iteminfo.value(key), itemname)
+ if pcheader_disable then
+ vcxprojfile:print("<PrecompiledHeader Condition=\"\'%$(Configuration)\'==\'%s\'\">NotUsing</PrecompiledHeader>", cond)
+ end
end
end
end
@@ -571,7 +578,7 @@ function _make_source_file_forall(vcxprojfile, vsinfo, sourcefile, sourceinfo, v
end
-- make source file for specific modes
-function _make_source_file_forspec(vcxprojfile, vsinfo, sourcefile, sourceinfo, vcxprojdir)
+function _make_source_file_forspec(vcxprojfile, vsinfo, target, sourcefile, sourceinfo, vcxprojdir)
-- add source file
sourcefile = path.relative(path.absolute(sourcefile), vcxprojdir)
@@ -590,6 +597,12 @@ function _make_source_file_forspec(vcxprojfile, vsinfo, sourcefile, sourceinfo,
-- for *.c/cpp files
else
+
+ -- disable the precompiled header if sourcekind ~= headerkind
+ local pcheader = target.pcxxheader or target.pcheader
+ if pcheader and language.sourcekind_of(sourcefile) ~= ifelse(target.pcxxheader, "cxx", "cc") then
+ vcxprojfile:print("<PrecompiledHeader>NotUsing</PrecompiledHeader>")
+ end
vcxprojfile:print("<ObjectFileName>%s</ObjectFileName>", objectfile)
vcxprojfile:print("<AdditionalOptions>%s %%(AdditionalOptions)</AdditionalOptions>", os.args(info.flags))
end
@@ -600,18 +613,31 @@ function _make_source_file_forspec(vcxprojfile, vsinfo, sourcefile, sourceinfo,
end
-- make source file for precompiled header
-function _make_source_file_forpch(vcxprojfile, vsinfo, pcsourcefile, targetinfo, vcxprojdir)
+function _make_source_file_forpch(vcxprojfile, vsinfo, target, vcxprojdir)
-- add precompiled source file
- local sourcefile = path.relative(path.absolute(pcsourcefile), vcxprojdir)
- vcxprojfile:enter("<ClCompile Include=\"%s\">", sourcefile)
- vcxprojfile:print("<PrecompiledHeader>Create</PrecompiledHeader>")
- vcxprojfile:print("<AdditionalOptions> %%(AdditionalOptions)</AdditionalOptions>")
- for _, info in ipairs(targetinfo) do
- local objectfile = path.relative(path.absolute(info.pcheaderfile .. ".obj"), vcxprojdir)
- vcxprojfile:print("<ObjectFileName Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\">%s</ObjectFileName>", info.mode, info.arch, objectfile)
- end
- vcxprojfile:leave("</ClCompile>")
+ local pcheader = target.pcxxheader or target.pcheader
+ if pcheader then
+ local sourcefile = path.relative(path.absolute(pcheader), vcxprojdir)
+ vcxprojfile:enter("<ClCompile Include=\"%s\">", sourcefile)
+ vcxprojfile:print("<PrecompiledHeader>Create</PrecompiledHeader>")
+ vcxprojfile:print("<PrecompiledHeaderFile></PrecompiledHeaderFile>")
+ vcxprojfile:print("<AdditionalOptions> %%(AdditionalOptions)</AdditionalOptions>")
+ for _, info in ipairs(target.info) do
+
+ -- compile as c/c++
+ local compileas = ifelse(target.pcxxheader, "CompileAsCpp", "CompileAsC")
+ vcxprojfile:print("<CompileAs Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\">%s</CompileAs>", info.mode, info.arch, compileas)
+
+ -- add object file
+ local pcoutputfile = info.pcxxoutputfile or info.pcoutputfile
+ if pcoutputfile then
+ local objectfile = path.relative(path.absolute(pcoutputfile .. ".obj"), vcxprojdir)
+ vcxprojfile:print("<ObjectFileName Condition=\"\'%$(Configuration)|%$(Platform)\'==\'%s|%s\'\">%s</ObjectFileName>", info.mode, info.arch, objectfile)
+ end
+ end
+ vcxprojfile:leave("</ClCompile>")
+ end
end
-- make source files
@@ -639,16 +665,14 @@ function _make_source_files(vcxprojfile, vsinfo, target, vcxprojdir)
-- make source files
for sourcefile, sourceinfo in pairs(sourceinfos) do
if #sourceinfo == #target.info then
- _make_source_file_forall(vcxprojfile, vsinfo, sourcefile, sourceinfo, vcxprojdir)
+ _make_source_file_forall(vcxprojfile, vsinfo, target, sourcefile, sourceinfo, vcxprojdir)
else
- _make_source_file_forspec(vcxprojfile, vsinfo, sourcefile, sourceinfo, vcxprojdir)
+ _make_source_file_forspec(vcxprojfile, vsinfo, target, sourcefile, sourceinfo, vcxprojdir)
end
end
-- make precompiled source file
- if target.pcsourcefile then
- _make_source_file_forpch(vcxprojfile, vsinfo, target.pcsourcefile, target.info, vcxprojdir)
- end
+ _make_source_file_forpch(vcxprojfile, vsinfo, target, vcxprojdir)
vcxprojfile:leave("</ItemGroup>")
@@ -657,9 +681,6 @@ function _make_source_files(vcxprojfile, vsinfo, target, vcxprojdir)
for _, includefile in ipairs(target.headerfiles) do
_make_header_file(vcxprojfile, includefile, vcxprojdir)
end
- if target.pcheader then
- _make_header_file(vcxprojfile, target.pcheader, vcxprojdir)
- end
vcxprojfile:leave("</ItemGroup>")
end
diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua
index c2432b4df..f15fa9c5f 100644
--- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua
+++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj_filters.lua
@@ -98,13 +98,14 @@ function _make_sources(filtersfile, vsinfo, target, vcxprojdir)
filtersfile:print("<Filter>%s</Filter>", filter)
filtersfile:leave("</%s>", ifelse(as, "CustomBuild", "ClCompile"))
end
- end
- if target.pcsourcefile then
- local filter = _make_filter(target.pcsourcefile, target, vcxprojdir)
- if filter then
- filtersfile:enter("<ClCompile Include=\"%s\">", path.relative(path.absolute(target.pcsourcefile), vcxprojdir))
- filtersfile:print("<Filter>%s</Filter>", filter)
- filtersfile:leave("</ClCompile>")
+ local pcheader = target.pcxxheader or target.pcheader
+ if pcheader then
+ local filter = _make_filter(pcheader, target, vcxprojdir)
+ if filter then
+ filtersfile:enter("<ClCompile Include=\"%s\">", path.relative(path.absolute(pcheader), vcxprojdir))
+ filtersfile:print("<Filter>%s</Filter>", filter)
+ filtersfile:leave("</ClCompile>")
+ end
end
end
filtersfile:leave("</ItemGroup>")
@@ -123,14 +124,6 @@ function _make_headers(filtersfile, vsinfo, target, vcxprojdir)
filtersfile:leave("</ClInclude>")
end
end
- if target.pcheader then
- local filter = _make_filter(target.pcheader, target, vcxprojdir)
- if filter then
- filtersfile:enter("<ClInclude Include=\"%s\">", path.relative(path.absolute(target.pcheader), vcxprojdir))
- filtersfile:print("<Filter>%s</Filter>", filter)
- filtersfile:leave("</ClInclude>")
- end
- end
filtersfile:leave("</ItemGroup>")
end