Hello,
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 script.py 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)
set(DEPENDENCIES_FILE dependencies.txt)
set(DEPENDENCIES_FILE_COPY dependencies.txt.copy)
# custom target to run python script
add_custom_target(${PYTHON_GENERATOR}
COMMAND python script.py
DEPENDS ${TEST_SOURCE}
)
COMMAND python script.py
DEPENDS ${TEST_SOURCE}
)
# re-configure when file changed
configure_file(${DEPENDENCIES_FILE} ${DEPENDENCIES_FILE_COPY} COPYONLY)
file(REMOVE ${DEPENDENCIES_FILE_COPY})
configure_file(${DEPENDENCIES_FILE} ${DEPENDENCIES_FILE_COPY} COPYONLY)
file(REMOVE ${DEPENDENCIES_FILE_COPY})
# 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,
Johannes
-- Powered by www.kitware.com
Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake