Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

cmake - How to add file(READ ...) as a dependency to configure_file(...)?

I have something like the following snippet in a CMakeLists.txt:

file(READ api.yaml API_YAML)
configure_file(schemautil.h.in schemautil.h)

The variable ${API_YAML} is used in schemautil.h.in

When I go to build, the configured file schemautil.h does not regenerate when I make changes to api.yaml.

How do I make updates to api.yaml trigger the configure_file line?

Also, if there is a better way to accomplish what I'm doing here -- i.e. stuffing api.yaml into source code at compile time, I'm interested.

question from:https://stackoverflow.com/questions/65945012/how-to-add-fileread-as-a-dependency-to-configure-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can create a dependency on that file to trigger a re-configure by adding

set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS api.yaml)

See CMAKE_CONFIGURE_DEPENDS in the CMake documentation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...