Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • CMake CMake
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,811
    • Issues 3,811
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 10
    • Merge requests 10
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar

An update will be applied May 24th, between 12PM and 1PM EDT (UTC -400). The site may be slow during that time.

  • CMake
  • CMakeCMake
  • Issues
  • #21255

Closed
Open
Created Sep 30, 2020 by alcroito@alcroitoDeveloper

Support adding configuration specific custom targets and dependencies when using Ninja Multi-Config

It would be useful to allow creation of ninja targets that are specific to a certain configuration.

One can then run add_custom_target commands or add_custom_command commands limited to a certain configuration.

Sample project showcasing the syntax:

cmake_minimum_required(VERSION 3.18)

set(CMAKE_CROSS_CONFIGS "all" CACHE STRING "" FORCE)
set(CMAKE_DEFAULT_CONFIGS "all" CACHE STRING "" FORCE)
list(GET CMAKE_CONFIGURATION_TYPES 0 first_config_type)
set(CMAKE_DEFAULT_BUILD_TYPE "${first_config_type}" CACHE STRING "")

project(test_proj CXX)

set(source_file "${CMAKE_CURRENT_BINARY_DIR}/lib.cpp")
file(WRITE "${source_file}" "int main(int argc, char** argv) {return 0;}")
add_executable(app "${source_file}")


### Simple case

foreach(config ${CMAKE_CONFIGURATION_TYPES})
    add_custom_target(app_per_config_${config}
        COMMAND ${CMAKE_COMMAND} -E echo "${config} specific command"
        )
    add_dependencies(app_per_config_${config} app:${config})  # <--------------------- new syntax
endforeach()


### More complicated case with add_custom_command

foreach(config ${CMAKE_CONFIGURATION_TYPES})
    add_custom_target(app_prepare_${config})
    add_dependencies(app_prepare_${config} app:${config}) # <------------------------- new syntax

    set(script_timestamp_file "${CMAKE_CURRENT_BINARY_DIR}/script_timestamp_${config}.txt")
    add_custom_command(
        OUTPUT "${script_timestamp_file}"
        DEPENDS
            app_prepare_${config}
        COMMAND
            ${CMAKE_COMMAND} -E touch "${script_timestamp_file}"
        VERBATIM
    )

    add_custom_target(app_post_per_config DEPENDS "${script_timestamp_file}")
    add_dependencies(app_post_per_config app)
endforeach()

This is slightly related to #12877 (closed) because it would allow creating custom commands targeting a specific configuration.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking