Fix parallel builds
* atomic_config_file(): copy file to destination
.. to allow operation across file systems
* atomic_configure_file: lock destination directory
.. to sync multiple cmake processes writing to that location
* apply file(LOCK) only for cmake >= 3.2
* create configure files in sub-folder atomic_configure
function(atomic_configure_file input output)
- set(atomic_file "${CMAKE_BINARY_DIR}/atomic_configure_file")
+ get_filename_component(atomic_file ${output} NAME)
+ set(atomic_file "${CMAKE_BINARY_DIR}/atomic_configure/${atomic_file}")
configure_file("${input}" "${atomic_file}" ${ARGN})
get_filename_component(output_path ${output} PATH)
- if(NOT EXISTS ${output_path})
- file(MAKE_DIRECTORY ${output_path})
+ # sync multiple catkin cmake processes writing to that location
+ if (NOT CMAKE_VERSION VERSION_LESS 3.2)
+ file(LOCK "${output_path}" DIRECTORY GUARD FUNCTION)
endif()
- file(RENAME "${atomic_file}" "${output}")
+ file(COPY "${atomic_file}" DESTINATION "${output_path}")
endfunction()
