forked from openPMD/openPMD-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
1464 lines (1359 loc) · 59.5 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
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Preamble ####################################################################
#
cmake_minimum_required(VERSION 3.15.0)
project(openPMD VERSION 0.16.0) # LANGUAGES CXX
# the openPMD "markup"/"schema" standard version
set(openPMD_STANDARD_VERSION 1.1.0)
include(${openPMD_SOURCE_DIR}/cmake/openPMDFunctions.cmake)
# CMake policies ##############################################################
#
# Search in <PackageName>_ROOT:
# https://cmake.org/cmake/help/v3.12/policy/CMP0074.html
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()
# We use simple syntax in cmake_dependent_option, so we are compatible with the
# extended syntax in CMake 3.22+
# https://cmake.org/cmake/help/v3.22/policy/CMP0127.html
if(POLICY CMP0127)
cmake_policy(SET CMP0127 NEW)
endif()
# No in-Source builds #########################################################
#
# In-source builds clutter up the source directory and lead to mistakes with
# generated includes
if(openPMD_SOURCE_DIR STREQUAL openPMD_BINARY_DIR)
message(FATAL_ERROR "In-source builds are not possible. "
"Please remove the CMakeFiles/ directory and CMakeCache.txt file. "
"Then run CMake in a temporary build directory. "
"Learn more: https://hsf-training.github.io/hsf-training-cmake-webpage/02-building/index.html")
endif()
# Project structure ###########################################################
#
get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
# temporary build directories
if(NOT openPMD_ARCHIVE_OUTPUT_DIRECTORY)
if(CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
set(openPMD_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
else()
set(openPMD_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
endif()
endif()
if(NOT openPMD_LIBRARY_OUTPUT_DIRECTORY)
if(CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(openPMD_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
else()
set(openPMD_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
endif()
endif()
if(NOT openPMD_RUNTIME_OUTPUT_DIRECTORY)
if(CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(openPMD_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
else()
set(openPMD_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
endif()
endif()
if(NOT openPMD_PDB_OUTPUT_DIRECTORY)
if(CMAKE_PDB_OUTPUT_DIRECTORY)
set(openPMD_PDB_OUTPUT_DIRECTORY ${CMAKE_PDB_OUTPUT_DIRECTORY})
else()
set(openPMD_PDB_OUTPUT_DIRECTORY ${openPMD_LIBRARY_OUTPUT_DIRECTORY})
endif()
endif()
if(NOT openPMD_COMPILE_PDB_OUTPUT_DIRECTORY)
if(CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY)
set(openPMD_COMPILE_PDB_OUTPUT_DIRECTORY ${CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY})
else()
set(openPMD_COMPILE_PDB_OUTPUT_DIRECTORY ${openPMD_LIBRARY_OUTPUT_DIRECTORY})
endif()
endif()
# install directories
if(NOT CMAKE_INSTALL_LIBDIR AND NOT WIN32)
include(GNUInstallDirs)
endif()
if(NOT openPMD_INSTALL_PREFIX)
if(CMAKE_INSTALL_PREFIX)
set(openPMD_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
else()
message(FATAL_ERROR "openPMD_INSTALL_PREFIX / CMAKE_INSTALL_PREFIX not set.")
endif()
endif()
if(NOT openPMD_INSTALL_BINDIR)
if(CMAKE_INSTALL_BINDIR)
set(openPMD_INSTALL_BINDIR "${CMAKE_INSTALL_BINDIR}")
else()
set(openPMD_INSTALL_BINDIR bin)
endif()
endif()
if(NOT openPMD_INSTALL_INCLUDEDIR)
if(CMAKE_INSTALL_INCLUDEDIR)
set(openPMD_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}")
else()
set(openPMD_INSTALL_INCLUDEDIR include)
endif()
endif()
if(NOT openPMD_INSTALL_LIBDIR)
if(CMAKE_INSTALL_LIBDIR)
set(openPMD_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
else()
if(WIN32)
set(openPMD_INSTALL_LIBDIR Lib)
else()
set(openPMD_INSTALL_LIBDIR lib)
endif()
endif()
endif()
if(NOT openPMD_INSTALL_CMAKEDIR)
if(CMAKE_INSTALL_CMAKEDIR)
set(openPMD_INSTALL_CMAKEDIR "${CMAKE_INSTALL_CMAKEDIR}/openPMD")
else()
if(WIN32)
set(openPMD_INSTALL_CMAKEDIR "cmake")
else()
set(openPMD_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/openPMD")
endif()
endif()
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"
)
# list of all possible options
set(openPMD_CONFIG_OPTIONS ${openPMD_CONFIG_OPTIONS} ${name} PARENT_SCOPE)
endfunction()
openpmd_option(MPI "Parallel, Multi-Node I/O for clusters" AUTO)
openpmd_option(HDF5 "HDF5 backend (.h5 files)" AUTO)
openpmd_option(ADIOS2 "ADIOS2 backend (.bp files)" AUTO)
openpmd_option(PYTHON "Enable Python bindings" AUTO)
option(openPMD_INSTALL "Add installation targets" ON)
option(openPMD_INSTALL_RPATH "Add RPATHs to installed binaries" ON)
option(openPMD_HAVE_PKGCONFIG "Generate a .pc file for pkg-config" ON)
option(openPMD_USE_INTERNAL_CATCH "Use internally shipped Catch2" ON)
option(openPMD_USE_INTERNAL_PYBIND11 "Use internally shipped pybind11" ON)
option(openPMD_USE_INTERNAL_JSON "Use internally shipped nlohmann-json" ON)
option(openPMD_USE_INTERNAL_TOML11 "Use internally shipped toml11" ON)
option(openPMD_USE_INVASIVE_TESTS "Enable unit tests that modify source code" OFF)
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")
endif()
include(CMakeDependentOption)
# change CMake default (static libs):
# build shared libs if supported by target platform
get_property(SHARED_LIBS_SUPPORTED GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS)
if(DEFINED BUILD_SHARED_LIBS)
set(openPMD_BUILD_SHARED_LIBS_DEFAULT ${BUILD_SHARED_LIBS})
else()
set(openPMD_BUILD_SHARED_LIBS_DEFAULT ${SHARED_LIBS_SUPPORTED})
endif()
option(openPMD_BUILD_SHARED_LIBS "Build shared libraries (so/dylib/dll)."
${openPMD_BUILD_SHARED_LIBS_DEFAULT})
if(openPMD_BUILD_SHARED_LIBS AND NOT SHARED_LIBS_SUPPORTED)
message(FATAL_ERROR "openPMD_BUILD_SHARED_LIBS requested but not supported by platform")
endif()
# Testing logic with possibility to overwrite on a project basis in superbuilds
include(CTest)
mark_as_advanced(BUILD_TESTING) # automatically defined, default: ON
if(DEFINED BUILD_TESTING)
set(openPMD_BUILD_TESTING_DEFAULT ${BUILD_TESTING})
else()
set(openPMD_BUILD_TESTING_DEFAULT ON)
endif()
option(openPMD_BUILD_TESTING "Build the openPMD tests"
${openPMD_BUILD_TESTING_DEFAULT})
# deprecated: backwards compatibility to <= 0.13.*
if(NOT DEFINED BUILD_CLI_TOOLS)
set(BUILD_CLI_TOOLS ON)
endif()
if(NOT DEFINED BUILD_EXAMPLES)
set(BUILD_EXAMPLES ON)
endif()
option(openPMD_BUILD_CLI_TOOLS "Build the command line tools" ${BUILD_CLI_TOOLS})
option(openPMD_BUILD_EXAMPLES "Build the examples" ${BUILD_EXAMPLES})
openpmd_option(CUDA_EXAMPLES "Use CUDA in examples" OFF)
# Helper Functions ############################################################
#
# C++ standard: requirements for a target
function(openpmd_cxx_required target)
target_compile_features(${target} PUBLIC cxx_std_17)
set_target_properties(${target} PROPERTIES
CXX_EXTENSIONS OFF
CXX_STANDARD_REQUIRED ON
)
endfunction()
# CUDA C++ standard: requirements for a target
function(openpmd_cuda_required target)
target_compile_features(${target} PUBLIC cuda_std_17)
set_target_properties(${target} PROPERTIES
CUDA_SEPARABLE_COMPILATION ON
CUDA_EXTENSIONS OFF
CUDA_STANDARD_REQUIRED ON)
endfunction()
# Dependencies ################################################################
#
# external library: MPI (optional)
# Implementation quirks for BullMPI, Clang+MPI and Brew's MPICH
# definitely w/o MPI::MPI_C:
# brew's MPICH with C-flag work-arounds - errors AppleClang for CXX targets
# https://github.com/Homebrew/homebrew-core/issues/80465
# https://lists.mpich.org/pipermail/discuss/2020-January/005863.html
# sometimes needed MPI::MPI_C in the past:
# Clang+MPI: Potentially needed MPI::MPI_C targets in the past
# (exact MPI flavor & Clang version lost)
# BullMPI: PUBLIC dependency to MPI::MPI_CXX is missing in MPI::MPI_C target
set(openPMD_MPI_LINK_C_DEFAULT OFF)
option(openPMD_MPI_LINK_C "Also link the MPI C targets" ${openPMD_MPI_LINK_C_DEFAULT})
mark_as_advanced(openPMD_MPI_LINK_C)
set(openPMD_MPI_NEED_COMPONENTS CXX)
set(openPMD_MPI_TARGETS MPI::MPI_CXX)
if(openPMD_MPI_LINK_C)
set(openPMD_MPI_NEED_COMPONENTS C ${openPMD_MPI_NEED_COMPONENTS})
set(openPMD_MPI_TARGETS MPI::MPI_C ${openPMD_MPI_TARGETS})
endif()
if(openPMD_USE_MPI STREQUAL AUTO)
find_package(MPI COMPONENTS ${openPMD_MPI_NEED_COMPONENTS})
if(MPI_FOUND)
set(openPMD_HAVE_MPI TRUE)
else()
set(openPMD_HAVE_MPI FALSE)
endif()
elseif(openPMD_USE_MPI)
find_package(MPI REQUIRED COMPONENTS ${openPMD_MPI_NEED_COMPONENTS})
set(openPMD_HAVE_MPI TRUE)
else()
set(openPMD_HAVE_MPI FALSE)
endif()
# external library: nlohmann-json (required)
if(openPMD_USE_INTERNAL_JSON)
set(JSON_BuildTests OFF CACHE INTERNAL "")
set(JSON_Install OFF CACHE INTERNAL "") # only used PRIVATE
add_subdirectory("${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/json")
message(STATUS "nlohmann-json: Using INTERNAL version '3.9.1'")
else()
find_package(nlohmann_json 3.9.1 CONFIG REQUIRED)
message(STATUS "nlohmann-json: Found version '${nlohmann_json_VERSION}'")
endif()
add_library(openPMD::thirdparty::nlohmann_json INTERFACE IMPORTED)
target_link_libraries(openPMD::thirdparty::nlohmann_json
INTERFACE nlohmann_json::nlohmann_json)
# external library: toml11
if(openPMD_USE_INTERNAL_TOML11)
set(toml11_INSTALL OFF CACHE INTERNAL "")
add_subdirectory("${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/toml11")
message(STATUS "toml11: Using INTERNAL version '3.7.1'")
else()
# toml11 4.0 was a breaking change. This is reflected in the library's CMake
# logic: version 4.0 is not accepted by a call to find_package(toml11 3.7).
# Since we support both incompatible versions, we use two find_package()
# calls. Search for version 4 first in order to prefer that
# in (the unlikely) case that both versions are installed.
find_package(toml11 4.0 CONFIG QUIET)
if(NOT toml11_FOUND)
find_package(toml11 3.7.1 CONFIG REQUIRED)
endif()
message(STATUS "toml11: Found version '${toml11_VERSION}'")
endif()
add_library(openPMD::thirdparty::toml11 INTERFACE IMPORTED)
target_link_libraries(openPMD::thirdparty::toml11
INTERFACE toml11::toml11)
# external: CUDA (optional)
if(openPMD_BUILD_EXAMPLES) # currently only used in examples
if(openPMD_USE_CUDA_EXAMPLES STREQUAL AUTO)
find_package(CUDAToolkit)
elseif(openPMD_USE_CUDA_EXAMPLES)
find_package(CUDAToolkit REQUIRED)
endif()
endif()
if(CUDAToolkit_FOUND)
enable_language(CUDA)
set(openPMD_HAVE_CUDA_EXAMPLES TRUE)
else()
set(openPMD_HAVE_CUDA_EXAMPLES FALSE)
endif()
# external library: HDF5 (optional)
# note: in the new hdf5-cmake.config files, major releases like
# 1.8, 1.10 and 1.12 are not marked compatible versions
# We could use CMake 3.19.0+ version ranges, but:
# - this issues a Wdev warning with FindHDF5.cmake
# - does not work at least with HDF5 1.10:
# Could not find a configuration file for package "HDF5" that is compatible
# with requested version range "1.8.13...1.12".
# The following configuration files were considered but not accepted:
# ../share/cmake/hdf5/hdf5-config.cmake, version: 1.10.7
# - thus, we do our own HDF5_VERSION check...
if(openPMD_USE_HDF5 STREQUAL AUTO)
set(HDF5_PREFER_PARALLEL ${openPMD_HAVE_MPI})
find_package(HDF5 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 REQUIRED COMPONENTS C)
set(openPMD_HAVE_HDF5 TRUE)
else()
set(openPMD_HAVE_HDF5 FALSE)
endif()
# HDF5 checks
string(CONCAT openPMD_HDF5_STATUS "")
# version: lower limit
if(openPMD_HAVE_HDF5)
if(HDF5_VERSION STREQUAL "")
message(WARNING "HDF5_VERSION is empty. Now assuming it is 1.8.13 or newer.")
else()
if(HDF5_VERSION VERSION_LESS 1.8.13)
string(CONCAT openPMD_HDF5_STATUS
"Found HDF5 version ${HDF5_VERSION} is too old. At least "
"version 1.8.13 is required.\n")
endif()
endif()
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 # FindHDF5.cmake
AND NOT HDF5_ENABLE_PARALLEL # hdf5-config.cmake
)
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.\n")
endif()
# HDF5 includes mpi.h in the public header H5public.h if parallel
if(openPMD_HAVE_HDF5 AND
(HDF5_IS_PARALLEL OR HDF5_ENABLE_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.\n")
endif()
if(openPMD_HDF5_STATUS)
string(CONCAT openPMD_HDF5_STATUS
${openPMD_HDF5_STATUS}
"If you manually installed a version of HDF5 in "
"a non-default path, add its installation prefix to the "
"environment variable CMAKE_PREFIX_PATH to find it: "
"https://cmake.org/cmake/help/latest/envvar/CMAKE_PREFIX_PATH.html")
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()
# external library: ADIOS2 (optional)
if(openPMD_USE_ADIOS2 STREQUAL AUTO)
find_package(ADIOS2 2.7.0 CONFIG)
if(ADIOS2_FOUND)
set(openPMD_HAVE_ADIOS2 TRUE)
else()
set(openPMD_HAVE_ADIOS2 FALSE)
endif()
elseif(openPMD_USE_ADIOS2)
find_package(ADIOS2 2.7.0 REQUIRED CONFIG)
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)
set(_PY_DEV_MODULE Development.Module)
if(CMAKE_VERSION VERSION_LESS 3.18.0)
# over-specification needed for CMake<3.18
# https://pybind11.readthedocs.io/en/latest/compiling.html#findpython-mode
# https://cmake.org/cmake/help/v3.18/module/FindPython.html
set(_PY_DEV_MODULE Development)
endif()
if(openPMD_USE_PYTHON STREQUAL AUTO)
find_package(Python 3.8.0 COMPONENTS Interpreter ${_PY_DEV_MODULE})
if(Python_FOUND)
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.12.0")
else()
find_package(pybind11 2.12.0 CONFIG)
if(pybind11_FOUND)
set(openPMD_HAVE_PYTHON TRUE)
message(STATUS "pybind11: Found version '${pybind11_VERSION}'")
else()
set(openPMD_HAVE_PYTHON FALSE)
endif()
endif()
else()
set(openPMD_HAVE_PYTHON FALSE)
endif()
elseif(openPMD_USE_PYTHON)
find_package(Python COMPONENTS Interpreter ${_PY_DEV_MODULE} REQUIRED)
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.12.0")
else()
find_package(pybind11 2.12.0 REQUIRED CONFIG)
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/config.cpp
src/ChunkInfo.cpp
src/Dataset.cpp
src/Datatype.cpp
src/Error.cpp
src/Format.cpp
src/Iteration.cpp
src/IterationEncoding.cpp
src/Mesh.cpp
src/ParticlePatches.cpp
src/ParticleSpecies.cpp
src/ReadIterations.cpp
src/Record.cpp
src/RecordComponent.cpp
src/Series.cpp
src/version.cpp
src/WriteIterations.cpp
src/auxiliary/Date.cpp
src/auxiliary/Filesystem.cpp
src/auxiliary/JSON.cpp
src/auxiliary/Mpi.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
src/benchmark/mpi/OneDimensionalBlockSlicer.cpp
src/helper/list_series.cpp)
set(IO_SOURCE
src/IO/AbstractIOHandler.cpp
src/IO/AbstractIOHandlerImpl.cpp
src/IO/AbstractIOHandlerHelper.cpp
src/IO/DummyIOHandler.cpp
src/IO/IOTask.cpp
src/IO/FlushParams.cpp
src/IO/HDF5/HDF5IOHandler.cpp
src/IO/HDF5/ParallelHDF5IOHandler.cpp
src/IO/HDF5/HDF5Auxiliary.cpp
src/IO/JSON/JSONIOHandler.cpp
src/IO/JSON/JSONIOHandlerImpl.cpp
src/IO/JSON/JSONFilePosition.cpp
src/IO/ADIOS/ADIOS2IOHandler.cpp
src/IO/ADIOS/ADIOS2File.cpp
src/IO/ADIOS/ADIOS2Auxiliary.cpp
src/IO/InvalidatableFile.cpp)
# library
if(openPMD_BUILD_SHARED_LIBS)
set(_openpmd_lib_type SHARED)
else()
set(_openpmd_lib_type STATIC)
endif()
add_library(openPMD ${_openpmd_lib_type} ${CORE_SOURCE} ${IO_SOURCE})
add_library(openPMD::openPMD ALIAS openPMD)
# properties
openpmd_cxx_required(openPMD)
set_target_properties(openPMD PROPERTIES
COMPILE_PDB_NAME openPMD
ARCHIVE_OUTPUT_DIRECTORY ${openPMD_ARCHIVE_OUTPUT_DIRECTORY}
LIBRARY_OUTPUT_DIRECTORY ${openPMD_LIBRARY_OUTPUT_DIRECTORY}
RUNTIME_OUTPUT_DIRECTORY ${openPMD_RUNTIME_OUTPUT_DIRECTORY}
PDB_OUTPUT_DIRECTORY ${openPMD_PDB_OUTPUT_DIRECTORY}
COMPILE_PDB_OUTPUT_DIRECTORY ${openPMD_COMPILE_PDB_OUTPUT_DIRECTORY}
POSITION_INDEPENDENT_CODE ON
WINDOWS_EXPORT_ALL_SYMBOLS ON
)
# note: same as above, but for Multi-Config generators
if(isMultiConfig)
# this is a tweak for setup.py to pick up our libs & pybind module properly
# this assumes there will only be one config built
option(openPMD_BUILD_NO_CFG_SUBPATH
"For multi-config builds, do not appends the config to build dir" OFF)
mark_as_advanced(openPMD_BUILD_NO_CFG_SUBPATH)
foreach(CFG IN LISTS CMAKE_CONFIGURATION_TYPES)
string(TOUPPER "${CFG}" CFG_UPPER)
if(openPMD_BUILD_NO_CFG_SUBPATH) # for setup.py
set(CFG_PATH "")
else()
set(CFG_PATH "/${CFG}")
endif()
set_target_properties(openPMD PROPERTIES
COMPILE_PDB_NAME_${CFG_UPPER} openPMD
ARCHIVE_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_ARCHIVE_OUTPUT_DIRECTORY}${CFG_PATH}
LIBRARY_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_LIBRARY_OUTPUT_DIRECTORY}${CFG_PATH}
RUNTIME_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_RUNTIME_OUTPUT_DIRECTORY}${CFG_PATH}
PDB_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_PDB_OUTPUT_DIRECTORY}${CFG_PATH}
COMPILE_PDB_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_COMPILE_PDB_OUTPUT_DIRECTORY}${CFG_PATH}
)
endforeach()
endif()
set(_cxx_msvc "$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>")
set(_msvc_1914 "$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,19.14>")
set(_msvc_options)
list(APPEND _msvc_options
$<${_cxx_msvc}:/bigobj>
$<${_cxx_msvc}:$<${_msvc_1914}:/Zc:__cplusplus>>
)
target_compile_options(openPMD PUBLIC ${_msvc_options})
# own headers
target_include_directories(openPMD PUBLIC
$<BUILD_INTERFACE:${openPMD_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${openPMD_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
)
# Catch2 for unit tests
if(openPMD_BUILD_TESTING)
add_library(openPMD::thirdparty::Catch2 INTERFACE IMPORTED)
if(openPMD_USE_INTERNAL_CATCH)
target_include_directories(openPMD::thirdparty::Catch2 SYSTEM INTERFACE
$<BUILD_INTERFACE:${openPMD_SOURCE_DIR}/share/openPMD/thirdParty/catch2/include>
)
message(STATUS "Catch2: Using INTERNAL version '2.13.10'")
else()
find_package(Catch2 2.13.10 REQUIRED CONFIG)
target_link_libraries(openPMD::thirdparty::Catch2
INTERFACE Catch2::Catch2)
message(STATUS "Catch2: Found version '${Catch2_VERSION}'")
endif()
endif()
if(openPMD_HAVE_MPI)
target_link_libraries(openPMD PUBLIC ${openPMD_MPI_TARGETS})
endif()
# JSON Backend and User-Facing Runtime Options
#target_link_libraries(openPMD PRIVATE openPMD::thirdparty::nlohmann_json)
target_include_directories(openPMD SYSTEM PRIVATE
$<TARGET_PROPERTY:openPMD::thirdparty::nlohmann_json,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:openPMD::thirdparty::toml11,INTERFACE_INCLUDE_DIRECTORIES>)
# HDF5 Backend
# TODO: Once we require CMake 3.20+, simply link hdf5::hdf5 C lib target
if(openPMD_HAVE_HDF5)
target_link_libraries(openPMD PUBLIC ${HDF5_LIBRARIES})
target_include_directories(openPMD SYSTEM PRIVATE ${HDF5_INCLUDE_DIRS})
target_compile_definitions(openPMD PRIVATE ${HDF5_DEFINITIONS})
endif()
# ADIOS2 Backend
if(openPMD_HAVE_ADIOS2)
if(openPMD_HAVE_MPI)
target_link_libraries(openPMD PUBLIC adios2::cxx11_mpi)
else()
target_link_libraries(openPMD PUBLIC adios2::cxx11)
endif()
endif()
# Runtime parameter and API status checks ("asserts")
if(openPMD_USE_VERIFY)
target_compile_definitions(openPMD PRIVATE openPMD_USE_VERIFY=1)
else()
target_compile_definitions(openPMD PRIVATE openPMD_USE_VERIFY=0)
endif()
# python bindings
if(openPMD_HAVE_PYTHON)
add_library(openPMD.py MODULE
src/binding/python/openPMD.cpp
src/binding/python/Access.cpp
src/binding/python/Attributable.cpp
src/binding/python/BaseRecordComponent.cpp
src/binding/python/ChunkInfo.cpp
src/binding/python/Dataset.cpp
src/binding/python/Datatype.cpp
src/binding/python/Error.cpp
src/binding/python/Helper.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/PatchRecord.cpp
src/binding/python/PatchRecordComponent.cpp
src/binding/python/Record.cpp
src/binding/python/RecordComponent.cpp
src/binding/python/MeshRecordComponent.cpp
src/binding/python/Series.cpp
src/binding/python/UnitDimension.cpp
)
target_link_libraries(openPMD.py PRIVATE openPMD)
target_link_libraries(openPMD.py PRIVATE pybind11::module pybind11::windows_extras)
# LTO/IPO: CMake target properties work well for 3.18+ and are buggy before
set(_USE_PY_LTO ON) # default shall be ON
if(DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION) # overwrite default if defined
if(NOT CMAKE_INTERPROCEDURAL_OPTIMIZATION)
set(_USE_PY_LTO OFF)
endif()
endif()
message(STATUS "Python LTO/IPO: ${_USE_PY_LTO}")
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.18)
set_target_properties(openPMD.py PROPERTIES
INTERPROCEDURAL_OPTIMIZATION ${_USE_PY_LTO})
else()
if(_USE_PY_LTO)
target_link_libraries(openPMD.py PRIVATE pybind11::lto)
endif()
endif()
unset(_USE_PY_LTO)
if(EMSCRIPTEN)
set_target_properties(openPMD.py PROPERTIES
PREFIX "")
else()
pybind11_extension(openPMD.py)
endif()
if(NOT MSVC AND NOT ${CMAKE_BUILD_TYPE} MATCHES Debug|RelWithDebInfo)
pybind11_strip(openPMD.py)
endif()
set_target_properties(openPMD.py PROPERTIES CXX_VISIBILITY_PRESET "hidden"
CUDA_VISIBILITY_PRESET "hidden")
# ancient Clang releases
# https://github.com/openPMD/openPMD-api/issues/542
# https://pybind11.readthedocs.io/en/stable/faq.html#recursive-template-instantiation-exceeded-maximum-depth-of-256
# https://bugs.llvm.org/show_bug.cgi?id=18417
# https://github.com/llvm/llvm-project/commit/e55b4737c026ea2e0b44829e4115d208577a67b2
if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang" AND
CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.1) OR
("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND
CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.0))
message(STATUS "Clang: Passing -ftemplate-depth=1024")
target_compile_options(openPMD.py
PRIVATE -ftemplate-depth=1024)
endif()
if(WIN32)
set(openPMD_INSTALL_PYTHONDIR_DEFAULT
"${CMAKE_INSTALL_LIBDIR}/site-packages")
else()
set(openPMD_INSTALL_PYTHONDIR_DEFAULT
"${CMAKE_INSTALL_LIBDIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages"
)
endif()
set(openPMD_INSTALL_PYTHONDIR "${openPMD_INSTALL_PYTHONDIR_DEFAULT}"
CACHE STRING "Location for installed python package")
set(openPMD_PYTHON_OUTPUT_DIRECTORY "${openPMD_BINARY_DIR}/${openPMD_INSTALL_PYTHONDIR}"
CACHE STRING "Build directory for python modules")
set_target_properties(openPMD.py PROPERTIES
ARCHIVE_OUTPUT_NAME openpmd_api_cxx
LIBRARY_OUTPUT_NAME openpmd_api_cxx
COMPILE_PDB_NAME openpmd_api_cxx
ARCHIVE_OUTPUT_DIRECTORY ${openPMD_PYTHON_OUTPUT_DIRECTORY}/openpmd_api
LIBRARY_OUTPUT_DIRECTORY ${openPMD_PYTHON_OUTPUT_DIRECTORY}/openpmd_api
RUNTIME_OUTPUT_DIRECTORY ${openPMD_PYTHON_OUTPUT_DIRECTORY}/openpmd_api
PDB_OUTPUT_DIRECTORY ${openPMD_PYTHON_OUTPUT_DIRECTORY}/openpmd_api
COMPILE_PDB_OUTPUT_DIRECTORY ${openPMD_PYTHON_OUTPUT_DIRECTORY}/openpmd_api
)
# note: same as above, but for Multi-Config generators
if(isMultiConfig)
foreach(CFG IN LISTS CMAKE_CONFIGURATION_TYPES)
string(TOUPPER "${CFG}" CFG_UPPER)
if(openPMD_BUILD_NO_CFG_SUBPATH) # for setup.py
set(CFG_PATH "")
else()
set(CFG_PATH "/${CFG}")
endif()
set_target_properties(openPMD.py PROPERTIES
COMPILE_PDB_NAME_${CFG_UPPER} openpmd_api_cxx
ARCHIVE_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_PYTHON_OUTPUT_DIRECTORY}${CFG_PATH}/openpmd_api
LIBRARY_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_PYTHON_OUTPUT_DIRECTORY}${CFG_PATH}/openpmd_api
RUNTIME_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_PYTHON_OUTPUT_DIRECTORY}${CFG_PATH}/openpmd_api
PDB_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_PYTHON_OUTPUT_DIRECTORY}${CFG_PATH}/openpmd_api
COMPILE_PDB_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_PYTHON_OUTPUT_DIRECTORY}${CFG_PATH}/openpmd_api
)
endforeach()
endif()
function(copy_aux_py)
set(AUX_PY_SRC_DIR ${openPMD_SOURCE_DIR}/src/binding/python/openpmd_api/)
set(AUX_PY_DSR_DIR ${openPMD_PYTHON_OUTPUT_DIRECTORY}/openpmd_api/)
foreach(src_name IN LISTS ARGN)
configure_file(${AUX_PY_SRC_DIR}/${src_name} ${AUX_PY_DSR_DIR}/${src_name} COPYONLY)
endforeach()
endfunction()
copy_aux_py(
__init__.py DaskArray.py DaskDataFrame.py DataFrame.py
ls/__init__.py ls/__main__.py
pipe/__init__.py pipe/__main__.py
)
endif()
# tests
set(openPMD_TEST_NAMES
Core
Auxiliary
SerialIO
ParallelIO
JSON
)
# command line tools
set(openPMD_CLI_TOOL_NAMES
ls
)
set(openPMD_PYTHON_CLI_TOOL_NAMES
pipe
)
set(openPMD_PYTHON_CLI_MODULE_NAMES ${openPMD_CLI_TOOL_NAMES})
# examples
set(openPMD_EXAMPLE_NAMES
1_structure
2_read_serial
2a_read_thetaMode_serial
3_write_serial
3a_write_thetaMode_serial
3b_write_resizable_particles
4_read_parallel
5_write_parallel
6_dump_filebased_series
7_extended_write_serial
8_benchmark_parallel
8a_benchmark_write_parallel
8b_benchmark_read_parallel
10_streaming_write
10_streaming_read
12_span_write
13_write_dynamic_configuration
)
set(openPMD_PYTHON_EXAMPLE_NAMES
2_read_serial
2a_read_thetaMode_serial
3_write_serial
3a_write_thetaMode_serial
3b_write_resizable_particles
4_read_parallel
5_write_parallel
7_extended_write_serial
9_particle_write_serial
10_streaming_write
10_streaming_read
11_particle_dataframe
12_span_write
13_write_dynamic_configuration
)
if(openPMD_USE_INVASIVE_TESTS)
if(WIN32)
message(WARNING "Invasive tests that redefine class signatures are "
"known to fail on Windows!")
endif()
target_compile_definitions(openPMD PRIVATE openPMD_USE_INVASIVE_TESTS=1)
endif()
if(openPMD_BUILD_TESTING)
# compile Catch2 implementation part separately
add_library(CatchRunner ${_openpmd_lib_type}
test/CatchRunner.cpp) # Always MPI_Init with Serial Fallback
add_library(CatchMain ${_openpmd_lib_type}
test/CatchMain.cpp) # Serial only
openpmd_cxx_required(CatchRunner)
openpmd_cxx_required(CatchMain)
set_target_properties(CatchRunner CatchMain PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${openPMD_ARCHIVE_OUTPUT_DIRECTORY}
LIBRARY_OUTPUT_DIRECTORY ${openPMD_LIBRARY_OUTPUT_DIRECTORY}
RUNTIME_OUTPUT_DIRECTORY ${openPMD_RUNTIME_OUTPUT_DIRECTORY}
PDB_OUTPUT_DIRECTORY ${openPMD_PDB_OUTPUT_DIRECTORY}
COMPILE_PDB_OUTPUT_DIRECTORY ${openPMD_COMPILE_PDB_OUTPUT_DIRECTORY}
POSITION_INDEPENDENT_CODE ON
WINDOWS_EXPORT_ALL_SYMBOLS ON
)
set_target_properties(CatchRunner PROPERTIES COMPILE_PDB_NAME CatchRunner)
set_target_properties(CatchMain PROPERTIES COMPILE_PDB_NAME CatchMain)
# note: same as above, but for Multi-Config generators
if(isMultiConfig)
foreach(CFG IN LISTS CMAKE_CONFIGURATION_TYPES)
string(TOUPPER "${CFG}" CFG_UPPER)
set_target_properties(CatchRunner PROPERTIES
COMPILE_PDB_NAME_${CFG_UPPER} CatchRunner
ARCHIVE_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_ARCHIVE_OUTPUT_DIRECTORY}/${CFG}
LIBRARY_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_LIBRARY_OUTPUT_DIRECTORY}/${CFG}
RUNTIME_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_RUNTIME_OUTPUT_DIRECTORY}/${CFG}
PDB_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_PDB_OUTPUT_DIRECTORY}/${CFG}
COMPILE_PDB_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_COMPILE_PDB_OUTPUT_DIRECTORY}/${CFG}
)
set_target_properties(CatchMain PROPERTIES
COMPILE_PDB_NAME_${CFG_UPPER} CatchMain
ARCHIVE_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_ARCHIVE_OUTPUT_DIRECTORY}/${CFG}
LIBRARY_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_LIBRARY_OUTPUT_DIRECTORY}/${CFG}
RUNTIME_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_RUNTIME_OUTPUT_DIRECTORY}/${CFG}
PDB_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_PDB_OUTPUT_DIRECTORY}/${CFG}
COMPILE_PDB_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_COMPILE_PDB_OUTPUT_DIRECTORY}/${CFG}
)
endforeach()
endif()
target_compile_options(CatchRunner PUBLIC ${_msvc_options})
target_compile_options(CatchMain PUBLIC ${_msvc_options})
target_link_libraries(CatchRunner PUBLIC openPMD::thirdparty::Catch2)
target_link_libraries(CatchMain PUBLIC openPMD::thirdparty::Catch2)
if(openPMD_HAVE_MPI)
target_link_libraries(CatchRunner PUBLIC ${openPMD_MPI_TARGETS})
target_compile_definitions(CatchRunner PUBLIC openPMD_HAVE_MPI=1)
endif()
foreach(testname ${openPMD_TEST_NAMES})
add_executable(${testname}Tests test/${testname}Test.cpp)
openpmd_cxx_required(${testname}Tests)
set_target_properties(${testname}Tests PROPERTIES
COMPILE_PDB_NAME ${testname}Tests
ARCHIVE_OUTPUT_DIRECTORY ${openPMD_ARCHIVE_OUTPUT_DIRECTORY}
LIBRARY_OUTPUT_DIRECTORY ${openPMD_LIBRARY_OUTPUT_DIRECTORY}
RUNTIME_OUTPUT_DIRECTORY ${openPMD_RUNTIME_OUTPUT_DIRECTORY}
PDB_OUTPUT_DIRECTORY ${openPMD_RUNTIME_OUTPUT_DIRECTORY}
COMPILE_PDB_OUTPUT_DIRECTORY ${openPMD_RUNTIME_OUTPUT_DIRECTORY}
)
# note: same as above, but for Multi-Config generators
if(isMultiConfig)
foreach(CFG IN LISTS CMAKE_CONFIGURATION_TYPES)
string(TOUPPER "${CFG}" CFG_UPPER)
set_target_properties(${testname}Tests PROPERTIES
COMPILE_PDB_NAME_${CFG_UPPER} ${testname}Tests
ARCHIVE_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_ARCHIVE_OUTPUT_DIRECTORY}/${CFG}
LIBRARY_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_LIBRARY_OUTPUT_DIRECTORY}/${CFG}
RUNTIME_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_RUNTIME_OUTPUT_DIRECTORY}/${CFG}
PDB_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_RUNTIME_OUTPUT_DIRECTORY}/${CFG}
COMPILE_PDB_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_RUNTIME_OUTPUT_DIRECTORY}/${CFG}
)
endforeach()
endif()
if(openPMD_USE_INVASIVE_TESTS)
target_compile_definitions(${testname}Tests PRIVATE openPMD_USE_INVASIVE_TESTS=1)
endif()
target_link_libraries(${testname}Tests PRIVATE openPMD)
if(${testname} MATCHES "Parallel.+$")
target_link_libraries(${testname}Tests PRIVATE CatchRunner)
else()
target_link_libraries(${testname}Tests PRIVATE CatchMain)
endif()
if(${testname} STREQUAL JSON)
target_include_directories(${testname}Tests SYSTEM PRIVATE
$<TARGET_PROPERTY:openPMD::thirdparty::nlohmann_json,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:openPMD::thirdparty::toml11,INTERFACE_INCLUDE_DIRECTORIES>)
endif()
endforeach()
endif()
if(openPMD_BUILD_CLI_TOOLS)
foreach(toolname ${openPMD_CLI_TOOL_NAMES})
add_executable(openpmd-${toolname} src/cli/${toolname}.cpp)
openpmd_cxx_required(openpmd-${toolname})
set_target_properties(openpmd-${toolname} PROPERTIES
COMPILE_PDB_NAME openpmd-${toolname}
ARCHIVE_OUTPUT_DIRECTORY ${openPMD_ARCHIVE_OUTPUT_DIRECTORY}
LIBRARY_OUTPUT_DIRECTORY ${openPMD_LIBRARY_OUTPUT_DIRECTORY}
RUNTIME_OUTPUT_DIRECTORY ${openPMD_RUNTIME_OUTPUT_DIRECTORY}
PDB_OUTPUT_DIRECTORY ${openPMD_RUNTIME_OUTPUT_DIRECTORY}
COMPILE_PDB_OUTPUT_DIRECTORY ${openPMD_RUNTIME_OUTPUT_DIRECTORY}
)
# note: same as above, but for Multi-Config generators
if(isMultiConfig)
foreach(CFG IN LISTS CMAKE_CONFIGURATION_TYPES)
string(TOUPPER "${CFG}" CFG_UPPER)
set_target_properties(openpmd-${toolname} PROPERTIES
COMPILE_PDB_NAME_${CFG_UPPER} openpmd-${toolname}
ARCHIVE_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_ARCHIVE_OUTPUT_DIRECTORY}/${CFG}
LIBRARY_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_LIBRARY_OUTPUT_DIRECTORY}/${CFG}
RUNTIME_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_RUNTIME_OUTPUT_DIRECTORY}/${CFG}
PDB_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_RUNTIME_OUTPUT_DIRECTORY}/${CFG}
COMPILE_PDB_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_RUNTIME_OUTPUT_DIRECTORY}/${CFG}
)
endforeach()
endif()
target_link_libraries(openpmd-${toolname} PRIVATE openPMD)
endforeach()
endif()
if(openPMD_BUILD_EXAMPLES)
foreach(examplename ${openPMD_EXAMPLE_NAMES})
if(${examplename} MATCHES ".+parallel$" AND NOT openPMD_HAVE_MPI)
# skip parallel test
continue()
endif()
add_executable(${examplename} examples/${examplename}.cpp)
if (openPMD_HAVE_CUDA_EXAMPLES)
set_source_files_properties(examples/${examplename}.cpp
PROPERTIES LANGUAGE CUDA)
openpmd_cuda_required(${examplename})
else()
openpmd_cxx_required(${examplename})
endif()
set_target_properties(${examplename} PROPERTIES
COMPILE_PDB_NAME ${examplename}
ARCHIVE_OUTPUT_DIRECTORY ${openPMD_ARCHIVE_OUTPUT_DIRECTORY}
LIBRARY_OUTPUT_DIRECTORY ${openPMD_LIBRARY_OUTPUT_DIRECTORY}
RUNTIME_OUTPUT_DIRECTORY ${openPMD_RUNTIME_OUTPUT_DIRECTORY}
PDB_OUTPUT_DIRECTORY ${openPMD_RUNTIME_OUTPUT_DIRECTORY}
COMPILE_PDB_OUTPUT_DIRECTORY ${openPMD_RUNTIME_OUTPUT_DIRECTORY}
)
# note: same as above, but for Multi-Config generators
if(isMultiConfig)
foreach(CFG IN LISTS CMAKE_CONFIGURATION_TYPES)
string(TOUPPER "${CFG}" CFG_UPPER)
set_target_properties(${examplename} PROPERTIES
COMPILE_PDB_NAME_${CFG_UPPER} ${examplename}
ARCHIVE_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_ARCHIVE_OUTPUT_DIRECTORY}/${CFG}
LIBRARY_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_LIBRARY_OUTPUT_DIRECTORY}/${CFG}
RUNTIME_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_RUNTIME_OUTPUT_DIRECTORY}/${CFG}
PDB_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_RUNTIME_OUTPUT_DIRECTORY}/${CFG}
COMPILE_PDB_OUTPUT_DIRECTORY_${CFG_UPPER} ${openPMD_RUNTIME_OUTPUT_DIRECTORY}/${CFG}
)
endforeach()
endif()
target_link_libraries(${examplename} PRIVATE openPMD)
endforeach()
endif()
# Warnings ####################################################################
#
# TODO: LEGACY! Use CMake TOOLCHAINS instead!
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
# On Windows, Clang -Wall aliases -Weverything; default is /W3
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND NOT WIN32)
# list(APPEND CMAKE_CXX_FLAGS "-fsanitize=address") # address, memory, undefined
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
# set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
# set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fsanitize=address")
# note: might still need a
# export LD_PRELOAD=libclang_rt.asan.so
# or on Debian 9 with Clang 6.0
# export LD_PRELOAD=/usr/lib/llvm-6.0/lib/clang/6.0.0/lib/linux/libclang_rt.asan-x86_64.so:
# /usr/lib/llvm-6.0/lib/clang/6.0.0/lib/linux/libclang_rt.ubsan_minimal-x86_64.so
# at runtime when used with symbol-hidden code (e.g. pybind11 module)
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic -Wshadow -Woverloaded-virtual -Wextra-semi -Wunreachable-code -Wsign-compare ${CMAKE_CXX_FLAGS}")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic -Wshadow -Woverloaded-virtual -Wextra-semi -Wunreachable-code -Wsign-compare ${CMAKE_CXX_FLAGS}")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
set(CMAKE_CXX_FLAGS "-w3 -wd193,383,1572 ${CMAKE_CXX_FLAGS}")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic -Wshadow -Woverloaded-virtual -Wunreachable-code -Wsign-compare ${CMAKE_CXX_FLAGS}")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# Warning C4503: "decorated name length exceeded, name was truncated"
# Symbols longer than 4096 chars are truncated (and hashed instead)
set(CMAKE_CXX_FLAGS "-wd4503 ${CMAKE_CXX_FLAGS}")
# Warning C4244: "conversion from 'X' to 'Y', possible loss of data"
set(CMAKE_CXX_FLAGS "-wd4244 ${CMAKE_CXX_FLAGS}")
# Yes, you should build against the same C++ runtime and with same
# configuration (Debug/Release). MSVC does inconvenient choices for their