I have a Version.hpp file that I have a custom command tied to which basically runs CMake in script mode to perform configure_file() on it during build time. The reason it does this is because it builds Version.hpp using dynamic information, such as defining a macro with the current SHA1 being built, etc.
I notice in parallel builds, this header file gets built too late, because of parallel builds. What if a file includes the header and its translation unit is built before Version.hpp is generated by the custom command? Would it be better/simpler to do configure_file() at configuration time instead of at build time as a custom command? Here's the logic (some variables are defined elsewhere, but should give you the gist): set( generated_source_dir ${CMAKE_CURRENT_BINARY_DIR}/Source ) set( version_file_in ${CMAKE_CURRENT_SOURCE_DIR}/Version.cpp.in ) set( version_file_out ${generated_source_dir}/Main/Version.cpp ) add_custom_command( OUTPUT ${version_file_out} COMMAND ${CMAKE_COMMAND} -D IN_FILE=${version_file_in} -D OUT_FILE=${version_file_out} -D GIT_EXECUTABLE=${GIT_EXECUTABLE} -D BUILD_VERSION=${ZIOSK_BUILD_VERSION} -P ${CMAKE_CURRENT_SOURCE_DIR}/build_version_header.cmake WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} ) source_group( Generated FILES ${version_file_out} ) list( APPEND source_files ${version_file_out} ) -- 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