I've been caught out by an add_custom_command w/target declaration problem and present it here. Below are two CMake source trees, the first one runs the custom command while the second version does not.
QQ. I expected the two trees to be (roughly equivalent) - why would the latter skip running the custom command?
V1: Building generates myFile.txt
# ~/CMakeLists.txt
project(myProj)
cmake_minimum_required(VERSION 3.16)
add_subdirectory(myDir)
# ~/myDir/CMakeLists.txt
add_executable(myExe) # ***Declare target here***
add_custom_command(
OUTPUT myFile.txt
COMMAND touch myFile.txt
DEPENDS myFile.txt
)
target_sources(myExe PRIVATE myFile.txt)
V2: Building doesn't generate a myFile.txt
# ~/myDir/CMakeLists.txt
project(myProj)
cmake_minimum_required(VERSION 3.16)
add_executable(myExe) # ***Declare target here***
add_subdirectory(myDir)
# ~/myDir/CMakeLists.txt
add_custom_command(
OUTPUT myFile.txt
COMMAND touch myFile.txt
DEPENDS myFile.txt
)
target_sources(myExe PRIVATE myFile.txt)
I've been tearing my hair out and didn't turn up much after skimming the reference. Cheers