diff --git a/taskfiles/utils-cmake.yaml b/taskfiles/utils-cmake.yaml index 0bec4d4..898666e 100644 --- a/taskfiles/utils-cmake.yaml +++ b/taskfiles/utils-cmake.yaml @@ -16,6 +16,13 @@ tasks: cmake-build: internal: true label: "{{.TASK}}:{{.BUILD_DIR}}-{{.TARGETS}}-{{.EXTRA_ARGS}}" + vars: + EXTRA_ARGS: + ref: "default (list) .EXTRA_ARGS" + JOBS: >- + {{default "" .JOBS}} + TARGETS: + ref: "default (list) .TARGETS" requires: vars: ["BUILD_DIR"] cmds: @@ -37,6 +44,9 @@ tasks: # @param {string[]} [EXTRA_ARGS] Any additional arguments to pass with the clean target. cmake-clean: internal: true + vars: + EXTRA_ARGS: + ref: "default (list) .EXTRA_ARGS" requires: vars: ["BUILD_DIR"] cmds: @@ -44,7 +54,7 @@ tasks: vars: BUILD_DIR: "{{.BUILD_DIR}}" EXTRA_ARGS: - ref: "default (list) .EXTRA_ARGS" + ref: ".EXTRA_ARGS" TARGETS: ["clean"] # Runs the CMake generate step for the given source and build directories. We purposely omit @@ -57,6 +67,9 @@ tasks: cmake-generate: internal: true label: "{{.TASK}}:{{.SOURCE_DIR}}-{{.BUILD_DIR}}-{{.EXTRA_ARGS}}" + vars: + EXTRA_ARGS: + ref: "default (list) .EXTRA_ARGS" requires: vars: ["BUILD_DIR", "SOURCE_DIR"] cmds: @@ -78,6 +91,9 @@ tasks: cmake-install: internal: true label: "{{.TASK}}:{{.BUILD_DIR}}-{{.INSTALL_PREFIX}}-{{.EXTRA_ARGS}}" + vars: + EXTRA_ARGS: + ref: "default (list) .EXTRA_ARGS" requires: vars: ["BUILD_DIR", "INSTALL_PREFIX"] cmds: @@ -88,3 +104,92 @@ tasks: {{- range .EXTRA_ARGS}} "{{.}}" {{- 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 + # should perform any actions. However, the download and extraction will be skipped if unnecessary. + # + # General parameters + # @param {string} NAME Project name (used in directory names). + # @param {string} [SOURCE_DIR={{.WORK_DIR}}/{{.NAME}}-src] Directory in which to extract the tar + # file. + # @param {string} [WORK_DIR={{.TASK_DIR}}] Base directory to store the build, install, and src + # directories inside. + # + # Download parameters + # @param {string} FILE_SHA256 Content hash to verify the downloaded tar file against. + # @param {string} URL + # + # CMake generate parameters + # @param {string[]} [GEN_ARGS] Any additional arguments to pass to the CMake generate command. + # + # CMake build parameters + # @param {string[]} [BUILD_ARGS] Any additional arguments to pass to the CMake build command. + # @param {string} [BUILD_DIR={{.WORK_DIR}}/{{.NAME}}-build] Directory in which to generate the + # build system and perform the build. + # @param {int} [JOBS] The maximum number of concurrent processes to use when building. If + # omitted, the native build tool's default number is used. See `man cmake`. + # @param {string[]} [TARGETS] A list of specific targets to build instead of the default target. + # + # CMake install parameters + # @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. + cmake-install-remote-tar: + internal: true + label: "{{.TASK}}:{{.NAME}}-{{.URL}}-{{.INSTALL_PREFIX}}" + vars: + # General parameters + WORK_DIR: >- + {{default .ROOT_DIR .WORK_DIR}} + SOURCE_DIR: >- + {{default (printf "%s/%s-src" .WORK_DIR .NAME) .SOURCE_DIR}} + + # CMake generate parameters + GEN_ARGS: + ref: "default (list) .GEN_ARGS" + + # CMake build parameters + BUILD_ARGS: + ref: "default (list) .BUILD_ARGS" + BUILD_DIR: >- + {{default (printf "%s/%s-build" .WORK_DIR .NAME) .BUILD_DIR}} + JOBS: >- + {{default "" .JOBS}} + TARGETS: + ref: "default (list) .TARGETS" + + # CMake install parameters + INSTALL_ARGS: + ref: "default (list) .INSTALL_ARGS" + INSTALL_PREFIX: >- + {{default (printf "%s/%s-install" .WORK_DIR .NAME) .INSTALL_PREFIX}} + requires: + vars: ["FILE_SHA256", "NAME", "URL"] + deps: + - task: ":utils:download-and-extract-tar" + vars: + FILE_SHA256: "{{.FILE_SHA256}}" + OUTPUT_DIR: "{{.SOURCE_DIR}}" + URL: "{{.URL}}" + cmds: + - task: ":utils:cmake-generate" + vars: + BUILD_DIR: "{{.BUILD_DIR}}" + EXTRA_ARGS: + ref: ".GEN_ARGS" + SOURCE_DIR: "{{.SOURCE_DIR}}" + - task: ":utils:cmake-build" + vars: + BUILD_DIR: "{{.BUILD_DIR}}" + EXTRA_ARGS: + ref: ".BUILD_ARGS" + JOBS: "{{.JOBS}}" + TARGETS: + ref: ".TARGETS" + - task: ":utils:cmake-install" + vars: + BUILD_DIR: "{{.BUILD_DIR}}" + EXTRA_ARGS: + ref: ".INSTALL_ARGS" + INSTALL_PREFIX: "{{.INSTALL_PREFIX}}"