Skip to content

Visual Studio Generators add_dependencies creates a vacuous no-op dependency which is never satisfied

Example:

CMakeLists.txt

add_custom_target(
   DependencyName
   COMMAND ...
   WORKING_DIRECTORY ${dependencyNameWorkingDir}
   USES_TERMINAL
   COMMENT "[DependencyName] Running ..."
)

add_dependencies(${TARGET_NAME} DependencyName)

If you generate with a visual studio generator and then build twice (first for fresh, second for incremental) with no changes, a .binlog illuminates this issue:

Message <CMAKE_BINARY_DIR>\CMakeFiles\<HASH>\DependencyName.rule will be compiled because output <CMAKE_BINARY_DIR>\TOOLS\<TARGET_NAME>\CMAKEFILES\DependencyName does not exist.

This DependencyName file will never exist because nothing actually makes it.

We can hack around this with something like

file(WRITE $ENV{TMP}/fakeDependencyNameFile.txt)
configure_file($ENV{TMP}/fakeDependencyNameFile.txt ${CMAKE_BINARY_DIR}/tools/${TARGET_NAME}/CMakeFiles/DependencyName COPYONLY)

But it feels wrong.

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