You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Timofei Zhakov <ti...@chemodax.net> on 2026/05/12 16:36:42 UTC

[PATCH] Use file(COPY) to copy test data instead of spawning a process

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

Re: [PATCH] Use file(COPY) to copy test data instead of spawning a process

Posted by Timofei Zhakov <ti...@chemodax.net>.
On Tue, May 12, 2026 at 8:18 PM Ivan Zhakov <iv...@apache.org> wrote:

> On Tue, 12 May 2026 at 18:37, Timofei Zhakov <ti...@chemodax.net> wrote:
>
>> 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.
>>
>> Committed in r1934148.
>
> Thanks!
>

Thank you!

-- 
Timofei Zhakov

Re: [PATCH] Use file(COPY) to copy test data instead of spawning a process

Posted by Ivan Zhakov <iv...@apache.org>.
On Tue, 12 May 2026 at 18:37, Timofei Zhakov <ti...@chemodax.net> wrote:

> 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.
>
> Committed in r1934148.

Thanks!

-- 
Ivan Zhakov