summaryrefslogtreecommitdiff
path: root/rules/CC/foreign/cmake
diff options
context:
space:
mode:
authorOliver Reiche <oliver.reiche@huawei.com>2023-05-30 15:38:40 +0200
committerOliver Reiche <oliver.reiche@huawei.com>2023-05-30 15:38:40 +0200
commit14300d3768522b1a201c30c94b6e54e096520b20 (patch)
treeeaa057fd88ddba1a94c48585fcfcbb71628fcbe7 /rules/CC/foreign/cmake
parent2d7051782625966857286aace6ff18760114ecc7 (diff)
parent9f535dadf06c6c6554bac632069777cf1b63ebf5 (diff)
downloadrules-cc-14300d3768522b1a201c30c94b6e54e096520b20.tar.gz
Merge commit '9f535dadf06c6c6554bac632069777cf1b63ebf5' into rules/rules-cc
Diffstat (limited to 'rules/CC/foreign/cmake')
-rw-r--r--rules/CC/foreign/cmake/EXPRESSIONS80
-rw-r--r--rules/CC/foreign/cmake/RULES18
2 files changed, 73 insertions, 25 deletions
diff --git a/rules/CC/foreign/cmake/EXPRESSIONS b/rules/CC/foreign/cmake/EXPRESSIONS
index 8977d5a..4c21f4b 100644
--- a/rules/CC/foreign/cmake/EXPRESSIONS
+++ b/rules/CC/foreign/cmake/EXPRESSIONS
@@ -1,6 +1,7 @@
{ "cmake-build":
{ "vars":
[ "source_dir"
+ , "cmake_subdir"
, "cmake_options"
, "cmake_defines"
, "cmake_jobs"
@@ -27,11 +28,24 @@
, "default-LDFLAGS": ["CC", "default-LDFLAGS"]
, "default-AR": ["CC", "default-AR"]
, "default-ENV": ["CC", "default-ENV"]
+ , "default-TOOLCHAIN": ["CC", "default-TOOLCHAIN"]
+ , "default-NON_SYSTEM_TOOLS": ["CC", "default-NON_SYSTEM_TOOLS"]
}
, "expression":
{ "type": "let*"
, "bindings":
- [ [ "CMAKE_FLAGS"
+ [ ["TOOLCHAIN_DIR", "toolchain"]
+ , ["TOOLCHAIN", {"type": "CALL_EXPRESSION", "name": "default-TOOLCHAIN"}]
+ , [ "TOOLCHAIN"
+ , { "type": "to_subdir"
+ , "subdir": {"type": "var", "name": "TOOLCHAIN_DIR"}
+ , "$1": {"type": "var", "name": "TOOLCHAIN"}
+ }
+ ]
+ , [ "NON_SYSTEM_TOOLS"
+ , {"type": "CALL_EXPRESSION", "name": "default-NON_SYSTEM_TOOLS"}
+ ]
+ , [ "CMAKE_FLAGS"
, { "type": "++"
, "$1":
[ { "type": "foreach"
@@ -47,6 +61,7 @@
, "cond": {"type": "var", "name": "BUILD_POSITION_INDEPENDENT"}
, "then": ["-DCMAKE_POSITION_INDEPENDENT_CODE=ON"]
}
+ , ["-DCMAKE_INSTALL_RPATH=$ORIGIN;$ORIGIN/../lib"]
]
}
]
@@ -84,26 +99,35 @@
, [ "ENV"
, { "type": "map_union"
, "$1":
- { "type": "++"
- , "$1":
- [ {"type": "CALL_EXPRESSION", "name": "default-ENV"}
- , [ { "type": "var"
- , "name": "ENV"
- , "default": {"type": "empty_map"}
- }
- ]
- , [ { "type": "env"
- , "vars": ["CC", "CXX", "CXXFLAGS", "CFLAGS", "LDFLAGS"]
- }
- ]
- ]
- }
+ [ {"type": "CALL_EXPRESSION", "name": "default-ENV"}
+ , {"type": "var", "name": "ENV", "default": {"type": "empty_map"}}
+ , { "type": "env"
+ , "vars": ["CC", "CXX", "CXXFLAGS", "CFLAGS", "LDFLAGS"]
+ }
+ ]
}
]
, [ "AR"
, { "type": "var"
, "name": "AR"
- , "default": {"type": "CALL_EXPRESSION", "name": "default-AR"}
+ , "default":
+ { "type": "join"
+ , "$1":
+ { "type": "++"
+ , "$1":
+ [ { "type": "if"
+ , "cond":
+ { "type": "lookup"
+ , "key": "AR"
+ , "map": {"type": "var", "name": "NON_SYSTEM_TOOLS"}
+ }
+ , "then":
+ ["./", {"type": "var", "name": "TOOLCHAIN_DIR"}, "/"]
+ }
+ , {"type": "CALL_EXPRESSION", "name": "default-AR"}
+ ]
+ }
+ }
}
]
, [ "CMAKE_JOBS"
@@ -121,6 +145,12 @@
]
}
]
+ , [ "CMAKE_SUBDIR"
+ , { "type": "join"
+ , "separator": "/"
+ , "$1": {"type": "var", "name": "cmake_subdir", "default": []}
+ }
+ ]
, [ "script"
, { "type": "singleton_map"
, "key": "run_cmake.sh"
@@ -147,9 +177,10 @@
]
}
}
- , [ "readonly CMAKE_AR=$(which $1)"
- , "shift"
- , "cmake \"$@\" -Ssource -Bbuild -DCMAKE_AR=${CMAKE_AR} -DCMAKE_INSTALL_PREFIX=./install >configure.log || (cat configure.log && exit 1)"
+ , [ "readonly CMAKE_SUBDIR=\"$1\""
+ , "readonly CMAKE_AR=$(which $2)"
+ , "shift 2"
+ , "cmake \"$@\" -S\"source/${CMAKE_SUBDIR}\" -Bbuild -DCMAKE_AR=${CMAKE_AR} -DCMAKE_INSTALL_PREFIX=./install >configure.log 2>&1 || (cat configure.log && exit 1)"
]
, [ { "type": "join"
, "separator": " "
@@ -157,7 +188,7 @@
{ "type": "++"
, "$1":
[ {"type": "var", "name": "CMAKE_JOBS"}
- , [ "cmake --build build --target install >build.log || (cat configure.log build.log && exit 1)"
+ , [ "cmake --build build --target install >build.log 2>&1 || (cat configure.log build.log && exit 1)"
]
]
}
@@ -192,14 +223,19 @@
, "inputs":
{ "type": "map_union"
, "$1":
- [ {"type": "var", "name": "source_dir"}
+ [ {"type": "var", "name": "TOOLCHAIN"}
+ , {"type": "var", "name": "source_dir"}
, {"type": "var", "name": "script"}
]
}
, "cmd":
{ "type": "++"
, "$1":
- [ ["/bin/sh", "run_cmake.sh", {"type": "var", "name": "AR"}]
+ [ [ "/bin/sh"
+ , "run_cmake.sh"
+ , {"type": "var", "name": "CMAKE_SUBDIR"}
+ , {"type": "var", "name": "AR"}
+ ]
, {"type": "var", "name": "CMAKE_FLAGS"}
]
}
diff --git a/rules/CC/foreign/cmake/RULES b/rules/CC/foreign/cmake/RULES
index 8651f4e..a53b92e 100644
--- a/rules/CC/foreign/cmake/RULES
+++ b/rules/CC/foreign/cmake/RULES
@@ -2,7 +2,8 @@
{ "doc": ["Data produced by CMake configure, build, and install."]
, "target_fields": ["project"]
, "string_fields":
- [ "options"
+ [ "subdir"
+ , "options"
, "defines"
, "jobs"
, "pre_cmds"
@@ -27,6 +28,10 @@
, "field_doc":
{ "project":
["The CMake project directory. It should contain a single tree artifact"]
+ , "subdir":
+ [ "The subdirectory that contains the entry CMakeLists.txt. Individual"
+ , "directory components are joined with \"/\"."
+ ]
, "options":
[ "CMake options for the configuration phase."
, "(e.g., [\"-GNinja\", \"-Ax64\"])"
@@ -162,6 +167,7 @@
}
}
]
+ , ["cmake_subdir", {"type": "FIELD", "name": "subdir"}]
, ["cmake_options", {"type": "FIELD", "name": "options"}]
, ["cmake_defines", {"type": "FIELD", "name": "defines"}]
, ["cmake_jobs", {"type": "FIELD", "name": "jobs"}]
@@ -218,7 +224,8 @@
{ "doc": ["Library produced by CMake configure, build, and install."]
, "target_fields": ["project", "deps"]
, "string_fields":
- [ "name"
+ [ "subdir"
+ , "name"
, "version"
, "stage"
, "options"
@@ -256,6 +263,10 @@
, "field_doc":
{ "project":
["The CMake project directory. It should contain a single tree artifact"]
+ , "subdir":
+ [ "The subdirectory that contains the entry CMakeLists.txt. Individual"
+ , "directory components are joined with \"/\"."
+ ]
, "name":
[ "The name of the library (without leading \"lib\" or trailing file name"
, "extension), also used as name for pkg-config files."
@@ -509,6 +520,7 @@
]
}
]
+ , ["cmake_subdir", {"type": "FIELD", "name": "subdir"}]
, ["cmake_options", {"type": "FIELD", "name": "options"}]
, ["cmake_defines", {"type": "FIELD", "name": "defines"}]
, ["cmake_jobs", {"type": "FIELD", "name": "jobs"}]
@@ -589,7 +601,7 @@
, "$1": {"type": "FIELD", "name": "stage"}
}
]
- , ["deps-fieldnames", ["deps"]]
+ , ["deps-fieldnames", ["deps", "defaults"]]
]
, "body": {"type": "CALL_EXPRESSION", "name": "prebuilt result"}
}