Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
CMake
CMake
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,198
    • Issues 3,198
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 16
    • Merge Requests 16
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI / CD
    • Repository
    • Value Stream
  • External Wiki
    • External Wiki
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • CMake
  • CMakeCMake
  • Issues
  • #21694

Closed
Open
Opened Jan 12, 2021 by Marc Chevrier@marc.chevrierMaintainer

add_custom_command(DEPFILE): inconsistent dependencies for Ninja generator

When a custom command output is used as input source to add_library() or add_executable(), there is potentially some inconsistency on how dependencies are defined.

In the depfile associated to the custom command, output file can be specified as an absolute path. But, in the ninja file rules.ninja, paths are expressed as relative to the build directory when possible.
As a result, successive launch of ninja relaunch the execution of the custom command and all dependent actions.

Here a snippet showing the problem:

cmake_minimum_required(VERSION 3.1...3.20)

project(NinjaDepfile C)

file (WRITE "${CMAKE_CURRENT_BINARY_DIR}/source.c" "#include \"source.h\"\n void f() {}\n")
file (WRITE "${CMAKE_CURRENT_BINARY_DIR}/source.h" "\n")

file (WRITE "${CMAKE_CURRENT_BINARY_DIR}/source.c.dep" "${CMAKE_CURRENT_BINARY_DIR}/source.c : ${CMAKE_CURRENT_BINARY_DIR}/source.h")

add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/source.c"
  COMMAND "${CMAKE_COMMAND}" -E touch "${CMAKE_BINARY_DIR}/source.c"
  DEPFILE "${CMAKE_BINARY_DIR}/source.c.dep")

add_library (ouput SHARED "${CMAKE_CURRENT_BINARY_DIR}/source.c")
To upload designs, you'll need to enable LFS and have admin enable hashed storage. More information
Assignee
Assign to
3.20.0
Milestone
3.20.0
Assign milestone
Time tracking
None
Due date
None
Reference: cmake/cmake#21694