diff options
| author | ruki <[email protected]> | 2019-04-23 22:46:02 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-04-23 10:36:15 +0800 |
| commit | 6a430c2260ea9ba01cfd164bfe265157b15c235f (patch) | |
| tree | 257a1c10b341b39c3db11fed6904bcc43f7e42cd | |
| parent | 622ffac19d48807ad132b26b06c10614612e76b9 (diff) | |
add c preprocessor
| -rw-r--r-- | xmake/languages/c++/xmake.lua | 1 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_cpp.lua | 54 | ||||
| -rw-r--r-- | xmake/modules/package/tools/autoconf.lua | 35 | ||||
| -rw-r--r-- | xmake/platforms/iphoneos/config.lua | 10 | ||||
| -rw-r--r-- | xmake/platforms/macosx/config.lua | 9 |
5 files changed, 88 insertions, 21 deletions
diff --git a/xmake/languages/c++/xmake.lua b/xmake/languages/c++/xmake.lua index 2d94df007..73c438adb 100644 --- a/xmake/languages/c++/xmake.lua +++ b/xmake/languages/c++/xmake.lua @@ -157,6 +157,7 @@ language("c++") {category = "Cross Complation Configuration/Compiler Configuration" } , {nil, "cc", "kv", nil, "The C Compiler" } , {nil, "cxx", "kv", nil, "The C++ Compiler" } + , {nil, "cpp", "kv", nil, "The C Preprocessor" } , {category = "Cross Complation Configuration/Linker Configuration" } , {nil, "ld", "kv", nil, "The Linker" } diff --git a/xmake/modules/detect/tools/find_cpp.lua b/xmake/modules/detect/tools/find_cpp.lua new file mode 100644 index 000000000..35c1a1e82 --- /dev/null +++ b/xmake/modules/detect/tools/find_cpp.lua @@ -0,0 +1,54 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2019, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_cpp.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find cpp +-- +-- @param opt the argument options, .e.g {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local cpp = find_cpp() +-- local cpp, version = find_cpp({program = "xcrun -sdk macosx cpp", version = true}) +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + + -- find program + local program = find_program(opt.program or "cpp", opt) + + -- find program version + local version = nil + if program and opt and opt.version then + version = find_programver(program, opt) + end + + -- ok? + return program, version +end diff --git a/xmake/modules/package/tools/autoconf.lua b/xmake/modules/package/tools/autoconf.lua index d1ed3de09..8104fc822 100644 --- a/xmake/modules/package/tools/autoconf.lua +++ b/xmake/modules/package/tools/autoconf.lua @@ -34,6 +34,7 @@ function _enter_envs(package) envs.AS = os.getenv("AS") envs.AR = os.getenv("AR") envs.LD = os.getenv("LD") + envs.CPP = os.getenv("CPP") envs.LDSHARED = os.getenv("LDSHARED") envs.RANLIB = os.getenv("RANLIB") envs.CFLAGS = os.getenv("CFLAGS") @@ -54,11 +55,12 @@ function _enter_envs(package) os.addenvp("ASFLAGS", package:config("asflags"), ' ') else os.setenv("RANLIB", "") - os.addenvp("CC", package:build_getenv("cc"), ' ') - os.addenvp("AS", package:build_getenv("as"), ' ') - os.addenvp("AR", package:build_getenv("ar"), ' ') - os.addenvp("LD", package:build_getenv("ld"), ' ') - os.addenvp("LDSHARED", package:build_getenv("sh"), ' ') + os.setenvp("CC", package:build_getenv("cc"), ' ') + os.setenvp("AS", package:build_getenv("as"), ' ') + os.setenvp("AR", package:build_getenv("ar"), ' ') + os.setenvp("LD", package:build_getenv("ld"), ' ') + os.setenvp("LDSHARED", package:build_getenv("sh"), ' ') + os.setenvp("CPP", package:build_getenv("cpp"), ' ') os.addenvp("CFLAGS", package:build_getenv("cflags"), ' ') os.addenvp("CFLAGS", package:build_getenv("cxflags"), ' ') os.addenvp("CXXFLAGS", package:build_getenv("cxflags"), ' ') @@ -88,8 +90,8 @@ function _leave_envs(package, envs) end end --- install package -function install(package, configs, opt) +-- configure package +function configure(package, configs) -- generate configure file if not os.isfile("configure") then @@ -119,16 +121,17 @@ function install(package, configs, opt) -- do configure os.vrunv("./configure", argv) - -- do before_build() - if opt and opt.before_build then - opt.before_build() - end - - -- do make and install - os.vrun("make -j4") - os.vrun("make install") - -- leave environments _leave_envs(package, envs) end +-- install package +function install(package, configs) + + -- do configure + configure(package, configs) + + -- do make and install + os.vrun("make install -j4") +end + diff --git a/xmake/platforms/iphoneos/config.lua b/xmake/platforms/iphoneos/config.lua index 2d8521dc4..8748657d9 100644 --- a/xmake/platforms/iphoneos/config.lua +++ b/xmake/platforms/iphoneos/config.lua @@ -30,7 +30,7 @@ import("private.platform.check_toolchain") function _toolchains() -- init architecture - local arch = config.get("arch") + local arch = config.get("arch") or os.arch() local simulator = (arch == "i386" or arch == "x86_64") -- init cross @@ -38,6 +38,7 @@ function _toolchains() -- init toolchains local cc = toolchain("the c compiler") + local cpp = toolchain("the c preprocessor") local cxx = toolchain("the c++ compiler") local ld = toolchain("the linker") local sh = toolchain("the shared library linker") @@ -49,12 +50,15 @@ function _toolchains() local sc = toolchain("the swift compiler") local sc_ld = toolchain("the swift linker") local sc_sh = toolchain("the swift shared library linker") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, + local toolchains = {cc = cc, cpp = cpp, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, mm = mm, mxx = mxx, sc = sc, ["sc-ld"] = sc_ld, ["sc-sh"] = sc_sh} -- init the c compiler cc:add({name = "clang", cross = cross}) + -- init the c preprocessor + cpp:add({name = "clang -arch " .. arch .. " -E", cross = cross}) + -- init the c++ compiler cxx:add({name = "clang", cross = cross}) cxx:add({name = "clang++", cross = cross}) @@ -100,7 +104,7 @@ function main(platform, name) -- only check the given config name? if name then - local toolchain = singleton.get("iphoneos.toolchains", _toolchains)[name] + local toolchain = singleton.get("iphoneos.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] if toolchain then check_toolchain(config, name, toolchain) end diff --git a/xmake/platforms/macosx/config.lua b/xmake/platforms/macosx/config.lua index 57674fc0b..618dba0e1 100644 --- a/xmake/platforms/macosx/config.lua +++ b/xmake/platforms/macosx/config.lua @@ -31,10 +31,12 @@ import("private.platform.check_toolchain") function _toolchains() -- init cross + local arch = config.get("arch") or os.arch() local cross = "xcrun -sdk macosx " -- init toolchains local cc = toolchain("the c compiler") + local cpp = toolchain("the c preprocessor") local cxx = toolchain("the c++ compiler") local ld = toolchain("the linker") local sh = toolchain("the shared library linker") @@ -60,7 +62,7 @@ function _toolchains() local cu = toolchain("the cuda compiler") local cu_ld = toolchain("the cuda linker") local cu_sh = toolchain("the cuda shared library linker") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, + local toolchains = {cc = cc, cpp = cpp, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, mm = mm, mxx = mxx, sc = sc, ["sc-ld"] = sc_ld, ["sc-sh"] = sc_sh, gc = gc, ["gc-ld"] = gc_ld, ["gc-ar"] = gc_ar, dc = dc, ["dc-ld"] = dc_ld, ["dc-sh"] = dc_sh, ["dc-ar"] = dc_ar, @@ -70,6 +72,9 @@ function _toolchains() -- init the c compiler cc:add("$(env CC)", {name = "clang", cross = cross}, "clang", "gcc") + -- init the c preprocessor + cpp:add("$(env CPP)", {name = "clang -arch " .. arch .. " -E", cross = cross}, "clang -arch " .. arch .. " -E") + -- init the c++ compiler cxx:add("$(env CXX)") cxx:add({name = "clang", cross = cross}) @@ -141,7 +146,7 @@ function main(platform, name) -- only check the given config name? if name then - local toolchain = singleton.get("macosx.toolchains", _toolchains)[name] + local toolchain = singleton.get("macosx.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] if toolchain then check_toolchain(config, name, toolchain) end |
