Re-configure depending on Python script output

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Re-configure depending on Python script output

I wanted to use a Python script to generate dependencies for cmake, and only reconfigure if these parameters changed [like additional sources, additional linker scripts, ...].
I managed to create these dependencies in a file, read these from cmake and configure my project accordingly, via the following scheme. It should be noted that creates dependencies.txt and only overwrites the previous version, if its content changed [so that configure_file should only see a change time-stamp when the content changed].
set(PYTHON_GENERATOR pythonGenerator)
set(DEPENDENCIES_FILE dependencies.txt)
set(DEPENDENCIES_FILE_COPY dependencies.txt.copy)
# custom target to run python script
            COMMAND python
            DEPENDS ${TEST_SOURCE}
# re-configure when file changed

# create real executable target which uses the generated source file
add_executable(executable ${TEST_SOURCE})

add_dependencies(executable ${PYTHON_GENERATOR})
My current problem is that make checks whether ${DEPENDENCIES_FILE} changed before potentially creating the file dependencies.txt anew. Thus I have to run make twice, for it to see the changes.
Is there a simpler way to always run my python script before mis-using configure_file?
Do you know of a simpler way to configure only when the dependencies changed?
Hope I could state clear anough what my problem is. Would be glad to answer any relating questions. Any help is going to be appreciated.
Best regards,


Powered by

Please keep messages on-topic and check the CMake FAQ at:

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support:
CMake Consulting:
CMake Training Courses:

Visit other Kitware open-source projects at

Follow this link to subscribe/unsubscribe: