diff options
Diffstat (limited to 'rules/CC/foreign/cmake')
-rw-r--r-- | rules/CC/foreign/cmake/EXPRESSIONS | 70 | ||||
-rw-r--r-- | rules/CC/foreign/cmake/RULES | 81 |
2 files changed, 115 insertions, 36 deletions
diff --git a/rules/CC/foreign/cmake/EXPRESSIONS b/rules/CC/foreign/cmake/EXPRESSIONS index 425c7a2..2266f61 100644 --- a/rules/CC/foreign/cmake/EXPRESSIONS +++ b/rules/CC/foreign/cmake/EXPRESSIONS @@ -1,11 +1,14 @@ { "cmake-build": { "vars": - [ "source_dir" + [ "ARCH" + , "HOST_ARCH" + , "source_dir" , "cmake_subdir" , "localbase_dir" , "cmake_options" , "cmake_defines" , "cmake_jobs" + , "cmake_targets" , "pre_cmds" , "post_cmds" , "CC" @@ -19,6 +22,8 @@ , "ENV" , "AR" , "BUILD_POSITION_INDEPENDENT" + , "defaults-transition" + , "host-defaults-transition" ] , "imports": { "artifacts": ["", "field_artifacts"] @@ -31,11 +36,22 @@ , "default-ENV": ["CC", "default-ENV"] , "default-TOOLCHAIN": ["CC", "default-TOOLCHAIN"] , "default-NON_SYSTEM_TOOLS": ["CC", "default-NON_SYSTEM_TOOLS"] + , "expand_exec_tool": ["./", "..", "expand_exec_tool"] } , "expression": { "type": "let*" , "bindings": - [ ["TOOLCHAIN_DIR", "toolchain"] + [ [ "expand_exec" + , { "type": "let*" + , "bindings": + [ [ "defaults-transition" + , {"type": "var", "name": "host-defaults-transition"} + ] + ] + , "body": {"type": "CALL_EXPRESSION", "name": "expand_exec_tool"} + } + ] + , ["TOOLCHAIN_DIR", "toolchain"] , ["TOOLCHAIN", {"type": "CALL_EXPRESSION", "name": "default-TOOLCHAIN"}] , [ "TOOLCHAIN" , { "type": "to_subdir" @@ -97,17 +113,6 @@ } } ] - , [ "ENV" - , { "type": "map_union" - , "$1": - [ {"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" @@ -131,6 +136,17 @@ } } ] + , [ "ENV" + , { "type": "map_union" + , "$1": + [ {"type": "CALL_EXPRESSION", "name": "default-ENV"} + , {"type": "var", "name": "ENV", "default": {"type": "empty_map"}} + , { "type": "env" + , "vars": ["CC", "CXX", "CXXFLAGS", "CFLAGS", "LDFLAGS", "AR"] + } + ] + } + ] , [ "CMAKE_JOBS" , { "type": "if" , "cond": {"type": "var", "name": "cmake_jobs"} @@ -152,6 +168,13 @@ , "$1": {"type": "var", "name": "cmake_subdir", "default": []} } ] + , [ "cmake_targets" + , { "type": "if" + , "cond": {"type": "var", "name": "cmake_targets"} + , "then": {"type": "var", "name": "cmake_targets"} + , "else": ["install"] + } + ] , [ "script" , { "type": "singleton_map" , "key": "run_cmake.sh" @@ -165,7 +188,9 @@ , "$1": [ [ "set -eu" , "mkdir scratch" - , "readonly TMPDIR=\"$(pwd)/scratch\"" + , "readonly ROOT=\"$(pwd)\"" + , "export TMPDIR=\"$(pwd)/scratch\"" + , "export LOCALBASE=\"$(pwd)/localbase\"" ] , { "type": "if" , "cond": {"type": "var", "name": "pre_cmds"} @@ -181,20 +206,28 @@ , [ "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 -DCMAKE_PREFIX_PATH=\"$(pwd)/localbase\" -DPKG_CONFIG_ARGN=--define-prefix --no-warn-unused-cli >configure.log 2>&1 || (cat configure.log && exit 1)" + , "${ROOT}/expand_exec TMPDIR LOCALBASE CC CXX CFLAGS CXXFLAGS LDFLAGS AR -- cmake -S\"source/${CMAKE_SUBDIR}\" -Bbuild -DCMAKE_AR=${CMAKE_AR} -DCMAKE_INSTALL_PREFIX=./install -DCMAKE_PREFIX_PATH=\"$LOCALBASE\" -DPKG_CONFIG_ARGN=--define-prefix --no-warn-unused-cli \"$@\" >configure.log 2>&1 || (cat configure.log && exit 1)" ] - , [ { "type": "join" + , { "type": "foreach" + , "range": {"type": "var", "name": "cmake_targets"} + , "var": "target" + , "body": + { "type": "join" , "separator": " " , "$1": { "type": "++" , "$1": [ {"type": "var", "name": "CMAKE_JOBS"} - , [ "cmake --build build --target install >build.log 2>&1 || (cat configure.log build.log && exit 1)" + , [ "${ROOT}/expand_exec TMPDIR LOCALBASE CC CXX CFLAGS CXXFLAGS LDFLAGS AR -- cmake --build build --target" + , { "type": "join_cmd" + , "$1": [{"type": "var", "name": "target"}] + } + , ">>build.log 2>&1 || (cat build.log && exit 1)" ] ] } } - ] + } , ["find ./install -type l -delete"] , { "type": "if" , "cond": {"type": "var", "name": "post_cmds"} @@ -226,6 +259,7 @@ , "$1": [ {"type": "var", "name": "TOOLCHAIN"} , {"type": "var", "name": "source_dir"} + , {"type": "var", "name": "expand_exec"} , { "type": "var" , "name": "localbase_dir" , "default": {"type": "empty_map"} diff --git a/rules/CC/foreign/cmake/RULES b/rules/CC/foreign/cmake/RULES index e4d16e0..63d6e48 100644 --- a/rules/CC/foreign/cmake/RULES +++ b/rules/CC/foreign/cmake/RULES @@ -1,10 +1,18 @@ { "data": - { "doc": ["Data produced by CMake configure, build, and install."] + { "doc": + [ "Data produced by CMake configure, build, and install." + , "" + , "All variables accessible to commands and options are: \"TMPDIR\"," + , "\"LOCALBASE\", \"CC\", \"CXX\", \"CFLAGS\", \"CXXFLAGS\", \"LDFLAGS\"," + , "and \"AR\". \"LOCALBASE\" contains the path to the installed artifacts" + , "from \"deps\"." + ] , "target_fields": ["project"] , "string_fields": [ "subdir" , "options" , "defines" + , "targets" , "jobs" , "pre_cmds" , "post_cmds" @@ -12,7 +20,9 @@ , "out_dirs" ] , "config_vars": - [ "CC" + [ "ARCH" + , "HOST_ARCH" + , "CC" , "CXX" , "CFLAGS" , "CXXFLAGS" @@ -41,6 +51,10 @@ [ "CMake defines for the configuration phase." , "(e.g., [\"CMAKE_BUILD_TYPE=Release\"])" ] + , "targets": + [ "The CMake targets to build in the specified order" + , "(default: [\"install\"])." + ] , "jobs": [ "Number of jobs to run simultaneously. If omitted, CMake's default" , "number is used." @@ -48,16 +62,17 @@ , "pre_cmds": [ "List of commands executed in the project directory before calling" , "CMake. Useful for renaming files or directories. Note that data" - , "between \"pre_cmds\" and \"post_cmds\" can be exchanged via $TMPDIR," - , "which is uniquely reserved for this action." + , "between \"pre_cmds\" and \"post_cmds\" can be exchanged via" + , "\"$TMPDIR\" which is uniquely reserved for this action." ] , "post_cmds": [ "List of commands executed in the install directory after successful" , "installation but before the output files are collected. Useful for" , "renaming files or directories. Note that data between \"pre_cmds\" and" - , "\"post_cmds\" can be exchanged via $TMPDIR, which is uniquely reserved" - , "for this action. The CMake source and build directory can be accessed" - , "via $CMAKE_SOURCE_DIR and $CMAKE_BINARY_DIR, respectively." + , "\"post_cmds\" can be exchanged via \"$TMPDIR\", which is uniquely" + , "reserved for this action. The CMake source and build directory can be" + , "accessed via \"$CMAKE_SOURCE_DIR\" and \"$CMAKE_BINARY_DIR\"," + , "respectively." ] , "out_files": [ "Paths to the produced output files. The paths are considered relative" @@ -133,6 +148,11 @@ { "stage_field": ["", "stage_singleton_field"] , "cmake-build": "cmake-build" , "strip-prefix": ["./", "..", "strip-prefix"] + , "for host": ["transitions", "for host"] + } + , "config_transitions": + { "defaults": + [{"type": "empty_map"}, {"type": "CALL_EXPRESSION", "name": "for host"}] } , "expression": { "type": "let*" @@ -175,9 +195,14 @@ , ["cmake_subdir", {"type": "FIELD", "name": "subdir"}] , ["cmake_options", {"type": "FIELD", "name": "options"}] , ["cmake_defines", {"type": "FIELD", "name": "defines"}] + , ["cmake_targets", {"type": "FIELD", "name": "targets"}] , ["cmake_jobs", {"type": "FIELD", "name": "jobs"}] , ["pre_cmds", {"type": "FIELD", "name": "pre_cmds"}] , ["post_cmds", {"type": "FIELD", "name": "post_cmds"}] + , ["defaults-transition", {"type": "empty_map"}] + , [ "host-defaults-transition" + , {"type": "CALL_EXPRESSION", "name": "for host"} + ] , [ "full_install_dir" , {"type": "CALL_EXPRESSION", "name": "cmake-build"} ] @@ -226,7 +251,14 @@ } } , "library": - { "doc": ["Library produced by CMake configure, build, and install."] + { "doc": + [ "Library produced by CMake configure, build, and install." + , "" + , "All variables accessible to commands and options are: \"TMPDIR\"," + , "\"LOCALBASE\", \"CC\", \"CXX\", \"CFLAGS\", \"CXXFLAGS\", \"LDFLAGS\"," + , "and \"AR\". \"LOCALBASE\" contains the path to the installed artifacts" + , "from \"deps\"." + ] , "target_fields": ["project", "deps"] , "string_fields": [ "subdir" @@ -249,7 +281,9 @@ , "pc_prefix" ] , "config_vars": - [ "CC" + [ "ARCH" + , "HOST_ARCH" + , "CC" , "CXX" , "CFLAGS" , "CXXFLAGS" @@ -282,12 +316,14 @@ , "components are joined with \".\"." ] , "options": - [ "CMake options for the configuration phase." - , "(e.g., [\"-GNinja\", \"-Ax64\"])" + [ "CMake options for the configuration phase" + , "(e.g., [\"-GNinja\", \"-Ax64\"]). Variables can be accessed via" + , "\"$(<varname>)\", e.g., \"$(TMPDIR)\" for variable \"$TMPDIR\"." ] , "defines": - [ "CMake defines for the configuration phase." - , "(e.g., [\"CMAKE_BUILD_TYPE=Release\"])" + [ "CMake defines for the configuration phase" + , "(e.g., [\"CMAKE_BUILD_TYPE=Release\"]). Variables can be accessed via" + , "\"$(<varname>)\", e.g., \"$(TMPDIR)\" for variable \"$TMPDIR\"." ] , "jobs": [ "Number of jobs to run simultaneously. If omitted, CMake's default" @@ -296,17 +332,17 @@ , "pre_cmds": [ "List of commands executed in the project directory before calling" , "CMake. Useful for renaming files or directories. Note that data" - , "between \"pre_cmds\" and \"post_cmds\" can be exchanged via $TMPDIR," - , "which is uniquely reserved for this action." + , "between \"pre_cmds\" and \"post_cmds\" can be exchanged via" + , "\"$TMPDIR\" which is uniquely reserved for this action." ] , "post_cmds": [ "List of commands executed in the install directory after successful" , "installation but before the output files are collected. Useful for" , "renaming files or directories (e.g., in case of SONAME mismatch). Note" , "that data between \"pre_cmds\" and \"post_cmds\" can be exchanged via" - , "$TMPDIR, which is uniquely reserved for this action. The CMake source" - , "and build directory can be accessed via $CMAKE_SOURCE_DIR and" - , "$CMAKE_BINARY_DIR, respectively." + , "\"$TMPDIR\", which is uniquely reserved for this action. The CMake" + , "source and build directory can be accessed via \"$CMAKE_SOURCE_DIR\"" + , "and \"$CMAKE_BINARY_DIR\", respectively." ] , "out_hdrs": [ "Paths to produced public header files. The path is considered" @@ -417,6 +453,11 @@ , "strip-prefix": ["./", "..", "strip-prefix"] , "prebuilt result": ["CC/prebuilt", "prebuilt result"] , "install-deps": ["CC", "install-with-deps stage"] + , "for host": ["transitions", "for host"] + } + , "config_transitions": + { "defaults": + [{"type": "empty_map"}, {"type": "CALL_EXPRESSION", "name": "for host"}] } , "expression": { "type": "let*" @@ -551,6 +592,10 @@ , ["cmake_jobs", {"type": "FIELD", "name": "jobs"}] , ["pre_cmds", {"type": "FIELD", "name": "pre_cmds"}] , ["post_cmds", {"type": "FIELD", "name": "post_cmds"}] + , ["defaults-transition", {"type": "empty_map"}] + , [ "host-defaults-transition" + , {"type": "CALL_EXPRESSION", "name": "for host"} + ] , [ "full_install_dir" , {"type": "CALL_EXPRESSION", "name": "cmake-build"} ] |