1# binary_dir_relative_path sets outvar to 2# ${CMAKE_CURRENT_BINARY_DIR}/${cur_bin_dir_relative}, but expressed relative to 3# ${CMAKE_BINARY_DIR}. 4# 5# TODO(davidben): When we require CMake 3.20 or later, this can be replaced with 6# the built-in cmake_path(RELATIVE_PATH) function. 7function(binary_dir_relative_path cur_bin_dir_relative outvar) 8 string(LENGTH "${CMAKE_BINARY_DIR}/" root_dir_length) 9 string(SUBSTRING "${CMAKE_CURRENT_BINARY_DIR}/${cur_bin_dir_relative}" ${root_dir_length} -1 result) 10 set(${outvar} ${result} PARENT_SCOPE) 11endfunction() 12 13# copy_post_build causes targets in ${ARGN} to be copied to 14# ${CMAKE_CURRENT_BINARY_DIR}/${dir} after being built. 15function(copy_post_build dir) 16 foreach(target ${ARGN}) 17 add_custom_command( 18 TARGET ${target} 19 POST_BUILD 20 COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/${dir}" 21 COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${target}> "${CMAKE_CURRENT_BINARY_DIR}/${dir}") 22 endforeach() 23endfunction() 24