diff options
| author | ruki <[email protected]> | 2017-11-08 00:14:34 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-11-07 19:27:30 +0800 |
| commit | 1dbc7da494ce9ac38795a5b31e9c3ebc250aa37c (patch) | |
| tree | b0d5128b4672d416260c65266cc9857cc5f54203 | |
| parent | c911900a035e04a301f938526c6d224fba14f46d (diff) | |
improve to detect toolchains on macOS
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | xmake/platforms/checker.lua | 14 | ||||
| -rw-r--r-- | xmake/platforms/macosx/check.lua | 4 | ||||
| -rw-r--r-- | xmake/platforms/macosx/load.lua | 43 |
4 files changed, 47 insertions, 16 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e4d483fa..47a0e5eb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * Improve support for IDE/editor plugins (.e.g vscode, sublime, intellij-idea) * Add `.gitignore` file when creating new projects * Improve to create template project +* Improve to detect toolchains on macosx without xcode ### Bugs fixed @@ -397,6 +398,7 @@ * 改进对IDE和编辑器插件的集成支持,例如:Visual Studio Code, Sublime Text 以及 IntelliJ IDEA * 当生成新工程的时候,自动生成一个`.gitignore`文件,忽略一些xmake的临时文件和目录 * 改进创建模板工程,使用模板名代替模板id作为参数 +* 改进macOS编译平台的探测,如果没有安装xcode也能够进行编译构建,如果有编译器的话 ### Bugs修复 diff --git a/xmake/platforms/checker.lua b/xmake/platforms/checker.lua index b38178a2b..b6c0b894c 100644 --- a/xmake/platforms/checker.lua +++ b/xmake/platforms/checker.lua @@ -116,7 +116,7 @@ function check_arch(config, default) end -- check the xcode application directory -function check_xcode_dir(config) +function check_xcode_dir(config, optional) -- get the xcode directory local xcode_dir = config.get("xcode_dir") @@ -131,7 +131,9 @@ function check_xcode_dir(config) -- trace cprint("checking for the Xcode application directory ... ${green}%s", xcode_dir) - else + + elseif not optional then + -- failed cprint("checking for the Xcode application directory ... ${red}no") cprint("${bright red}please run:") @@ -143,10 +145,10 @@ function check_xcode_dir(config) end -- check the xcode sdk version -function check_xcode_sdkver(config) +function check_xcode_sdkver(config, optional) -- get the xcode sdk version - local xcode_sdkver = config.get("xcode_sdkver") + local xcode_sdkver = config.get("xcode_sdkver") if not xcode_sdkver then -- check ok? update it @@ -158,7 +160,9 @@ function check_xcode_sdkver(config) -- trace cprint("checking for the Xcode SDK version for %s ... ${green}%s", config.get("plat"), xcode_sdkver) - else + + elseif not optional then + -- failed cprint("checking for the Xcode SDK version for %s ... ${red}no", config.get("plat")) cprint("${bright red}please run:") diff --git a/xmake/platforms/macosx/check.lua b/xmake/platforms/macosx/check.lua index c9218a0b5..507044c65 100644 --- a/xmake/platforms/macosx/check.lua +++ b/xmake/platforms/macosx/check.lua @@ -130,8 +130,8 @@ function main(kind, toolkind) _g.config = { checker.check_arch - , checker.check_xcode_dir - , checker.check_xcode_sdkver + , { checker.check_xcode_dir, true } + , { checker.check_xcode_sdkver, true } } -- init the check list of global diff --git a/xmake/platforms/macosx/load.lua b/xmake/platforms/macosx/load.lua index 2cd72a587..85ad7c302 100644 --- a/xmake/platforms/macosx/load.lua +++ b/xmake/platforms/macosx/load.lua @@ -35,23 +35,48 @@ function main() -- init flags for the xcode sdk directory local xcode_dir = config.get("xcode_dir") local xcode_sdkver = config.get("xcode_sdkver") - local xcode_sdkdir = xcode_dir .. "/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk" + local xcode_sdkdir = nil + if xcode_dir and xcode_sdkver then + xcode_sdkdir = xcode_dir .. "/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk" + end -- init flags for c/c++ - _g.cxflags = { "-arch " .. arch, "-fpascal-strings", "-fmessage-length=0", "-isysroot " .. xcode_sdkdir, "-I/usr/local/include", "-I/usr/include" } - _g.ldflags = { "-arch " .. arch, "-mmacosx-version-min=" .. target_minver, "-isysroot " .. xcode_sdkdir, "-L/usr/local/lib", "-L/usr/lib", "-stdlib=libc++", "-lz" } - _g.shflags = { "-arch " .. arch, "-mmacosx-version-min=" .. target_minver, "-isysroot " .. xcode_sdkdir, "-L/usr/local/lib", "-L/usr/lib", "-stdlib=libc++", "-lz" } + _g.cxflags = { "-arch " .. arch, "-fpascal-strings", "-fmessage-length=0" } + _g.ldflags = { "-arch " .. arch } + if target_minver then + table.insert(_g.ldflags, "-mmacosx-version-min=" .. target_minver) + end + if xcode_sdkdir then + table.insert(_g.cxflags, "-isysroot " .. xcode_sdkdir) + table.insert(_g.ldflags, "-isysroot " .. xcode_sdkdir) + else + table.insert(_g.cxflags, "-I/usr/local/include") + table.insert(_g.cxflags, "-I/usr/include") + table.insert(_g.ldflags, "-L/usr/local/lib") + table.insert(_g.ldflags, "-L/usr/lib") + end + table.insert(_g.ldflags, "-stdlib=libc++") + table.insert(_g.ldflags, "-lz") + _g.shflags = table.copy(_g.ldflags) -- init flags for objc/c++ (with _g.ldflags and _g.shflags) - _g.mxflags = { "-arch " .. arch, "-fpascal-strings", "-fmessage-length=0", "-isysroot " .. xcode_sdkdir } + _g.mxflags = { "-arch " .. arch, "-fpascal-strings", "-fmessage-length=0" } + if xcode_sdkdir then + table.insert(_g.mxflags, "-isysroot " .. xcode_sdkdir) + end -- init flags for asm (with _g.ldflags and _g.shflags) - _g.asflags = { "-arch " .. arch, "-isysroot " .. xcode_sdkdir } + _g.asflags = { "-arch " .. arch } + if xcode_sdkdir then + table.insert(_g.asflags, "-isysroot " .. xcode_sdkdir) + end -- init flags for swift - _g.scflags = { format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir } - _g["sc-shflags"] = { format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir } - _g["sc-ldflags"] = { format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir } + if target_minver and xcode_sdkdir then + _g.scflags = { format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir } + _g["sc-shflags"] = { format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir } + _g["sc-ldflags"] = { format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir } + end -- init flags for golang _g["gc-ldflags"] = {} |
