summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-09-29 00:51:53 +0800
committerruki <[email protected]>2021-09-29 00:51:53 +0800
commit88eda991bfd54b709cda4eb72be1665ad6ce85ef (patch)
treeddd328d9c0c071c14999194477d632863462a5e3
parent169141eaa2158281f80aca5c30e17c9d1ace52d7 (diff)
add with cmakelists
-rw-r--r--tests/projects/c/library_with_cmakelists/.gitignore8
-rw-r--r--tests/projects/c/library_with_cmakelists/foo/CMakeLists.txt8
-rw-r--r--tests/projects/c/library_with_cmakelists/foo/src/interface.c6
-rw-r--r--tests/projects/c/library_with_cmakelists/foo/src/interface.h8
-rw-r--r--tests/projects/c/library_with_cmakelists/src/main.c8
-rw-r--r--tests/projects/c/library_with_cmakelists/xmake.lua25
-rw-r--r--xmake/core/package/package.lua6
-rw-r--r--xmake/modules/private/action/require/impl/actions/install.lua5
8 files changed, 73 insertions, 1 deletions
diff --git a/tests/projects/c/library_with_cmakelists/.gitignore b/tests/projects/c/library_with_cmakelists/.gitignore
new file mode 100644
index 000000000..152105761
--- /dev/null
+++ b/tests/projects/c/library_with_cmakelists/.gitignore
@@ -0,0 +1,8 @@
+# Xmake cache
+.xmake/
+build/
+
+# MacOS Cache
+.DS_Store
+
+
diff --git a/tests/projects/c/library_with_cmakelists/foo/CMakeLists.txt b/tests/projects/c/library_with_cmakelists/foo/CMakeLists.txt
new file mode 100644
index 000000000..2654a77a2
--- /dev/null
+++ b/tests/projects/c/library_with_cmakelists/foo/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.13.0)
+project(foo_demo LANGUAGES C CXX ASM)
+
+add_library(foo STATIC "")
+target_sources(foo PRIVATE
+ src/interface.c
+)
+
diff --git a/tests/projects/c/library_with_cmakelists/foo/src/interface.c b/tests/projects/c/library_with_cmakelists/foo/src/interface.c
new file mode 100644
index 000000000..598d07560
--- /dev/null
+++ b/tests/projects/c/library_with_cmakelists/foo/src/interface.c
@@ -0,0 +1,6 @@
+#include "interface.h"
+
+int add(int a, int b)
+{
+ return a + b;
+}
diff --git a/tests/projects/c/library_with_cmakelists/foo/src/interface.h b/tests/projects/c/library_with_cmakelists/foo/src/interface.h
new file mode 100644
index 000000000..6c2aa9c2a
--- /dev/null
+++ b/tests/projects/c/library_with_cmakelists/foo/src/interface.h
@@ -0,0 +1,8 @@
+/*! calculate add(a, b)
+ *
+ * @param a the first argument
+ * @param b the second argument
+ *
+ * @return the result
+ */
+int add(int a, int b);
diff --git a/tests/projects/c/library_with_cmakelists/src/main.c b/tests/projects/c/library_with_cmakelists/src/main.c
new file mode 100644
index 000000000..9505a2f75
--- /dev/null
+++ b/tests/projects/c/library_with_cmakelists/src/main.c
@@ -0,0 +1,8 @@
+#include "interface.h"
+#include <stdio.h>
+
+int main(int argc, char** argv)
+{
+ printf("add(1, 2) = %d\n", add(1, 2));
+ return 0;
+}
diff --git a/tests/projects/c/library_with_cmakelists/xmake.lua b/tests/projects/c/library_with_cmakelists/xmake.lua
new file mode 100644
index 000000000..337527d0f
--- /dev/null
+++ b/tests/projects/c/library_with_cmakelists/xmake.lua
@@ -0,0 +1,25 @@
+add_rules("mode.debug", "mode.release")
+
+package("foo")
+ add_deps("cmake")
+ set_sourcedir("foo")
+ on_install(function (package)
+ local configs = {}
+ table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
+ table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
+ import("package.tools.cmake").build(package, configs, {buildir = "build"})
+ os.cp("src/*.h", package:installdir("include"))
+ os.cp("build/*.a", package:installdir("lib"))
+ end)
+ on_test(function (package)
+ assert(package:has_cincludes("interface.h"))
+ end)
+package_end()
+
+add_requires("foo")
+
+target("demo")
+ set_kind("binary")
+ add_files("src/main.c")
+ add_packages("foo")
+
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index 4b3432246..a29c4fd1f 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -514,6 +514,11 @@ function _instance:unlock()
end
end
+-- get the source directory
+function _instance:sourcedir()
+ return self:get("sourcedir")
+end
+
-- get the cached directory of this package
function _instance:cachedir()
local name = self:name():lower():gsub("::", "_")
@@ -1715,6 +1720,7 @@ function package.apis()
, "package.set_homepage"
, "package.set_description"
, "package.set_parallelize"
+ , "package.set_sourcedir"
, "package.set_installdir"
-- package.add_xxx
, "package.add_deps"
diff --git a/xmake/modules/private/action/require/impl/actions/install.lua b/xmake/modules/private/action/require/impl/actions/install.lua
index 9dcbc537b..fac545f8e 100644
--- a/xmake/modules/private/action/require/impl/actions/install.lua
+++ b/xmake/modules/private/action/require/impl/actions/install.lua
@@ -137,7 +137,10 @@ function main(package)
-- enter the working directory
local oldir = nil
- if #package:urls() > 0 then
+ local sourcedir = package:sourcedir()
+ if sourcedir then
+ oldir = os.cd(sourcedir)
+ elseif #package:urls() > 0 then
-- only one root directory? skip it
local filedirs = os.filedirs(path.join(workdir, "source", "*"))
if #filedirs == 1 and os.isdir(filedirs[1]) then