summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-12-05 00:41:49 +0800
committerruki <[email protected]>2020-12-04 22:11:35 +0800
commit5f5a91f31793f747dc9d168a627b5d7107aa8107 (patch)
tree3dd20ada170c2d7b530cdc710f1014901aceb385
parent6e1208a78898729bae46a726240f0de01e75d99f (diff)
improve find_cmake and find_ninja
-rw-r--r--xmake/modules/detect/tools/find_cmake.lua7
-rw-r--r--xmake/modules/detect/tools/find_ninja.lua59
2 files changed, 64 insertions, 2 deletions
diff --git a/xmake/modules/detect/tools/find_cmake.lua b/xmake/modules/detect/tools/find_cmake.lua
index 49a8b6e42..145a439e9 100644
--- a/xmake/modules/detect/tools/find_cmake.lua
+++ b/xmake/modules/detect/tools/find_cmake.lua
@@ -21,6 +21,7 @@
-- imports
import("lib.detect.find_program")
import("lib.detect.find_programver")
+import("core.tool.toolchain")
-- find cmake
--
@@ -41,6 +42,10 @@ function main(opt)
opt = opt or {}
if is_host("windows") then
opt.paths = "$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Kitware\\CMake;InstallDir)\\bin"
+ local msvc = toolchain.load("msvc")
+ if msvc:check() then
+ opt.envs = toolchain.load("msvc"):runenvs() -- we attempt to find it from vstudio environments
+ end
end
-- find program
@@ -51,7 +56,5 @@ function main(opt)
if program and opt and opt.version then
version = find_programver(program, opt)
end
-
- -- ok?
return program, version
end
diff --git a/xmake/modules/detect/tools/find_ninja.lua b/xmake/modules/detect/tools/find_ninja.lua
new file mode 100644
index 000000000..055939497
--- /dev/null
+++ b/xmake/modules/detect/tools/find_ninja.lua
@@ -0,0 +1,59 @@
+--!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-2020, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file find_ninja.lua
+--
+
+-- imports
+import("lib.detect.find_program")
+import("lib.detect.find_programver")
+import("core.tool.toolchain")
+
+-- find ninja
+--
+-- @param opt the argument options, e.g. {version = true}
+--
+-- @return program, version
+--
+-- @code
+--
+-- local ninja = find_ninja()
+-- local ninja, version = find_ninja({version = true})
+--
+-- @endcode
+--
+function main(opt)
+
+ -- init options
+ opt = opt or {}
+ if is_host("windows") then
+ local msvc = toolchain.load("msvc")
+ if msvc:check() then
+ opt.envs = toolchain.load("msvc"):runenvs() -- we attempt to find it from vstudio environments
+ end
+ end
+
+ -- find program
+ local program = find_program(opt.program or "ninja", opt)
+
+ -- find program version
+ local version = nil
+ if program and opt and opt.version then
+ version = find_programver(program, opt)
+ end
+ return program, version
+end