From f94b1d033afe94af4e53c7a0f0fe069d61b352ad Mon Sep 17 00:00:00 2001 From: davidlion Date: Wed, 16 Apr 2025 23:40:15 -0400 Subject: [PATCH 1/8] feat(taskfile): Add `cmake:setup-deps` to install all dependencies and write their settings files. --- exports/taskfiles/utils/cmake.yaml | 57 ++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/exports/taskfiles/utils/cmake.yaml b/exports/taskfiles/utils/cmake.yaml index d7eb7a8..b85c0af 100644 --- a/exports/taskfiles/utils/cmake.yaml +++ b/exports/taskfiles/utils/cmake.yaml @@ -1,6 +1,7 @@ version: "3" includes: + misc: "misc.yaml" remote: "remote.yaml" set: ["u", "pipefail"] @@ -86,19 +87,24 @@ tasks: # Runs the CMake install step for the given build directory. The caller must have previously # called `build` on `BUILD_DIR` for this task to succeed. We purposely omit `sources` and - # `generates` as we defer to `cmake` to decide whether it should perform any actions. + # `generates` as we defer to `cmake` to decide whether it should perform any actions. If + # `CMAKE_SETTINGS_DIR` exists a file containing the CMake project_ROOT variable will be written. # # @param {string} BUILD_DIR Directory containing the completed build to use. # @param {string} INSTALL_PREFIX Path prefix of where the project should be installed. + # @param {string} NAME CMake project name (used in directory names and CMake settings). + # @param {string} [CMAKE_SETTINGS_DIR] Directory to write the project's CMake settings file in. # @param {string[]} [EXTRA_ARGS] Any additional arguments to pass to the install command. install: internal: true label: "{{.TASK}}:{{.BUILD_DIR}}-{{.INSTALL_PREFIX}}-{{.EXTRA_ARGS}}" vars: + CMAKE_SETTINGS_DIR: >- + {{default "" .CMAKE_SETTINGS_DIR}} EXTRA_ARGS: ref: "default (list) .EXTRA_ARGS" requires: - vars: ["BUILD_DIR", "INSTALL_PREFIX"] + vars: ["BUILD_DIR", "INSTALL_PREFIX", "NAME"] cmds: - >- cmake @@ -107,6 +113,14 @@ tasks: {{- range .EXTRA_ARGS}} "{{.}}" {{- end}} + - >- + {{- if .CMAKE_SETTINGS_DIR}} + echo "set({{.NAME}}_ROOT + \"{{.INSTALL_PREFIX}}\" + CACHE PATH + \"Path to {{.NAME}} settings.\" + )" >> "{{.CMAKE_SETTINGS_DIR}}/{{.NAME}}.cmake" + {{- end}} # Downloads a CMake project tar file from `URL` and then generates, builds, and installs the # project. We purposely omit `sources` and `generates` as we defer to `cmake` to decide whether it @@ -135,6 +149,8 @@ tasks: # @param {string[]} [TARGETS] A list of specific targets to build instead of the default target. # # CMake install parameters + # @param {string} [CMAKE_SETTINGS_DIR={{.WORK_DIR}}/cmake-settings] Directory to write the + # project's CMake settings file in. # @param {string[]} [INSTALL_ARGS] Any additional arguments to pass to the CMake install command. # @param {string} [INSTALL_PREFIX={{.WORK_DIR}}/{{.NAME}}-install] Path prefix of where the # project should be installed. @@ -163,6 +179,8 @@ tasks: ref: "default (list) .TARGETS" # CMake install parameters + CMAKE_SETTINGS_DIR: >- + {{default (printf "%s/cmake-settings" .WORK_DIR) .CMAKE_SETTINGS_DIR}} INSTALL_ARGS: ref: "default (list) .INSTALL_ARGS" INSTALL_PREFIX: >- @@ -193,6 +211,41 @@ tasks: - task: "install" vars: BUILD_DIR: "{{.BUILD_DIR}}" + CMAKE_SETTINGS_DIR: "{{.CMAKE_SETTINGS_DIR}}" EXTRA_ARGS: ref: ".INSTALL_ARGS" INSTALL_PREFIX: "{{.INSTALL_PREFIX}}" + NAME: "{{.NAME}}" + + # Setup all CMake dependencies for a project by: + # 1. Create a directory to contain all CMake settings files (CMAKE_SETTINGS_DIR). + # 2. Install all dependencies by running DEP_TASK. + # 3. Include each dependency's settings file in a combined settings file (CMAKE_SETTINGS_FILE) + # for use inside a CMake project. + # + # @param {string} CMAKE_SETTINGS_DIR A directory path to write CMake settings files to. + # @param {string} DEP_TASK A task to run that will install all dependencies. + # - The task name must be qualified from the root of the project. + # - The task must not require any arguments (to use a task with arguments create a new task that + # calls the original with any arguments set). + # - Dependencies must write their settings file to CMAKE_SETTINGS_DIR to be included into the + # combined settings file (CMAKE_SETTINGS_FILE). + # @param {string} [CMAKE_SETTINGS_FILE] + setup-deps: + internal: true + label: "{{.TASK}}:{{.CMAKE_SETTINGS_DIR}}-{{.DEP_TASK}}" + vars: + CMAKE_SETTINGS_FILE: >- + {{default (printf "%s/settings.cmake" .CMAKE_SETTINGS_DIR) .CMAKE_SETTINGS_FILE}} + requires: + vars: ["CMAKE_SETTINGS_DIR", "DEP_TASK"] + cmds: + - "rm -rf {{.CMAKE_SETTINGS_DIR}}" + - "mkdir -p {{.CMAKE_SETTINGS_DIR}}" + - task: "::{{.DEP_TASK}}" + - >- + for file in {{.CMAKE_SETTINGS_DIR}}/*.cmake; do + if [ "$file" != "{{.CMAKE_SETTINGS_FILE}}" ]; then + echo "include(\"$file\")" >> "{{.CMAKE_SETTINGS_FILE}}"; + fi + done From 00633c2ce657ac401949d70dd058e1ba2ec683a2 Mon Sep 17 00:00:00 2001 From: davidlion Date: Thu, 17 Apr 2025 00:50:23 -0400 Subject: [PATCH 2/8] Remove dead misc include. --- exports/taskfiles/utils/cmake.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/exports/taskfiles/utils/cmake.yaml b/exports/taskfiles/utils/cmake.yaml index b85c0af..4b3ceb2 100644 --- a/exports/taskfiles/utils/cmake.yaml +++ b/exports/taskfiles/utils/cmake.yaml @@ -1,7 +1,6 @@ version: "3" includes: - misc: "misc.yaml" remote: "remote.yaml" set: ["u", "pipefail"] From 422d25f97df6516c307002b8ff60464496952716 Mon Sep 17 00:00:00 2001 From: davidlion Date: Thu, 17 Apr 2025 01:05:19 -0400 Subject: [PATCH 3/8] Address coderabbit doc string issues. --- exports/taskfiles/utils/cmake.yaml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/exports/taskfiles/utils/cmake.yaml b/exports/taskfiles/utils/cmake.yaml index 4b3ceb2..70dbb1d 100644 --- a/exports/taskfiles/utils/cmake.yaml +++ b/exports/taskfiles/utils/cmake.yaml @@ -92,7 +92,8 @@ tasks: # @param {string} BUILD_DIR Directory containing the completed build to use. # @param {string} INSTALL_PREFIX Path prefix of where the project should be installed. # @param {string} NAME CMake project name (used in directory names and CMake settings). - # @param {string} [CMAKE_SETTINGS_DIR] Directory to write the project's CMake settings file in. + # @param {string} [CMAKE_SETTINGS_DIR] If set, the directory to write the project's CMake settings + # file in. # @param {string[]} [EXTRA_ARGS] Any additional arguments to pass to the install command. install: internal: true @@ -148,8 +149,8 @@ tasks: # @param {string[]} [TARGETS] A list of specific targets to build instead of the default target. # # CMake install parameters - # @param {string} [CMAKE_SETTINGS_DIR={{.WORK_DIR}}/cmake-settings] Directory to write the - # project's CMake settings file in. + # @param {string} [CMAKE_SETTINGS_DIR={{.WORK_DIR}}/cmake-settings] If set, the directory to write + # the project's CMake settings file in. # @param {string[]} [INSTALL_ARGS] Any additional arguments to pass to the CMake install command. # @param {string} [INSTALL_PREFIX={{.WORK_DIR}}/{{.NAME}}-install] Path prefix of where the # project should be installed. @@ -230,6 +231,8 @@ tasks: # - Dependencies must write their settings file to CMAKE_SETTINGS_DIR to be included into the # combined settings file (CMAKE_SETTINGS_FILE). # @param {string} [CMAKE_SETTINGS_FILE] + # @param {string} [CMAKE_SETTINGS_FILE={{.CMAKE_SETTINGS_DIR}}/settings.cmake] The file to write + # that includes each dependency's settings file. setup-deps: internal: true label: "{{.TASK}}:{{.CMAKE_SETTINGS_DIR}}-{{.DEP_TASK}}" From bafab28d7b3c040f9df5c121c9a479f4e9980088 Mon Sep 17 00:00:00 2001 From: davidlion Date: Fri, 18 Apr 2025 11:16:51 -0400 Subject: [PATCH 4/8] Apply suggestions from code review. Co-authored-by: kirkrodrigues <2454684+kirkrodrigues@users.noreply.github.com> --- exports/taskfiles/utils/cmake.yaml | 39 ++++++++++++++++-------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/exports/taskfiles/utils/cmake.yaml b/exports/taskfiles/utils/cmake.yaml index 70dbb1d..98ae313 100644 --- a/exports/taskfiles/utils/cmake.yaml +++ b/exports/taskfiles/utils/cmake.yaml @@ -149,8 +149,8 @@ tasks: # @param {string[]} [TARGETS] A list of specific targets to build instead of the default target. # # CMake install parameters - # @param {string} [CMAKE_SETTINGS_DIR={{.WORK_DIR}}/cmake-settings] If set, the directory to write - # the project's CMake settings file in. + # @param {string} [CMAKE_SETTINGS_DIR={{.WORK_DIR}}/cmake-settings] The directory where the + # project's CMake settings file should be stored. # @param {string[]} [INSTALL_ARGS] Any additional arguments to pass to the CMake install command. # @param {string} [INSTALL_PREFIX={{.WORK_DIR}}/{{.NAME}}-install] Path prefix of where the # project should be installed. @@ -217,22 +217,22 @@ tasks: INSTALL_PREFIX: "{{.INSTALL_PREFIX}}" NAME: "{{.NAME}}" - # Setup all CMake dependencies for a project by: - # 1. Create a directory to contain all CMake settings files (CMAKE_SETTINGS_DIR). - # 2. Install all dependencies by running DEP_TASK. - # 3. Include each dependency's settings file in a combined settings file (CMAKE_SETTINGS_FILE) - # for use inside a CMake project. + # Sets up all CMake dependencies for a project by: # - # @param {string} CMAKE_SETTINGS_DIR A directory path to write CMake settings files to. - # @param {string} DEP_TASK A task to run that will install all dependencies. - # - The task name must be qualified from the root of the project. - # - The task must not require any arguments (to use a task with arguments create a new task that + # 1. creating a directory to contain all CMake settings files (CMAKE_SETTINGS_DIR). + # 2. installing all dependencies by running `DEP_TASK`. + # 3. combining each dependency's settings file into a single settings file (CMAKE_SETTINGS_FILE) + # for use inside a CMake project. + # + # @param {string} CMAKE_SETTINGS_DIR The directory where CMake settings files should be stored. + # @param {string} DEP_TASK The task to run that will install all dependencies. NOTE: + # - The task name must be qualified from the root of the project. + # - The task must not require any arguments (to use a task with arguments create a new task that # calls the original with any arguments set). - # - Dependencies must write their settings file to CMAKE_SETTINGS_DIR to be included into the - # combined settings file (CMAKE_SETTINGS_FILE). - # @param {string} [CMAKE_SETTINGS_FILE] - # @param {string} [CMAKE_SETTINGS_FILE={{.CMAKE_SETTINGS_DIR}}/settings.cmake] The file to write - # that includes each dependency's settings file. + # - Dependencies must write their settings file to CMAKE_SETTINGS_DIR in order to have them + # included in CMAKE_SETTINGS_FILE. + # @param {string} [CMAKE_SETTINGS_FILE={{.CMAKE_SETTINGS_DIR}}/all.cmake] The file in which to + # combine each dependency's settings file. setup-deps: internal: true label: "{{.TASK}}:{{.CMAKE_SETTINGS_DIR}}-{{.DEP_TASK}}" @@ -244,10 +244,13 @@ tasks: cmds: - "rm -rf {{.CMAKE_SETTINGS_DIR}}" - "mkdir -p {{.CMAKE_SETTINGS_DIR}}" + + # NOTE: We prefix DEP_TASK with `::` assuming that this taskfile is included through the + # `utils` taskfile, and that in turn is included in the user's taskfile. - task: "::{{.DEP_TASK}}" - - >- + - |- for file in {{.CMAKE_SETTINGS_DIR}}/*.cmake; do - if [ "$file" != "{{.CMAKE_SETTINGS_FILE}}" ]; then + if [[ "$file" != "{{.CMAKE_SETTINGS_FILE}}" ]]; then echo "include(\"$file\")" >> "{{.CMAKE_SETTINGS_FILE}}"; fi done From 92d388dd27acb5a0823c6dce2d173fb0e0ae87d4 Mon Sep 17 00:00:00 2001 From: davidlion Date: Fri, 18 Apr 2025 11:19:53 -0400 Subject: [PATCH 5/8] Apply review suggestion for install doc string. --- exports/taskfiles/utils/cmake.yaml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/exports/taskfiles/utils/cmake.yaml b/exports/taskfiles/utils/cmake.yaml index 98ae313..117978f 100644 --- a/exports/taskfiles/utils/cmake.yaml +++ b/exports/taskfiles/utils/cmake.yaml @@ -85,15 +85,18 @@ tasks: {{- end}} # Runs the CMake install step for the given build directory. The caller must have previously - # called `build` on `BUILD_DIR` for this task to succeed. We purposely omit `sources` and - # `generates` as we defer to `cmake` to decide whether it should perform any actions. If - # `CMAKE_SETTINGS_DIR` exists a file containing the CMake project_ROOT variable will be written. + # called `build` on `BUILD_DIR` for this task to succeed. If `CMAKE_SETTINGS_DIR` is set, a + # settings file will be created in that directory, containing a `{{.NAME}}_ROOT` CMake variable + # that points to `INSTALL_PREFIX`. + # + # NOTE: We purposely omit `sources` and `generates` as we defer to `cmake` to decide whether it + # should perform any actions. # # @param {string} BUILD_DIR Directory containing the completed build to use. # @param {string} INSTALL_PREFIX Path prefix of where the project should be installed. - # @param {string} NAME CMake project name (used in directory names and CMake settings). - # @param {string} [CMAKE_SETTINGS_DIR] If set, the directory to write the project's CMake settings - # file in. + # @param {string} NAME CMake project name (used in directory names and the CMake settings file). + # @param {string} [CMAKE_SETTINGS_DIR] If set, the directory where the project's CMake settings + # file should be stored. # @param {string[]} [EXTRA_ARGS] Any additional arguments to pass to the install command. install: internal: true From d7443558ff6d70001439e8e1728e90a3af8e2c93 Mon Sep 17 00:00:00 2001 From: davidlion Date: Mon, 21 Apr 2025 00:16:33 -0400 Subject: [PATCH 6/8] Apply review suggestion. --- exports/taskfiles/utils/cmake.yaml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/exports/taskfiles/utils/cmake.yaml b/exports/taskfiles/utils/cmake.yaml index 117978f..1a9365c 100644 --- a/exports/taskfiles/utils/cmake.yaml +++ b/exports/taskfiles/utils/cmake.yaml @@ -118,11 +118,9 @@ tasks: {{- end}} - >- {{- if .CMAKE_SETTINGS_DIR}} - echo "set({{.NAME}}_ROOT - \"{{.INSTALL_PREFIX}}\" - CACHE PATH - \"Path to {{.NAME}} settings.\" - )" >> "{{.CMAKE_SETTINGS_DIR}}/{{.NAME}}.cmake" + cat <> "{{.CMAKE_SETTINGS_DIR}}/{{.NAME}}.cmake" + set({{.NAME}}_ROOT "{{.INSTALL_PREFIX}}" CACHE PATH "Package root for {{.NAME}}.") + EOF {{- end}} # Downloads a CMake project tar file from `URL` and then generates, builds, and installs the @@ -236,7 +234,7 @@ tasks: # included in CMAKE_SETTINGS_FILE. # @param {string} [CMAKE_SETTINGS_FILE={{.CMAKE_SETTINGS_DIR}}/all.cmake] The file in which to # combine each dependency's settings file. - setup-deps: + install-deps-and-generate-settings: internal: true label: "{{.TASK}}:{{.CMAKE_SETTINGS_DIR}}-{{.DEP_TASK}}" vars: From aae90ca867a0e32f812a7b53948f7d4454fdb03c Mon Sep 17 00:00:00 2001 From: davidlion Date: Mon, 21 Apr 2025 00:25:36 -0400 Subject: [PATCH 7/8] Revert here doc change. --- exports/taskfiles/utils/cmake.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/exports/taskfiles/utils/cmake.yaml b/exports/taskfiles/utils/cmake.yaml index 1a9365c..6ddff4a 100644 --- a/exports/taskfiles/utils/cmake.yaml +++ b/exports/taskfiles/utils/cmake.yaml @@ -118,9 +118,11 @@ tasks: {{- end}} - >- {{- if .CMAKE_SETTINGS_DIR}} - cat <> "{{.CMAKE_SETTINGS_DIR}}/{{.NAME}}.cmake" - set({{.NAME}}_ROOT "{{.INSTALL_PREFIX}}" CACHE PATH "Package root for {{.NAME}}.") - EOF + echo "set({{.NAME}}_ROOT + \"{{.INSTALL_PREFIX}}\" + CACHE PATH + \"Package root for {{.NAME}}.\" + )" >> "{{.CMAKE_SETTINGS_DIR}}/{{.NAME}}.cmake" {{- end}} # Downloads a CMake project tar file from `URL` and then generates, builds, and installs the From 7b1717c0743bb3fee6033219c61d5ad6bfd2667b Mon Sep 17 00:00:00 2001 From: davidlion Date: Mon, 21 Apr 2025 02:09:33 -0400 Subject: [PATCH 8/8] Fix settings -> all. --- exports/taskfiles/utils/cmake.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exports/taskfiles/utils/cmake.yaml b/exports/taskfiles/utils/cmake.yaml index 6ddff4a..6638dbc 100644 --- a/exports/taskfiles/utils/cmake.yaml +++ b/exports/taskfiles/utils/cmake.yaml @@ -241,7 +241,7 @@ tasks: label: "{{.TASK}}:{{.CMAKE_SETTINGS_DIR}}-{{.DEP_TASK}}" vars: CMAKE_SETTINGS_FILE: >- - {{default (printf "%s/settings.cmake" .CMAKE_SETTINGS_DIR) .CMAKE_SETTINGS_FILE}} + {{default (printf "%s/all.cmake" .CMAKE_SETTINGS_DIR) .CMAKE_SETTINGS_FILE}} requires: vars: ["CMAKE_SETTINGS_DIR", "DEP_TASK"] cmds: