0

I have following problem:

In my cmake project I create for each target custom command, that will write its includes in file.

set(TARGET_INCLUDES $<TARGET_PROPERTY:${target},INCLUDE_DIRECTORIES>)
set(INCL_FILE "project_includes/${target}_includes.txt")
set( INC_WRITER_FLAGS --include-path ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES} ${TARGET_INCLUDES}
                          --output ${CMAKE_BINARY_DIR}/${INCL_FILE} )

message("!!!!!!!!!!!!! generating rule for ${CMAKE_BINARY_DIR}/${INCL_FILE}")
add_custom_command(
      OUTPUT ${CMAKE_BINARY_DIR}/${INCL_FILE}
      COMMAND ${Python3_EXECUTABLE} ${INCLUDE_WRITER_PATH} ${INC_WRITER_FLAGS}
      VERBATIM)

I see this debug message for each of my targets, so I assume, that it is created. Then for each target I create script that depends on all *_includes.txt of its dependencies. But in my resulting build.ninja there is no command for creating *_includes.txt for about quarter of my targets and build fails as second script cannot find neither its dependencies nor rules to create them. Currently I have no idea, what targets for those add_custom_command didn't do anything have in common, maybe someone have idea, under what circumstances can such effect be possible? Cmake 3.18.5

0

1 Answer 1

1

Add custom command is only run if output is used. When output is not used, it is not run.

See add custom target.

Sign up to request clarification or add additional context in comments.

2 Comments

But it is used, other add_custom_command explicitly depends on it's output and build fails due to absence of those output (and even rule to build it)
@CrazySage: ".. other add_custom_command explicitly depends on it's output" - Please, update your question post to the state of minimal reproducible example. Currently your question post shows only single add_custom_command call and nothing else. Without complete code we have no idea why your project doesn't work.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.