I think this syntax is much simpler, more convenient, and looks
prettier. According to the documentation [1] cmake will do its best at
avoiding copying the file twice if the same exists with matching
timestamps. Not using cmake executable to copy files will also slightly
improve configuration time because it removes invoking extra tools, if it's
even remotely close to being anywhere significant.

[[[
cmake: Use file(COPY) to copy test data instead of spawning a process.

* CMakeLists.txt
  (tests): Use a better statement for configure time file manipulation.

Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt (revision 1934145)
+++ CMakeLists.txt (working copy)
@@ -617,25 +617,14 @@
   add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --verbose)

   # copy data files to build directory so that we can run programs from
there
-  execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory
-                  ${PROJECT_BINARY_DIR}/data)
-  execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
-                  ${PROJECT_SOURCE_DIR}/test/data/billion-laughs.xml
-                  ${PROJECT_BINARY_DIR}/data/billion-laughs.xml)
-  execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
-                  ${PROJECT_SOURCE_DIR}/test/data/file_datafile.txt
-                  ${PROJECT_BINARY_DIR}/data/file_datafile.txt)
-  execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
-                  ${PROJECT_SOURCE_DIR}/test/data/mmap_datafile.txt
-                  ${PROJECT_BINARY_DIR}/data/mmap_datafile.txt)
-  execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
-                  ${PROJECT_SOURCE_DIR}/test/data/mmap_large_datafile.txt
-                  ${PROJECT_BINARY_DIR}/data/mmap_large_datafile.txt)
+  file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/data)
+  file(COPY ${PROJECT_SOURCE_DIR}/test/data/billion-laughs.xml
+            ${PROJECT_SOURCE_DIR}/test/data/file_datafile.txt
+            ${PROJECT_SOURCE_DIR}/test/data/mmap_datafile.txt
+            ${PROJECT_SOURCE_DIR}/test/data/mmap_large_datafile.txt
+            ${PROJECT_SOURCE_DIR}/test/echoargs.bat
+       DESTINATION ${PROJECT_BINARY_DIR}/data)

-  execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
-                  ${PROJECT_SOURCE_DIR}/test/echoargs.bat
-                  ${PROJECT_BINARY_DIR}/echoargs.bat)
-
   add_executable(testapp test/testapp.c)
   target_link_libraries(testapp ${apr_libname} libaprapp-2)
   set_target_properties(testapp PROPERTIES LINK_FLAGS
/entry:wmainCRTStartup)
]]]

[1] https://cmake.org/cmake/help/latest/command/file.html#copy

-- 
Timofei Zhakov

Reply via email to