forked from openPMD/openPMD-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
862 lines (787 loc) · 31.3 KB
/
CMakeLists.txt
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
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
# Preamble ####################################################################
#
cmake_minimum_required(VERSION 3.10.0)
project(openPMD VERSION 0.3.0) # LANGUAGES CXX
# the openPMD "markup"/"schema" standard version
set(openPMD_STANDARD_VERSION 1.1.0)
list(APPEND CMAKE_MODULE_PATH "${openPMD_SOURCE_DIR}/share/openPMD/cmake")
# Project structure ###########################################################
#
# temporary build directories
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
CACHE PATH "Build directory for archives")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
CACHE PATH "Build directory for libraries")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
CACHE PATH "Build directory for binaries")
# install directories
include(GNUInstallDirs)
set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/openPMD"
CACHE PATH "CMake config package location for installed targets")
if(WIN32)
set(CMAKE_INSTALL_LIBDIR Lib)
set(CMAKE_INSTALL_CMAKEDIR "cmake")
endif()
# Options and Variants ########################################################
#
function(openpmd_option name description default)
set(openPMD_USE_${name} ${default} CACHE STRING "${description}")
set_property(CACHE openPMD_USE_${name} PROPERTY
STRINGS "ON;TRUE;AUTO;OFF;FALSE"
)
if(openPMD_HAVE_${name})
set(openPMD_HAVE_${name} TRUE)
else()
set(openPMD_HAVE_${name})
endif()
# list of all possible options
set(openPMD_CONFIG_OPTIONS ${openPMD_CONFIG_OPTIONS} ${name} PARENT_SCOPE)
endfunction()
openpmd_option(MPI "Enable MPI support" AUTO)
openpmd_option(HDF5 "Enable HDF5 support" AUTO)
openpmd_option(ADIOS1 "Enable ADIOS1 support" AUTO)
openpmd_option(ADIOS2 "Enable ADIOS2 support" OFF)
#openpmd_option(JSON "Enable JSON support" AUTO)
openpmd_option(INVASIVE_TESTS "Enable unit tests that modify source code" AUTO)
openpmd_option(PYTHON "Enable Python bindings" AUTO)
option(openPMD_USE_INTERNAL_VARIANT "Use internally shipped MPark.Variant" ON)
option(openPMD_USE_INTERNAL_CATCH "Use internally shipped Catch2" ON)
option(openPMD_USE_INTERNAL_PYBIND11 "Use internally shipped pybind11" ON)
option(openPMD_USE_VERIFY "Enable internal VERIFY (assert) macro independent of build type" ON)
set(CMAKE_CONFIGURATION_TYPES "Release;Debug;MinSizeRel;RelWithDebInfo")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
"Choose the build type, e.g. Release or Debug." FORCE)
endif()
include(CTest)
# automatically defines: BUILD_TESTING, default is ON
option(BUILD_EXAMPLES "Build the examples" ON)
# Dependencies ################################################################
#
# external library: MPI (optional)
if(openPMD_USE_MPI STREQUAL AUTO)
find_package(MPI)
if(MPI_FOUND)
set(openPMD_HAVE_MPI TRUE)
else()
set(openPMD_HAVE_MPI FALSE)
endif()
elseif(openPMD_USE_MPI)
find_package(MPI REQUIRED)
set(openPMD_HAVE_MPI TRUE)
else()
set(openPMD_HAVE_MPI FALSE)
endif()
# external library: HDF5 (optional)
if(openPMD_USE_HDF5 STREQUAL AUTO)
set(HDF5_PREFER_PARALLEL ${openPMD_HAVE_MPI})
find_package(HDF5 1.8.13 COMPONENTS C)
if(HDF5_FOUND)
set(openPMD_HAVE_HDF5 TRUE)
else()
set(openPMD_HAVE_HDF5 FALSE)
endif()
elseif(openPMD_USE_HDF5)
set(HDF5_PREFER_PARALLEL ${openPMD_HAVE_MPI})
find_package(HDF5 1.8.13 REQUIRED COMPONENTS C)
set(openPMD_HAVE_HDF5 TRUE)
else()
set(openPMD_HAVE_HDF5 FALSE)
endif()
# we imply support for parallel I/O if MPI variant is ON
if(openPMD_HAVE_MPI AND openPMD_HAVE_HDF5 AND NOT HDF5_IS_PARALLEL)
string(CONCAT openPMD_HDF5_STATUS
"Found MPI but only serial version of HDF5. Either set "
"openPMD_USE_MPI=OFF to disable MPI or set openPMD_USE_HDF5=OFF "
"to disable HDF5 or provide a parallel install of HDF5.")
if(openPMD_USE_HDF5 STREQUAL AUTO)
message(WARNING "${openPMD_HDF5_STATUS}")
set(openPMD_HAVE_HDF5 FALSE)
elseif(openPMD_USE_HDF5)
message(FATAL_ERROR "${openPMD_HDF5_STATUS}")
endif()
endif()
# HDF5 includes mpi.h in the public header H5public.h if HDF5_IS_PARALLEL
if(openPMD_HAVE_HDF5 AND HDF5_IS_PARALLEL AND NOT openPMD_HAVE_MPI)
string(CONCAT openPMD_HDF5_STATUS
"Found only parallel version of HDF5 but no MPI. Either set "
"openPMD_USE_MPI=ON to force using MPI or set openPMD_USE_HDF5=OFF "
"to disable HDF5 or provide a serial install of HDF5.")
if(openPMD_USE_HDF5 STREQUAL AUTO)
message(WARNING "${openPMD_HDF5_STATUS}")
set(openPMD_HAVE_HDF5 FALSE)
elseif(openPMD_USE_HDF5)
message(FATAL_ERROR "${openPMD_HDF5_STATUS}")
endif()
endif()
# always search for a sequential lib first, so we can mock MPI
find_package(ADIOS 1.13.1 COMPONENTS sequential QUIET)
set(ADIOS_DEFINITIONS_SEQUENTIAL ${ADIOS_DEFINITIONS})
set(ADIOS_LIBRARIES_SEQUENTIAL ${ADIOS_LIBRARIES})
set(ADIOS_INCLUDE_DIRS_SEQUENTIAL ${ADIOS_INCLUDE_DIRS})
unset(ADIOS_FOUND CACHE)
unset(ADIOS_VERSION CACHE)
# regular logic
set(ADIOS1_PREFER_COMPONENTS)
if(NOT openPMD_HAVE_MPI)
set(ADIOS1_PREFER_COMPONENTS sequential)
endif()
if(openPMD_USE_ADIOS1 STREQUAL AUTO)
find_package(ADIOS 1.13.1 COMPONENTS ${ADIOS1_PREFER_COMPONENTS})
if(ADIOS_FOUND)
set(openPMD_HAVE_ADIOS1 TRUE)
else()
set(openPMD_HAVE_ADIOS1 FALSE)
endif()
elseif(openPMD_USE_ADIOS1)
find_package(ADIOS 1.13.1 REQUIRED COMPONENTS ${ADIOS1_PREFER_COMPONENTS})
set(openPMD_HAVE_ADIOS1 TRUE)
else()
set(openPMD_HAVE_ADIOS1 FALSE)
endif()
if(openPMD_HAVE_MPI AND openPMD_HAVE_ADIOS1 AND ADIOS_HAVE_SEQUENTIAL)
string(CONCAT openPMD_ADIOS1_STATUS
"Found MPI but requested ADIOS1 is serial. "
"Set openPMD_USE_MPI=OFF to disable MPI.")
if(openPMD_USE_ADIOS1 STREQUAL AUTO)
message(WARNING "${openPMD_ADIOS1_STATUS}")
set(openPMD_HAVE_ADIOS1 FALSE)
elseif(openPMD_USE_ADIOS1)
message(FATAL_ERROR "${openPMD_ADIOS1_STATUS}")
endif()
endif()
if(NOT openPMD_HAVE_MPI AND openPMD_HAVE_ADIOS1 AND NOT ADIOS_HAVE_SEQUENTIAL)
string(CONCAT openPMD_ADIOS1_STATUS
"Did not find MPI but requested ADIOS1 is parallel. "
"Set openPMD_USE_ADIOS1=OFF to disable ADIOS1.")
if(openPMD_USE_ADIOS1 STREQUAL AUTO)
message(WARNING "${openPMD_ADIOS1_STATUS}")
set(openPMD_HAVE_ADIOS1 FALSE)
elseif(openPMD_USE_ADIOS1)
message(FATAL_ERROR "${openPMD_ADIOS1_STATUS}")
endif()
endif()
# external library: ADIOS2 (optional)
if(openPMD_USE_ADIOS2 STREQUAL AUTO)
find_package(ADIOS2 2.1.0)
if(ADIOS2_FOUND)
set(openPMD_HAVE_ADIOS2 TRUE)
else()
set(openPMD_HAVE_ADIOS2 FALSE)
endif()
elseif(openPMD_USE_ADIOS2)
find_package(ADIOS2 2.1.0 REQUIRED)
set(openPMD_HAVE_ADIOS2 TRUE)
else()
set(openPMD_HAVE_ADIOS2 FALSE)
endif()
# TODO: Check if ADIOS2 is parallel when openPMD_HAVE_MPI is ON
# external library: pybind11 (optional)
if(openPMD_USE_PYTHON STREQUAL AUTO)
if(openPMD_USE_INTERNAL_PYBIND11)
add_subdirectory("${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/pybind11")
set(openPMD_HAVE_PYTHON TRUE)
message(STATUS "pybind11: Using INTERNAL version 2.2.3")
else()
find_package(pybind11 2.2.3 CONFIG) # 2.3.0
if(pybind11_FOUND)
set(openPMD_HAVE_PYTHON TRUE)
message(STATUS "pybind11: Found version ${pybind11_VERSION}")
else()
set(openPMD_HAVE_PYTHON FALSE)
endif()
endif()
elseif(openPMD_USE_PYTHON)
if(openPMD_USE_INTERNAL_PYBIND11)
add_subdirectory("${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/pybind11")
set(openPMD_HAVE_PYTHON TRUE)
message(STATUS "pybind11: Using INTERNAL version 2.2.3")
else()
find_package(pybind11 2.2.3 CONFIG REQUIRED) # 2.3.0
set(openPMD_HAVE_PYTHON TRUE)
message(STATUS "pybind11: Found version ${pybind11_VERSION}")
endif()
else()
set(openPMD_HAVE_PYTHON FALSE)
endif()
# Targets #####################################################################
#
set(CORE_SOURCE
src/Dataset.cpp
src/Datatype.cpp
src/Iteration.cpp
src/IterationEncoding.cpp
src/Mesh.cpp
src/ParticlePatches.cpp
src/ParticleSpecies.cpp
src/Record.cpp
src/RecordComponent.cpp
src/Series.cpp
src/auxiliary/Filesystem.cpp
src/backend/Attributable.cpp
src/backend/BaseRecordComponent.cpp
src/backend/MeshRecordComponent.cpp
src/backend/PatchRecord.cpp
src/backend/PatchRecordComponent.cpp
src/backend/Writable.cpp)
set(IO_SOURCE
src/IO/AbstractIOHandler.cpp
src/IO/AbstractIOHandlerImpl.cpp
src/IO/AbstractIOHandlerHelper.cpp
src/IO/IOTask.cpp
src/IO/HDF5/HDF5IOHandler.cpp
src/IO/HDF5/ParallelHDF5IOHandler.cpp)
set(IO_ADIOS1_SEQUENTIAL_SOURCE
src/IO/AbstractIOHandler.cpp
src/IO/AbstractIOHandlerImpl.cpp
src/auxiliary/Filesystem.cpp
src/IO/ADIOS/ADIOS1IOHandler.cpp)
set(IO_ADIOS1_SOURCE
src/IO/AbstractIOHandler.cpp
src/IO/AbstractIOHandlerImpl.cpp
src/auxiliary/Filesystem.cpp
src/IO/ADIOS/ParallelADIOS1IOHandler.cpp)
# library
add_library(openPMD ${CORE_SOURCE} ${IO_SOURCE})
add_library(openPMD::openPMD ALIAS openPMD)
# properties
target_compile_features(openPMD
PUBLIC cxx_std_11
)
set_target_properties(openPMD PROPERTIES
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
POSITION_INDEPENDENT_CODE ON
WINDOWS_EXPORT_ALL_SYMBOLS ON
)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
target_compile_options(openPMD PUBLIC "/bigobj")
endif()
# own headers
target_include_directories(openPMD PUBLIC
$<BUILD_INTERFACE:${openPMD_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
# C++11 std::variant (C++17 stdlib preview)
if(openPMD_USE_INTERNAL_VARIANT)
target_include_directories(openPMD SYSTEM PUBLIC
$<BUILD_INTERFACE:${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/variant/include>
)
message(STATUS "MPark.Variant: Using INTERNAL version 1.3.0")
else()
find_package(mpark_variant 1.3.0 REQUIRED)
target_link_libraries(openPMD PUBLIC mpark_variant)
message(STATUS "MPark.Variant: Found version ${mpark_variant_VERSION}")
endif()
# Catch2 for unit tests
if(BUILD_TESTING)
if(openPMD_USE_INTERNAL_CATCH)
target_include_directories(openPMD SYSTEM PUBLIC
$<BUILD_INTERFACE:${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/catch2/include>
)
message(STATUS "Catch2: Using INTERNAL version 2.2.1")
else()
find_package(Catch2 2.2.1 CONFIG REQUIRED)
message(STATUS "Catch2: Found version ${Catch2_VERSION}")
endif()
endif()
if(openPMD_HAVE_MPI)
# MPI targets: CMake 3.9+
# note: often the PUBLIC dependency to CXX is missing in C targets...
target_link_libraries(openPMD PUBLIC MPI::MPI_C MPI::MPI_CXX)
target_compile_definitions(openPMD PUBLIC "-DopenPMD_HAVE_MPI=1")
else()
target_compile_definitions(openPMD PUBLIC "-DopenPMD_HAVE_MPI=0")
endif()
# HDF5 Backend
if(openPMD_HAVE_HDF5)
target_link_libraries(openPMD PUBLIC ${HDF5_LIBRARIES})
target_include_directories(openPMD SYSTEM PUBLIC ${HDF5_INCLUDE_DIRS})
target_compile_definitions(openPMD PUBLIC ${HDF5_DEFINITIONS})
target_compile_definitions(openPMD PUBLIC "-DopenPMD_HAVE_HDF5=1")
else()
target_compile_definitions(openPMD PUBLIC "-DopenPMD_HAVE_HDF5=0")
endif()
# ADIOS1 Backend
add_library(openPMD.ADIOS1.Serial SHARED ${IO_ADIOS1_SEQUENTIAL_SOURCE})
add_library(openPMD.ADIOS1.Parallel SHARED ${IO_ADIOS1_SOURCE})
target_compile_features(openPMD.ADIOS1.Serial
PUBLIC cxx_std_11
)
target_compile_features(openPMD.ADIOS1.Parallel
PUBLIC cxx_std_11
)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
target_compile_options(openPMD.ADIOS1.Serial PUBLIC "/bigobj")
target_compile_options(openPMD.ADIOS1.Parallel PUBLIC "/bigobj")
endif()
if(openPMD_USE_INTERNAL_VARIANT)
target_include_directories(openPMD.ADIOS1.Serial SYSTEM PUBLIC
$<BUILD_INTERFACE:${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/variant/include>)
target_include_directories(openPMD.ADIOS1.Parallel SYSTEM PUBLIC
$<BUILD_INTERFACE:${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/variant/include>)
else()
target_link_libraries(openPMD.ADIOS1.Serial PUBLIC mpark_variant)
target_link_libraries(openPMD.ADIOS1.Parallel PUBLIC mpark_variant)
endif()
target_include_directories(openPMD.ADIOS1.Serial SYSTEM PRIVATE
${openPMD_SOURCE_DIR}/include)
target_include_directories(openPMD.ADIOS1.Parallel SYSTEM PRIVATE
${openPMD_SOURCE_DIR}/include)
if(openPMD_HAVE_MPI)
target_link_libraries(openPMD.ADIOS1.Parallel PUBLIC MPI::MPI_C MPI::MPI_CXX)
target_compile_definitions(openPMD.ADIOS1.Parallel PRIVATE "-DopenPMD_HAVE_MPI=1")
else()
target_compile_definitions(openPMD.ADIOS1.Parallel PRIVATE "-DopenPMD_HAVE_MPI=0")
endif()
if(openPMD_HAVE_ADIOS1)
set_target_properties(openPMD.ADIOS1.Serial PROPERTIES
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
POSITION_INDEPENDENT_CODE ON
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON
)
if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
set_target_properties(openPMD.ADIOS1.Serial PROPERTIES
LINK_FLAGS "-Wl,--exclude-libs,ALL")
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
set_target_properties(openPMD.ADIOS1.Serial PROPERTIES
XCODE_ATTRIBUTE_STRIP_STYLE "non-global"
XCODE_ATTRIBUTE_DEPLOYMENT_POSTPROCESSING "YES"
XCODE_ATTRIBUTE_SEPARATE_STRIP "YES"
)
endif()
foreach(adlib ${ADIOS_LIBRARIES_SEQUENTIAL})
target_link_libraries(openPMD.ADIOS1.Serial PRIVATE ${adlib})
endforeach()
target_include_directories(openPMD.ADIOS1.Serial SYSTEM PRIVATE ${ADIOS_INCLUDE_DIRS_SEQUENTIAL})
target_compile_definitions(openPMD.ADIOS1.Serial PRIVATE "${ADIOS_DEFINITIONS_SEQUENTIAL}")
target_compile_definitions(openPMD.ADIOS1.Serial PRIVATE "-DopenPMD_HAVE_ADIOS1=1")
target_compile_definitions(openPMD.ADIOS1.Serial PRIVATE "-DopenPMD_HAVE_MPI=0")
target_compile_definitions(openPMD.ADIOS1.Serial PRIVATE "-D_NOMPI=1")
if(openPMD_HAVE_MPI)
set_target_properties(openPMD.ADIOS1.Parallel PROPERTIES
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
POSITION_INDEPENDENT_CODE ON
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN 1
)
if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
set_target_properties(openPMD.ADIOS1.Parallel PROPERTIES
LINK_FLAGS "-Wl,--exclude-libs,ALL")
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
set_target_properties(openPMD.ADIOS1.Parallel PROPERTIES
XCODE_ATTRIBUTE_STRIP_STYLE "non-global"
XCODE_ATTRIBUTE_DEPLOYMENT_POSTPROCESSING "YES"
XCODE_ATTRIBUTE_SEPARATE_STRIP "YES"
)
endif()
foreach(adlib ${ADIOS_LIBRARIES})
target_link_libraries(openPMD.ADIOS1.Parallel PRIVATE ${adlib})
endforeach()
target_include_directories(openPMD.ADIOS1.Parallel SYSTEM PRIVATE ${ADIOS_INCLUDE_DIRS})
target_compile_definitions(openPMD.ADIOS1.Parallel PRIVATE "${ADIOS_DEFINITIONS}")
target_compile_definitions(openPMD.ADIOS1.Parallel PRIVATE "-DopenPMD_HAVE_ADIOS1=1")
endif()
target_compile_definitions(openPMD PUBLIC "-DopenPMD_HAVE_ADIOS1=1")
else()
target_compile_definitions(openPMD.ADIOS1.Serial PRIVATE "-DopenPMD_HAVE_ADIOS1=0")
target_compile_definitions(openPMD.ADIOS1.Parallel PRIVATE "-DopenPMD_HAVE_ADIOS1=0")
target_compile_definitions(openPMD PUBLIC "-DopenPMD_HAVE_ADIOS1=0")
endif()
target_link_libraries(openPMD PUBLIC openPMD.ADIOS1.Serial)
target_link_libraries(openPMD PUBLIC openPMD.ADIOS1.Parallel)
# ADIOS2 Backend
if(openPMD_HAVE_ADIOS2)
target_link_libraries(openPMD PUBLIC ADIOS2::ADIOS2)
target_compile_definitions(openPMD PUBLIC "-DopenPMD_HAVE_ADIOS2=1")
else()
target_compile_definitions(openPMD PUBLIC "-DopenPMD_HAVE_ADIOS2=0")
endif()
# Runtime parameter and API status checks ("asserts")
if(openPMD_USE_VERIFY)
target_compile_definitions(openPMD PRIVATE "-DopenPMD_USE_VERIFY=1")
else()
target_compile_definitions(openPMD PRIVATE "-DopenPMD_USE_VERIFY=0")
endif()
# python bindings
if(openPMD_HAVE_PYTHON)
pybind11_add_module(openPMD.py MODULE
src/binding/python/openPMD.cpp
src/binding/python/AccessType.cpp
src/binding/python/Attributable.cpp
src/binding/python/BaseRecord.cpp
src/binding/python/BaseRecordComponent.cpp
src/binding/python/Container.cpp
src/binding/python/Dataset.cpp
src/binding/python/Datatype.cpp
src/binding/python/Iteration.cpp
src/binding/python/IterationEncoding.cpp
src/binding/python/Mesh.cpp
src/binding/python/ParticlePatches.cpp
src/binding/python/ParticleSpecies.cpp
src/binding/python/Record.cpp
src/binding/python/RecordComponent.cpp
src/binding/python/MeshRecordComponent.cpp
src/binding/python/Series.cpp
)
target_link_libraries(openPMD.py PRIVATE openPMD)
if(WIN32)
set(CMAKE_INSTALL_PYTHONDIR_DEFAULT
"${CMAKE_INSTALL_LIBDIR}\\site-packages"
)
else()
set(CMAKE_INSTALL_PYTHONDIR_DEFAULT
"${CMAKE_INSTALL_LIBDIR}/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages"
)
endif()
set(CMAKE_INSTALL_PYTHONDIR "${CMAKE_INSTALL_PYTHONDIR_DEFAULT}"
CACHE STRING "Location for installed python package"
)
set(CMAKE_PYTHON_OUTPUT_DIRECTORY
"${openPMD_BINARY_DIR}/${CMAKE_INSTALL_PYTHONDIR}"
CACHE PATH "Build directory for python modules"
)
set_target_properties(openPMD.py PROPERTIES
ARCHIVE_OUTPUT_NAME openPMD
LIBRARY_OUTPUT_NAME openPMD
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_PYTHON_OUTPUT_DIRECTORY}
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_PYTHON_OUTPUT_DIRECTORY}
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_PYTHON_OUTPUT_DIRECTORY}
PDB_OUTPUT_DIRECTORY ${CMAKE_PYTHON_OUTPUT_DIRECTORY}
COMPILE_PDB_OUTPUT_DIRECTORY ${CMAKE_PYTHON_OUTPUT_DIRECTORY}
)
#if(openPMD_HAVE_MPI)
# target_link_libraries(openPMD.py PRIVATE PythonModule::mpi4py)
#endif()
endif()
# tests
set(openPMD_TEST_NAMES
Core
Auxiliary
SerialIO
ParallelIO
)
# examples
set(openPMD_EXAMPLE_NAMES
1_structure
2_read_serial
3_write_serial
4_read_parallel
5_write_parallel
6_dump_filebased_series
7_extended_write_serial
)
set(openPMD_PYTHON_EXAMPLE_NAMES
2_read_serial
3_write_serial
)
if(openPMD_USE_INVASIVE_TESTS STREQUAL AUTO)
if(WIN32)
set(openPMD_HAVE_INVASIVE_TESTS FALSE)
else()
set(openPMD_HAVE_INVASIVE_TESTS TRUE)
endif()
elseif(openPMD_USE_INVASIVE_TESTS)
set(openPMD_HAVE_INVASIVE_TESTS TRUE)
else()
set(openPMD_HAVE_INVASIVE_TESTS FALSE)
endif()
if(BUILD_TESTING)
foreach(testname ${openPMD_TEST_NAMES})
add_executable(${testname}Tests test/${testname}Test.cpp)
if(openPMD_HAVE_INVASIVE_TESTS)
target_compile_definitions(${testname}Tests PUBLIC "-DopenPMD_HAVE_INVASIVE_TESTS=1")
endif()
if(openPMD_HAVE_MPI)
target_compile_definitions(${testname}Tests PUBLIC "-DopenPMD_HAVE_MPI=1")
endif()
if(openPMD_HAVE_HDF5)
target_compile_definitions(${testname}Tests PUBLIC "-DopenPMD_HAVE_HDF5=1")
endif()
if(openPMD_HAVE_ADIOS1)
target_compile_definitions(${testname}Tests PUBLIC "-DopenPMD_HAVE_ADIOS1=1")
endif()
if(openPMD_HAVE_ADIOS2)
target_compile_definitions(${testname}Tests PUBLIC "-DopenPMD_HAVE_ADIOS2=1")
endif()
target_link_libraries(${testname}Tests PRIVATE openPMD)
if(TARGET Catch2::Catch)
target_link_libraries(${testname}Tests PRIVATE Catch2::Catch)
endif()
endforeach()
endif()
if(BUILD_EXAMPLES)
foreach(examplename ${openPMD_EXAMPLE_NAMES})
if(${examplename} MATCHES ".+parallel$")
if(openPMD_HAVE_MPI)
add_executable(${examplename} examples/${examplename}.cpp)
target_link_libraries(${examplename} PRIVATE openPMD)
endif()
else()
add_executable(${examplename} examples/${examplename}.cpp)
target_link_libraries(${examplename} PRIVATE openPMD)
endif()
endforeach()
endif()
# Warnings ####################################################################
#
# TODO: LEGACY! Use CMake TOOLCHAINS instead!
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address,memory,undefined")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weverything")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")
# pybind11 does not fix -Wshadow https://github.com/pybind/pybind11/issues/1267
if(NOT openPMD_HAVE_PYTHON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow")
endif()
string(CONCAT CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} "
"-Wno-unknown-pragmas")
# silence HDF5 (FIXME: -isystem should be enough)
string(CONCAT CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} "
"-Wno-reserved-id-macro -Wno-deprecated -Wno-old-style-cast "
"-Wno-cpp")
# older clangs: silence unknown warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-warning-option")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
# pybind11 does not fix -Wshadow https://github.com/pybind/pybind11/issues/1267
# pybind11 does not fix -Wpedantic https://github.com/pybind/pybind11/issues/1417
if(NOT openPMD_HAVE_PYTHON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow -Wpedantic")
endif()
string(CONCAT CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} "
"-Wno-unknown-pragmas")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# Warning C4503: "decorated name length exceeded, name was truncated"
# Symbols longer than 4096 chars are truncated
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd4503")
endif ()
# Generate Files with Configuration Options ###################################
#
# TODO configure a version.hpp
configure_file(
${openPMD_SOURCE_DIR}/openPMDConfig.cmake.in
${openPMD_BINARY_DIR}/openPMDConfig.cmake
@ONLY
)
include(CMakePackageConfigHelpers)
write_basic_package_version_file("openPMDConfigVersion.cmake"
VERSION ${openPMD_VERSION}
COMPATIBILITY SameMajorVersion
)
# Installs ####################################################################
#
# headers, libraries and exectuables
install(TARGETS openPMD openPMD.ADIOS1.Serial openPMD.ADIOS1.Parallel
EXPORT openPMDTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
if(openPMD_HAVE_PYTHON)
install(TARGETS openPMD.py
DESTINATION ${CMAKE_INSTALL_PYTHONDIR}
)
endif()
install(DIRECTORY "${openPMD_SOURCE_DIR}/include/openPMD"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
# install third-party libraries
if(openPMD_USE_INTERNAL_VARIANT)
install(DIRECTORY "${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/variant/include/mpark"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
endif()
# CMake package file for find_package(openPMD::openPMD) in depending projects
install(EXPORT openPMDTargets
FILE openPMDTargets.cmake
NAMESPACE openPMD::
DESTINATION ${CMAKE_INSTALL_CMAKEDIR}
)
install(
FILES
${openPMD_BINARY_DIR}/openPMDConfig.cmake
${openPMD_BINARY_DIR}/openPMDConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_CMAKEDIR}
)
install(
FILES
${openPMD_SOURCE_DIR}/share/openPMD/cmake/FindADIOS.cmake
DESTINATION ${CMAKE_INSTALL_CMAKEDIR}/Modules
)
# Tests #######################################################################
#
if(BUILD_TESTING)
enable_testing()
# OpenMPI root guard: https://github.com/open-mpi/ompi/issues/4451
if("$ENV{USER}" STREQUAL "root")
set(MPI_ALLOW_ROOT --allow-run-as-root)
endif()
set(MPI_TEST_EXE
${MPIEXEC_EXECUTABLE}
${MPI_ALLOW_ROOT}
${MPIEXEC_NUMPROC_FLAG} 2
)
# C++ Unit tests
foreach(testname ${openPMD_TEST_NAMES})
if(${testname} MATCHES "^Parallel.*$")
if(openPMD_HAVE_MPI)
add_test(NAME MPI.${testname}
COMMAND ${MPI_TEST_EXE} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${testname}Tests
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)
endif()
else()
add_test(NAME Serial.${testname}
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${testname}Tests
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)
endif()
endforeach()
endif()
# Python Unit tests
if(BUILD_TESTING)
if(openPMD_HAVE_PYTHON)
if(openPMD_HAVE_HDF5)
if(EXISTS "${openPMD_BINARY_DIR}/samples/git-sample/")
add_test(NAME Unittest.py
COMMAND ${PYTHON_EXECUTABLE}
${openPMD_SOURCE_DIR}/test/python/unittest/Test.py -v
WORKING_DIRECTORY
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)
if(WIN32)
string(REGEX REPLACE "/" "\\\\" WIN_BUILD_BASEDIR ${openPMD_BINARY_DIR})
string(REGEX REPLACE "/" "\\\\" WIN_BUILD_BINDIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
string(REPLACE ";" "\\;" WIN_PATH "$ENV{PATH}")
string(REPLACE ";" "\\;" WIN_PYTHONPATH "$ENV{PYTHONPATH}")
set_property(TEST Unittest.py
PROPERTY ENVIRONMENT
"PATH=${WIN_BUILD_BINDIR}\\${CMAKE_BUILD_TYPE}\;${WIN_PATH}\n"
"PYTHONPATH=${WIN_BUILD_BASEDIR}\\${CMAKE_INSTALL_PYTHONDIR}\\${CMAKE_BUILD_TYPE}\;${WIN_PYTHONPATH}"
)
else()
set_tests_properties(Unittest.py
PROPERTIES ENVIRONMENT
"PYTHONPATH=${openPMD_BINARY_DIR}/${CMAKE_INSTALL_PYTHONDIR}:$ENV{PYTHONPATH}"
)
endif()
endif()
endif()
endif()
endif()
# Examples ####################################################################
#
if(BUILD_EXAMPLES)
# C++ Examples
# Current examples all use HDF5, elaborate if other backends are used
if(openPMD_HAVE_HDF5)
if(EXISTS "${openPMD_BINARY_DIR}/samples/git-sample/")
foreach(examplename ${openPMD_EXAMPLE_NAMES})
if(${examplename} MATCHES "^.*_parallel$")
if(openPMD_HAVE_MPI)
add_test(NAME MPI.${examplename}
COMMAND ${MPI_TEST_EXE} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${examplename}
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)
endif()
else()
add_test(NAME Serial.${examplename}
COMMAND ${examplename}
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)
endif()
endforeach()
else()
message(STATUS "Note: Skipping C++ example tests (missing example files)")
endif()
endif()
endif()
# Python Examples
if(openPMD_HAVE_PYTHON)
if(EXISTS "${openPMD_BINARY_DIR}/samples/git-sample/")
foreach(examplename ${openPMD_PYTHON_EXAMPLE_NAMES})
add_custom_command(TARGET openPMD.py POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${openPMD_SOURCE_DIR}/examples/${examplename}.py
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${examplename}.py
)
if(BUILD_TESTING)
add_test(NAME Example.py.${examplename}
COMMAND ${PYTHON_EXECUTABLE}
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${examplename}.py
WORKING_DIRECTORY
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)
if(WIN32)
string(REGEX REPLACE "/" "\\\\" WIN_BUILD_BASEDIR ${openPMD_BINARY_DIR})
string(REGEX REPLACE "/" "\\\\" WIN_BUILD_BINDIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
string(REPLACE ";" "\\;" WIN_PATH "$ENV{PATH}")
string(REPLACE ";" "\\;" WIN_PYTHONPATH "$ENV{PYTHONPATH}")
set_property(TEST Example.py.${examplename}
PROPERTY ENVIRONMENT
"PATH=${WIN_BUILD_BINDIR}\\${CMAKE_BUILD_TYPE}\;${WIN_PATH}\n"
"PYTHONPATH=${WIN_BUILD_BASEDIR}\\${CMAKE_INSTALL_PYTHONDIR}\\${CMAKE_BUILD_TYPE}\;${WIN_PYTHONPATH}"
)
else()
set_tests_properties(Example.py.${examplename}
PROPERTIES ENVIRONMENT
"PYTHONPATH=${openPMD_BINARY_DIR}/${CMAKE_INSTALL_PYTHONDIR}:$ENV{PYTHONPATH}"
)
endif()
endif()
endforeach()
else()
message(STATUS "Note: Skipping Python example tests (missing example files)")
endif()
endif()
if(NOT EXISTS "${openPMD_BINARY_DIR}/samples/git-sample/")
if(WIN32)
message(STATUS "Note: run\n"
" Powershell.exe -File ${openPMD_SOURCE_DIR}/.travis/download_samples.ps1\n"
"to add example files to samples/git-sample/ directory!")
else()
message(STATUS "Note: run\n"
" . ${openPMD_SOURCE_DIR}/.travis/download_samples.sh\n"
"to add example files to samples/git-sample/ directory!")
endif()
endif()
# Status Message for Build Options ############################################
#
message("")
message("openPMD build configuration:")
message(" library Version: ${openPMD_VERSION}")
message(" openPMD Standard: ${openPMD_STANDARD_VERSION}")
message(" C++ Compiler: ${CMAKE_CXX_COMPILER_ID} "
"${CMAKE_CXX_COMPILER_VERSION} "
"${CMAKE_CXX_COMPILER_WRAPPER}")
message(" ${CMAKE_CXX_COMPILER}")
message("")
message(" Installation prefix: ${CMAKE_INSTALL_PREFIX}")
message(" bin: ${CMAKE_INSTALL_BINDIR}")
message(" lib: ${CMAKE_INSTALL_LIBDIR}")
message(" include: ${CMAKE_INSTALL_INCLUDEDIR}")
message(" cmake: ${CMAKE_INSTALL_CMAKEDIR}")
if(openPMD_HAVE_PYTHON)
message(" python: ${CMAKE_INSTALL_PYTHONDIR}")
endif()
message("")
message(" Additionally, install following third party libraries:")
message(" MPark.Variant: ${openPMD_USE_INTERNAL_VARIANT}")
message("")
message(" Build Type: ${CMAKE_BUILD_TYPE}")
message(" Testing: ${BUILD_TESTING}")
message(" Internal VERIFY: ${openPMD_USE_VERIFY}")
message(" Build Options:")
foreach(opt IN LISTS openPMD_CONFIG_OPTIONS)
if(${openPMD_HAVE_${opt}})
message(" ${opt}: ON")
else()
message(" ${opt}: OFF")
endif()
endforeach()
message("")