summaryrefslogtreecommitdiff
path: root/CC/foreign/cmake
diff options
context:
space:
mode:
authorOliver Reiche <oliver.reiche@huawei.com>2023-06-30 18:50:54 +0200
committerOliver Reiche <oliver.reiche@huawei.com>2023-07-10 11:26:29 +0200
commitfc702619ed6547609a8ac2bf6753858942bb6524 (patch)
tree6299ac8f786bef26ca95a6e690a9ab3e08f773e1 /CC/foreign/cmake
parent70a667e465c1e4d09af4c76d7c49ad5b8cf438fa (diff)
downloadrules-cc-fc702619ed6547609a8ac2bf6753858942bb6524.tar.gz
foreign: Support expanding env variables in options
Diffstat (limited to 'CC/foreign/cmake')
-rw-r--r--CC/foreign/cmake/EXPRESSIONS29
-rw-r--r--CC/foreign/cmake/RULES48
2 files changed, 61 insertions, 16 deletions
diff --git a/CC/foreign/cmake/EXPRESSIONS b/CC/foreign/cmake/EXPRESSIONS
index ae05337..c0b5712 100644
--- a/CC/foreign/cmake/EXPRESSIONS
+++ b/CC/foreign/cmake/EXPRESSIONS
@@ -1,6 +1,8 @@
{ "cmake-build":
{ "vars":
- [ "source_dir"
+ [ "ARCH"
+ , "HOST_ARCH"
+ , "source_dir"
, "cmake_subdir"
, "localbase_dir"
, "cmake_options"
@@ -19,6 +21,8 @@
, "ENV"
, "AR"
, "BUILD_POSITION_INDEPENDENT"
+ , "defaults-transition"
+ , "host-defaults-transition"
]
, "imports":
{ "artifacts": ["", "field_artifacts"]
@@ -31,11 +35,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"
@@ -165,8 +180,9 @@
, "$1":
[ [ "set -eu"
, "mkdir scratch"
- , "readonly TMPDIR=\"$(pwd)/scratch\""
- , "readonly LOCALBASE=\"$(pwd)/localbase\""
+ , "readonly ROOT=\"$(pwd)\""
+ , "export TMPDIR=\"$(pwd)/scratch\""
+ , "export LOCALBASE=\"$(pwd)/localbase\""
]
, { "type": "if"
, "cond": {"type": "var", "name": "pre_cmds"}
@@ -182,7 +198,7 @@
, [ "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=\"$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 -- 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"
, "separator": " "
@@ -190,7 +206,7 @@
{ "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 -- cmake --build build --target install >build.log 2>&1 || (cat configure.log build.log && exit 1)"
]
]
}
@@ -227,6 +243,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/CC/foreign/cmake/RULES b/CC/foreign/cmake/RULES
index 170026f..87805d5 100644
--- a/CC/foreign/cmake/RULES
+++ b/CC/foreign/cmake/RULES
@@ -2,8 +2,10 @@
{ "doc":
[ "Data produced by CMake configure, build, and install."
, ""
- , "Commands have access to a unique temporary directory via \"$TMPDIR\""
- , "and to the installed \"deps\" via \"$LOCALBASE\"."
+ , "All variables accessible to commands and options are: \"TMPDIR\","
+ , "\"LOCALBASE\", \"CC\", \"CXX\", \"CFLAGS\", \"CXXFLAGS\", and"
+ , "\"LDFLAGS\". \"LOCALBASE\" contains the path to the installed artifacts"
+ , "from \"deps\"."
]
, "target_fields": ["project"]
, "string_fields":
@@ -17,7 +19,9 @@
, "out_dirs"
]
, "config_vars":
- [ "CC"
+ [ "ARCH"
+ , "HOST_ARCH"
+ , "CC"
, "CXX"
, "CFLAGS"
, "CXXFLAGS"
@@ -139,6 +143,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*"
@@ -184,6 +193,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"}
]
@@ -235,8 +248,10 @@
{ "doc":
[ "Library produced by CMake configure, build, and install."
, ""
- , "Commands have access to a unique temporary directory via \"$TMPDIR\""
- , "and to the installed \"deps\" via \"$LOCALBASE\"."
+ , "All variables accessible to commands and options are: \"TMPDIR\","
+ , "\"LOCALBASE\", \"CC\", \"CXX\", \"CFLAGS\", \"CXXFLAGS\", and"
+ , "\"LDFLAGS\". \"LOCALBASE\" contains the path to the installed artifacts"
+ , "from \"deps\"."
]
, "target_fields": ["project", "deps"]
, "string_fields":
@@ -260,7 +275,9 @@
, "pc_prefix"
]
, "config_vars":
- [ "CC"
+ [ "ARCH"
+ , "HOST_ARCH"
+ , "CC"
, "CXX"
, "CFLAGS"
, "CXXFLAGS"
@@ -293,12 +310,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"
@@ -428,6 +447,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*"
@@ -562,6 +586,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"}
]