diff options
| author | ruki <[email protected]> | 2020-02-19 00:40:43 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-02-18 22:04:19 +0800 |
| commit | 6639c577afb292e4e8cc46fa8513e1c6ea952df4 (patch) | |
| tree | b001f4986ec87135583f6315caefce37ad935e80 | |
| parent | 8b831931741f696c3b90940877d4bc7eca1347cf (diff) | |
improve trybuild directory
| -rw-r--r-- | xmake/modules/private/action/trybuild/autotools.lua | 36 | ||||
| -rw-r--r-- | xmake/modules/private/action/trybuild/cmake.lua | 30 |
2 files changed, 58 insertions, 8 deletions
diff --git a/xmake/modules/private/action/trybuild/autotools.lua b/xmake/modules/private/action/trybuild/autotools.lua index da6c37740..63ccbc405 100644 --- a/xmake/modules/private/action/trybuild/autotools.lua +++ b/xmake/modules/private/action/trybuild/autotools.lua @@ -20,8 +20,19 @@ -- imports import("core.base.option") +import("core.project.config") import("lib.detect.find_file") +-- get build directory +function _get_buildir() + return config.buildir() +end + +-- get artifacts directory +function _get_artifacts_dir() + return path.absolute(path.join(_get_buildir(), "artifacts")) +end + -- detect build-system and configuration file function detect() return find_file("configure", os.curdir()) or find_file("configure.ac", os.curdir()) @@ -29,10 +40,24 @@ end -- do clean function clean() + if find_file("[mM]akefile", os.curdir()) then + os.exec("make clean") + if option.get("all") then + os.tryrm(_get_artifacts_dir()) + end + end end -- do build function build() + + -- get artifacts directory + local artifacts_dir = _get_artifacts_dir() + if not os.isdir(artifacts_dir) then + os.mkdir(artifacts_dir) + end + + -- generate configure if not os.isfile("configure") then if os.isfile("autogen.sh") then os.execv("sh", {"./autogen.sh"}) @@ -40,11 +65,16 @@ function build() os.exec("autoreconf --install --symlink") end end - os.mkdir("build/install") - os.exec("./configure --prefix=%s", path.absolute("build/install")) + + -- do configure + if not find_file("[mM]akefile", os.curdir()) then + os.execv("./configure", "--prefix=" .. artifacts_dir) + end + + -- do build os.exec("make -j4") os.exec("make install") - cprint("installed to ${bright}%s", path.absolute("build/install")) + cprint("output to ${bright}%s", artifacts_dir) cprint("${bright}build ok!") end diff --git a/xmake/modules/private/action/trybuild/cmake.lua b/xmake/modules/private/action/trybuild/cmake.lua index d548ed416..af1eadad1 100644 --- a/xmake/modules/private/action/trybuild/cmake.lua +++ b/xmake/modules/private/action/trybuild/cmake.lua @@ -20,8 +20,19 @@ -- imports import("core.base.option") +import("core.project.config") import("lib.detect.find_file") +-- get build directory +function _get_buildir() + return config.buildir() +end + +-- get artifacts directory +function _get_artifacts_dir() + return path.absolute(path.join(_get_buildir(), "artifacts")) +end + -- detect build-system and configuration file function detect() return find_file("CMakeLists.txt", os.curdir()) @@ -33,13 +44,22 @@ end -- do build function build() - os.mkdir("build") - os.cd("build") + + -- get artifacts directory + local artifacts_dir = _get_artifacts_dir() + if not os.isdir(artifacts_dir) then + os.mkdir(artifacts_dir) + end + + -- generate makefile + os.cd(_get_buildir()) if is_host("windows") and os.arch() == "x64" then - os.exec("cmake -A x64 -DCMAKE_INSTALL_PREFIX=\"%s\" ..", path.absolute("build/install")) + os.exec("cmake -A x64 -DCMAKE_INSTALL_PREFIX=\"%s\" ..", artifacts_dir) else - os.exec("cmake -DCMAKE_INSTALL_PREFIX=\"%s\" ..", path.absolute("build/install")) + os.exec("cmake -DCMAKE_INSTALL_PREFIX=\"%s\" ..", artifacts_dir) end + + -- do build if is_host("windows") then local slnfile = assert(find_file("*.sln", os.curdir()), "*.sln file not found!") @@ -51,7 +71,7 @@ function build() os.exec("make -j4") os.exec("make install") end - cprint("installed to ${bright}%s", path.absolute("build/install")) + cprint("installed to ${bright}%s", artifacts_dir) cprint("${bright}build ok!") end |
