-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
460 lines (377 loc) · 16.9 KB
/
CMakeLists.txt
File metadata and controls
460 lines (377 loc) · 16.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
cmake_minimum_required(VERSION 3.17.5...3.27.7)
# define build environments
set( CMAKE_INSTALL_PREFIX "$ENV{HOME}/.local/"
CACHE STRING "Select where to install the library." )
set(CMAKE_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}
CACHE STRING "Select where to build the library." )
set(MODULE_DIR ${CMAKE_BUILD_DIR}/mod)
if (DEFINED SKBUILD_PROJECT_NAME)
set(SKBUILD_PROJECT_NAME ${SKBUILD_PROJECT_NAME})
else()
set(SKBUILD_PROJECT_NAME "raffle")
endif()
# set compiler
set(CMAKE_Fortran_COMPILER gfortran
CACHE STRING "Select Fortran compiler." ) # Change this to your desired compiler
set(CMAKE_C_COMPILER gcc
CACHE STRING "Select C compiler." ) # Change this to your desired compiler
set(CMAKE_Fortran_STANDARD 2018)
# set the project version
file(READ "fpm.toml" ver)
string(REGEX MATCH "version = \"([0-9]+.[0-9]+.[0-9]+)\"" _ ${ver})
set(PROJECT_VERSION ${CMAKE_MATCH_1})
message(STATUS "Project version: ${PROJECT_VERSION}")
# set the project name
project(raffle
VERSION ${PROJECT_VERSION}
LANGUAGES C Fortran
)
# set the library name
set( LIB_NAME ${PROJECT_NAME} )
set( PROJECT_DESCRIPTION
"Fortran neural network" )
set( PROJECT_URL "https://github.com/ExeQuantCode/raffle" )
set( CMAKE_CONFIGURATION_TYPES "Release" "Parallel" "Serial" "Dev" "Debug" "Debug_Serial" "Coverage"
CACHE STRING "List of configurations types." )
set( CMAKE_BUILD_TYPE "Release"
CACHE STRING "Select which configuration to build." )
# set options for building tests and examples
option(BUILD_TESTS "Build the unit tests" On)
option(BUILD_EXAMPLES "Build the examples" On)
option(BUILD_PYTHON "Build the python library" On)
option(BUILD_EXECUTABLE "Build the Fortran executable" On)
option(REMAKE_F90WRAP "Remake the f90wrap signature file" Off)
# set coverage compiler flags
if (CMAKE_BUILD_TYPE MATCHES "Coverage")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
include(CodeCoverage)
setup_target_for_coverage_gcovr_html(
NAME coverage
EXECUTABLE ctest
EXCLUDE "${CMAKE_SOURCE_DIR}/test/*")
endif()
endif()
# enable testing
enable_testing()
# Define the sources
set(SRC_DIR src)
set(FORTRAN_SRC_DIR ${SRC_DIR}/fortran)
set(LIB_DIR ${FORTRAN_SRC_DIR}/lib)
set(LIB_FILES
mod_io_utils.F90
mod_constants.f90
mod_cache.f90
mod_misc.f90
mod_tools_infile.f90
mod_misc_maths.f90
mod_misc_linalg.f90
mod_dist_calcs.f90
mod_geom_utils.f90
mod_geom_extd.f90
mod_element_utils.f90
mod_evaluator.f90
mod_place_methods.f90
mod_viability.f90
mod_distribs.f90
mod_distribs_host.f90
)
set(SPECIAL_LIB_FILES
mod_geom_rw.f90
mod_distribs_container.f90
mod_generator.f90
)
foreach(lib ${LIB_FILES})
list(APPEND PREPENDED_LIB_FILES ${LIB_DIR}/${lib})
endforeach()
foreach(lib ${SPECIAL_LIB_FILES})
list(APPEND PREPENDED_LIB_FILES ${LIB_DIR}/${lib})
endforeach()
message(STATUS "Modified LIB_FILES: ${PREPENDED_LIB_FILES}")
set(SRC_FILES
raffle.f90
)
foreach(lib ${SPECIAL_LIB_FILES})
list(APPEND F90WRAP_FORTRAN_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/${LIB_DIR}/${lib})
endforeach()
foreach(src ${SRC_FILES})
list(APPEND F90WRAP_FORTRAN_SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/${FORTRAN_SRC_DIR}/${src})
list(APPEND PREPENDED_SRC_FILES ${FORTRAN_SRC_DIR}/${src})
endforeach()
set(EXECUTABLE_FILES
mod_rw_vasprun.f90
mod_read_structures.f90
inputs.f90
main.f90
)
set(APP_DIR app)
foreach(src ${EXECUTABLE_FILES})
list(APPEND PREPENDED_EXECUTABLE_FILES ${APP_DIR}/${src})
endforeach()
# initialise flags
set(CPPFLAGS "")
set(CFLAGS "")
set(MODULEFLAGS "")
set(MPFLAGS "")
set(WARNFLAGS "")
set(DEVFLAGS "")
set(DEBUGFLAGS "")
set(MEMFLAGS "")
set(OPTIMFLAGS "")
set(FASTFLAGS "")
# set flags based on compiler
if (CMAKE_Fortran_COMPILER MATCHES ".*gfortran.*" OR CMAKE_Fortran_COMPILER MATCHES ".*gcc.*")
message(STATUS "Using gfortran compiler")
set(PPFLAGS -cpp)
set(MPFLAGS -fopenmp -lgomp -floop-parallelize-all -ftree-parallelize-loops=32)
set(WARNFLAGS -Wall)
set(DEVFLAGS -g -fbacktrace -fcheck=all -fbounds-check -Og)
set(DEBUGFLAGS -fbounds-check)
set(MEMFLAGS -mcmodel=large)
set(OPTIMFLAGS -O3 -march=native)
set(FASTFLAGS -Ofast -march=native)
set(PYTHONFLAGS -c -O3 -fPIC)
elseif (CMAKE_Fortran_COMPILER MATCHES ".*nag.*")
message(STATUS "Using nag compiler")
set(PPFLAGS -f2018 -fpp)
set(MPFLAGS -openmp)
set(WARNFLAGS -Wall)
set(DEVFLAGS -g -mtrace -C=all -colour -O0)
set(DEBUGFLAGS -C=array)
set(MEMFLAGS -mcmodel=large)
set(OPTIMFLAGS -O3)
set(FASTFLAGS -Ofast)
elseif (CMAKE_Fortran_COMPILER MATCHES ".*ifort.*" OR CMAKE_Fortran_COMPILER MATCHES ".*ifx.*")
message(STATUS "Using intel compiler")
set(PPFLAGS -fpp)
set(MPFLAGS -qopenmp)
set(WARNFLAGS -warn all)
set(DEVFLAGS -check all -warn)
set(DEBUGFLAGS -check all -fpe0 -warn -tracekback -debug extended)
set(MEMFLAGS -mcmodel=large)
set(OPTIMFLAGS -O3)
set(FASTFLAGS -Ofast)
else()
# Code for other Fortran compilers
message(STATUS "Using a different Fortran compiler")
endif()
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${PPFLAGS}")
# create the library
add_library(${PROJECT_NAME} STATIC ${PREPENDED_LIB_FILES} ${PREPENDED_SRC_FILES})
set_target_properties(${PROJECT_NAME} PROPERTIES Fortran_MODULE_DIRECTORY ${MODULE_DIR})
target_link_libraries(${PROJECT_NAME} PUBLIC)
# replace ".f90" with ".mod"
string(REGEX REPLACE "\\.[^.]*$" ".mod" MODULE_FILES "${SRC_FILES}")
set(ETC_MODULE_FILES "")
# Loop through each Fortran file
foreach(FILE ${PREPENDED_LIB_FILES})
# Read the content of the Fortran file
file(READ "${FILE}" FILE_CONTENTS)
# Use a regular expression to extract the module name
string(REGEX MATCH "^module[ \t]+([a-zA-Z0-9_]+)" MATCH "${FILE_CONTENTS}")
# If a match is found, extract the module name (the first capture group)
if(MATCH)
string(REGEX REPLACE "module[ \t]+([a-zA-Z0-9_]+)" "\\1" MODULE_NAME "${MATCH}")
# Append the module name with .mod to the list
list(APPEND ETC_MODULE_FILES "${MODULE_DIR}/${MODULE_NAME}.mod")
endif()
endforeach()
# installation
install(FILES ${MODULE_DIR}/${MODULE_FILES} DESTINATION ${SKBUILD_PROJECT_NAME}/include)
install(FILES ${ETC_MODULE_FILES} DESTINATION ${SKBUILD_PROJECT_NAME}/etc)
install(TARGETS ${PROJECT_NAME} DESTINATION ${SKBUILD_PROJECT_NAME}/lib)
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION})
# set compile options based on different build configurations
target_compile_options(${PROJECT_NAME} PUBLIC "$<$<CONFIG:Release>:${OPTIMFLAGS}>")
target_compile_options(${PROJECT_NAME} PUBLIC "$<$<CONFIG:Release>:${MPFLAGS}>")
target_compile_options(${PROJECT_NAME} PUBLIC "$<$<CONFIG:Release>:${PYTHONFLAGS}>")
target_compile_options(${PROJECT_NAME} PUBLIC "$<$<CONFIG:Serial>:${OPTIMFLAGS}>")
target_compile_options(${PROJECT_NAME} PUBLIC "$<$<CONFIG:Serial>:${PYTHONFLAGS}>")
target_compile_options(${PROJECT_NAME} PUBLIC "$<$<CONFIG:Parallel>:${OPTIMFLAGS}>")
target_compile_options(${PROJECT_NAME} PUBLIC "$<$<CONFIG:Parallel>:${MPFLAGS}>")
target_compile_options(${PROJECT_NAME} PUBLIC "$<$<CONFIG:Parallel>:${PYTHONFLAGS}>")
target_compile_options(${PROJECT_NAME} PUBLIC "$<$<CONFIG:Dev>:${DEVFLAGS}>")
target_compile_options(${PROJECT_NAME} PUBLIC "$<$<CONFIG:Debug>:${DEBUGFLAGS}>")
target_compile_options(${PROJECT_NAME} PUBLIC "$<$<CONFIG:Debug>:${WARNFLAGS}>")
target_compile_options(${PROJECT_NAME} PUBLIC "$<$<CONFIG:Debug>:${MPFLAGS}>")
target_compile_options(${PROJECT_NAME} PUBLIC "$<$<CONFIG:Debug>:${PYTHONFLAGS}>")
target_compile_options(${PROJECT_NAME} PUBLIC "$<$<CONFIG:Debug_Serial>:${DEBUGFLAGS}>")
target_compile_options(${PROJECT_NAME} PUBLIC "$<$<CONFIG:Debug_Serial>:${WARNFLAGS}>")
target_compile_options(${PROJECT_NAME} PUBLIC "$<$<CONFIG:Debug_Serial>:${PYTHONFLAGS}>")
# check if build is parallel
if (CMAKE_BUILD_TYPE MATCHES "Release*" OR CMAKE_BUILD_TYPE MATCHES "Parallel*" OR CMAKE_BUILD_TYPE MATCHES "Debug")
message(STATUS "Building in parallel mode")
# Find OpenMP and add OpenMP flags to compiler and linker
find_package(OpenMP REQUIRED COMPONENTS Fortran)
if(OpenMP_Fortran_FOUND)
# Link OpenMP for your target (Fortran)
target_link_libraries(${PROJECT_NAME} PRIVATE OpenMP::OpenMP_Fortran)
# Enable OpenMP flags when compiling Fortran
target_compile_options(${PROJECT_NAME} PRIVATE ${OpenMP_Fortran_FLAGS})
endif()
endif()
if (BUILD_EXECUTABLE)
add_executable(${PROJECT_NAME}_executable ${PREPENDED_EXECUTABLE_FILES})
target_link_libraries(${PROJECT_NAME}_executable PRIVATE ${PROJECT_NAME})
install(TARGETS ${PROJECT_NAME}_executable DESTINATION ${SKBUILD_PROJECT_NAME}/bin)
set_target_properties(${PROJECT_NAME}_executable PROPERTIES Fortran_MODULE_DIRECTORY ${MODULE_DIR})
target_compile_options(${PROJECT_NAME}_executable PUBLIC "$<$<CONFIG:Release>:${OPTIMFLAGS}>")
target_compile_options(${PROJECT_NAME}_executable PUBLIC "$<$<CONFIG:Release>:${MPFLAGS}>")
target_compile_options(${PROJECT_NAME}_executable PUBLIC "$<$<CONFIG:Release>:${PYTHONFLAGS}>")
target_compile_options(${PROJECT_NAME}_executable PUBLIC "$<$<CONFIG:Serial>:${OPTIMFLAGS}>")
target_compile_options(${PROJECT_NAME}_executable PUBLIC "$<$<CONFIG:Serial>:${PYTHONFLAGS}>")
target_compile_options(${PROJECT_NAME}_executable PUBLIC "$<$<CONFIG:Parallel>:${OPTIMFLAGS}>")
target_compile_options(${PROJECT_NAME}_executable PUBLIC "$<$<CONFIG:Parallel>:${MPFLAGS}>")
target_compile_options(${PROJECT_NAME}_executable PUBLIC "$<$<CONFIG:Parallel>:${PYTHONFLAGS}>")
target_compile_options(${PROJECT_NAME}_executable PUBLIC "$<$<CONFIG:Dev>:${DEVFLAGS}>")
target_compile_options(${PROJECT_NAME}_executable PUBLIC "$<$<CONFIG:Debug>:${DEBUGFLAGS}>")
target_compile_options(${PROJECT_NAME}_executable PUBLIC "$<$<CONFIG:Debug>:${WARNFLAGS}>")
target_compile_options(${PROJECT_NAME}_executable PUBLIC "$<$<CONFIG:Debug>:${MPFLAGS}>")
target_compile_options(${PROJECT_NAME}_executable PUBLIC "$<$<CONFIG:Debug>:${PYTHONFLAGS}>")
target_compile_options(${PROJECT_NAME}_executable PUBLIC "$<$<CONFIG:Debug_Serial>:${DEBUGFLAGS}>")
target_compile_options(${PROJECT_NAME}_executable PUBLIC "$<$<CONFIG:Debug_Serial>:${WARNFLAGS}>")
target_compile_options(${PROJECT_NAME}_executable PUBLIC "$<$<CONFIG:Debug_Serial>:${PYTHONFLAGS}>")
set_target_properties(${PROJECT_NAME}_executable PROPERTIES VERSION ${PROJECT_VERSION})
endif()
if (BUILD_PYTHON)
# # Get the directory where object files are generated
get_target_property(OBJECTS ${PROJECT_NAME} EXTERNAL_OBJECT)
# Print the object files directory
set(OBJECTS_DIR ${CMAKE_BUILD_DIR}/CMakeFiles/${PROJECT_NAME}.dir)
message(STATUS "Object files directory for ${PROJECT_NAME}: ${OBJECTS_DIR}")
# Include f90wrap
find_package(Python COMPONENTS Interpreter Development.Module NumPy REQUIRED)
if(NOT DEFINED PYTHON_EXECUTABLE)
set(PYTHON_EXECUTABLE ${Python_EXECUTABLE})
endif()
# Grab the variables from a local Python installation F2PY headers
execute_process(
COMMAND "${Python_EXECUTABLE}" -c
"import numpy.f2py; print(numpy.f2py.get_include())"
OUTPUT_VARIABLE F2PY_INCLUDE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
add_library(fortranobject OBJECT "${F2PY_INCLUDE_DIR}/fortranobject.c")
target_link_libraries(fortranobject PUBLIC Python::NumPy)
target_include_directories(fortranobject PUBLIC "${F2PY_INCLUDE_DIR}")
set_property(TARGET fortranobject PROPERTY POSITION_INDEPENDENT_CODE ON)
set (F90WRAP_EXECUTABLE ${PYTHON_EXECUTABLE} -m f90wrap)
set (F2PY_EXECUTABLE ${PYTHON_EXECUTABLE} -m f90wrap --f2py-f90wrap)
# Run Python command to get the extension suffix
execute_process(
COMMAND ${Python_EXECUTABLE} -c "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))"
RESULT_VARIABLE result
OUTPUT_VARIABLE PYTHON_EXTENSION_MODULE_SUFFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Check if the suffix was retrieved successfully
if (result EQUAL 0)
message(STATUS "Python extension module suffix: ${PYTHON_EXTENSION_MODULE_SUFFIX}")
else()
message(FATAL_ERROR "Failed to retrieve Python extension module suffix")
endif()
set(F2PY_OUTPUT_FILE ${CMAKE_BUILD_DIR}/raffle/_${PROJECT_NAME}${PYTHON_EXTENSION_MODULE_SUFFIX})
# Generate f90wrap signature file
set(F90WRAP_FILE
${CMAKE_CURRENT_LIST_DIR}/src/wrapper/f90wrap_mod_distribs_container.f90
${CMAKE_CURRENT_LIST_DIR}/src/wrapper/f90wrap_mod_generator.f90
${CMAKE_CURRENT_LIST_DIR}/src/wrapper/f90wrap_mod_geom_rw.f90
${CMAKE_CURRENT_LIST_DIR}/src/wrapper/f90wrap_raffle.f90
)
if (REMAKE_F90WRAP)
set(KIND_MAP ${CMAKE_SOURCE_DIR}/kind_map)
set(F90WRAP_REMAKE_FILE ${CMAKE_BUILD_DIR}/f90wrap_${PROJECT_NAME}.f90)
add_custom_command(
OUTPUT ${F90WRAP_REMAKE_FILE}
COMMAND ${F90WRAP_EXECUTABLE}
--default-to-inout
-m ${PROJECT_NAME}
-k ${KIND_MAP}
${F90WRAP_FORTRAN_SRC_FILES}
--only raffle_generator_type stoichiometry_type basis_type distribs_container_type:
DEPENDS ${F90WRAP_FORTRAN_SRC_FILES}
WORKING_DIRECTORY ${CMAKE_BUILD_DIR}
COMMENT "Generating f90wrap signature file"
VERBATIM
)
endif()
# Copy f90wrap edited files from edited_autogen_files to ${CMAKE_BUILD_DIR}
add_custom_command(
OUTPUT ${CMAKE_BUILD_DIR}/raffle/python_copied
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/${SRC_DIR}/raffle ${CMAKE_BUILD_DIR}/raffle
COMMENT "Copying raffle python files"
)
# If parallel build, need to add the parallel flag
if (CMAKE_BUILD_TYPE MATCHES "Release*" OR CMAKE_BUILD_TYPE MATCHES "Parallel*" OR CMAKE_BUILD_TYPE MATCHES "Debug")
set(GOMPFLAGS "-lgomp")
else()
set(GOMPFLAGS "")
endif()
# Create a Python module using f2py
add_custom_command(
OUTPUT ${F2PY_OUTPUT_FILE}
COMMAND CC="${CMAKE_C_COMPILER}" LDFLAGS="-L${CMAKE_BUILD_DIR}" LIBS="-lraffle" ${F2PY_EXECUTABLE}
-c
-m _${PROJECT_NAME}
-I${MODULE_DIR}
--f90flags="${PPFLAGS}"
${GOMPFLAGS}
--backend meson
${F90WRAP_FILE}
-L${CMAKE_BUILD_DIR}
-lraffle
# --build-dir ${CMAKE_BUILD_DIR}/Dmeson
DEPENDS ${F90WRAP_FILE} ${CMAKE_BUILD_DIR}/raffle/python_copied ${PROJECT_NAME}
WORKING_DIRECTORY ${CMAKE_BUILD_DIR}/raffle
COMMENT "Creating Python module using f2py"
)
# Define output files
set(PY_MODULE ${CMAKE_BUILD_DIR}/raffle/${PROJECT_NAME}.py ${CMAKE_BUILD_DIR}/raffle/__init__.py)
# Create a custom target for the Python module
add_custom_target(python_module ALL
DEPENDS ${F90WRAP_REMAKE_FILE} ${F2PY_OUTPUT_FILE}
)
# Installation instructions
install(FILES ${PY_MODULE} DESTINATION ${SKBUILD_PROJECT_NAME})
install(FILES ${F2PY_OUTPUT_FILE} DESTINATION ${SKBUILD_PROJECT_NAME})
endif()
# include the build test directory
if(BUILD_TESTS)
add_subdirectory(test)
endif()
# add coverage compiler flags
if ( ( CMAKE_Fortran_COMPILER MATCHES ".*gfortran.*" OR CMAKE_Fortran_COMPILER MATCHES ".*gcc.*" ) AND
( CMAKE_BUILD_TYPE MATCHES "Coverage" ) )
append_coverage_compiler_flags()
endif()
if(BUILD_TESTS)
# Create a directory for test data
add_custom_command(
OUTPUT ${CMAKE_BUILD_DIR}/test/test_dir_created # Temporary marker file to indicate the directory was created
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BUILD_DIR}/test/test
COMMENT "Creating test directory"
)
# Copy test data files
add_custom_command(
OUTPUT ${CMAKE_BUILD_DIR}/test/test_data_copied # Temporary marker file to indicate the data was copied
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/test/data ${CMAKE_BUILD_DIR}/test/test/data
DEPENDS ${CMAKE_CURRENT_LIST_DIR}/test/data ${CMAKE_BUILD_DIR}/test/test_dir_created # Ensure the source data exists and the directory was created
COMMENT "Copying test data files"
)
# Create a custom target to ensure that the copy commands are executed
add_custom_target(copy_test_data ALL
DEPENDS ${CMAKE_BUILD_DIR}/test/test_data_copied # Ensure it depends on the data copying command
)
# Add dependency to your main project target
add_dependencies(${PROJECT_NAME} copy_test_data)
# Ensure that ctest waits for copy_test_data
add_custom_command(TARGET copy_test_data POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Test data files copied successfully"
)
# Get all registered tests
get_property(all_tests GLOBAL PROPERTY TESTS)
# Loop through all tests and add the dependency
foreach(test_name IN LISTS all_tests)
add_dependencies(${test_name} copy_test_data)
endforeach()
endif()