-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathCMakeLists.txt
2334 lines (1992 loc) · 83.9 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
######################################################################
# CMakeLists.txt - cmake build file for make to create CBFlib #
# #
# Version 0.9.6 06 November 2018 #
# #
# Paul Ellis and #
# Herbert J. Bernstein ([email protected]) #
# #
# (C) Copyright 2006 - 2018 Herbert J. Bernstein #
# #
######################################################################
######################################################################
# #
# YOU MAY REDISTRIBUTE THE CBFLIB PACKAGE UNDER THE TERMS OF THE GPL #
# #
# ALTERNATIVELY YOU MAY REDISTRIBUTE THE CBFLIB API UNDER THE TERMS #
# OF THE LGPL #
# #
######################################################################
########################### GPL NOTICES ##############################
# #
# This program is free software; you can redistribute it and/or #
# modify it under the terms of the GNU General Public License as #
# published by the Free Software Foundation; either version 2 of #
# (the License, or (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software #
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA #
# 02111-1307 USA #
# #
######################################################################
######################### LGPL NOTICES ###############################
# #
# This library is free software; you can redistribute it and/or #
# modify it under the terms of the GNU Lesser General Public #
# License as published by the Free Software Foundation; either #
# version 2.1 of the License, or (at your option) any later version. #
# #
# This library is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
# Lesser General Public License for more details. #
# #
# You should have received a copy of the GNU Lesser General Public #
# License along with this library; if not, write to the Free #
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, #
# MA 02110-1301 USA #
# #
######################################################################
######################################################################
# #
# Stanford University Notices #
# for the CBFlib software package that incorporates SLAC software #
# on which copyright is disclaimed #
# #
# This software #
# ------------- #
# The term "this software", as used in these Notices, refers to #
# those portions of the software package CBFlib that were created by #
# employees of the Stanford Linear Accelerator Center, Stanford #
# University. #
# #
# Stanford disclaimer of copyright #
# -------------------------------- #
# Stanford University, owner of the copyright, hereby disclaims its #
# copyright and all other rights in this software. Hence, anyone #
# may freely use it for any purpose without restriction. #
# #
# Acknowledgement of sponsorship #
# ------------------------------ #
# This software was produced by the Stanford Linear Accelerator #
# Center, Stanford University, under Contract DE-AC03-76SFO0515 with #
# the Department of Energy. #
# #
# Government disclaimer of liability #
# ---------------------------------- #
# Neither the United States nor the United States Department of #
# Energy, nor any of their employees, makes any warranty, express or #
# implied, or assumes any legal liability or responsibility for the #
# accuracy, completeness, or usefulness of any data, apparatus, #
# product, or process disclosed, or represents that its use would #
# not infringe privately owned rights. #
# #
# Stanford disclaimer of liability #
# -------------------------------- #
# Stanford University makes no representations or warranties, #
# express or implied, nor assumes any liability for the use of this #
# software. #
# #
# Maintenance of notices #
# ---------------------- #
# In the interest of clarity regarding the origin and status of this #
# software, this and all the preceding Stanford University notices #
# are to remain affixed to any copy or derivative of this software #
# made or distributed by the recipient and are to be affixed to any #
# copy of software made or distributed by the recipient that #
# contains a copy or derivative of this software. #
# #
# Based on SLAC Software Notices, Set 4 #
# OTT.002a, 2004 FEB 03 #
######################################################################
######################################################################
# NOTICE #
# Creative endeavors depend on the lively exchange of ideas. There #
# are laws and customs which establish rights and responsibilities #
# for authors and the users of what authors create. This notice #
# is not intended to prevent you from using the software and #
# documents in this package, but to ensure that there are no #
# misunderstandings about terms and conditions of such use. #
# #
# Please read the following notice carefully. If you do not #
# understand any portion of this notice, please seek appropriate #
# professional legal advice before making use of the software and #
# documents included in this software package. In addition to #
# whatever other steps you may be obliged to take to respect the #
# intellectual property rights of the various parties involved, if #
# you do make use of the software and documents in this package, #
# please give credit where credit is due by citing this package, #
# its authors and the URL or other source from which you obtained #
# it, or equivalent primary references in the literature with the #
# same authors. #
# #
# Some of the software and documents included within this software #
# package are the intellectual property of various parties, and #
# placement in this package does not in any way imply that any #
# such rights have in any way been waived or diminished. #
# #
# With respect to any software or documents for which a copyright #
# exists, ALL RIGHTS ARE RESERVED TO THE OWNERS OF SUCH COPYRIGHT. #
# #
# Even though the authors of the various documents and software #
# found here have made a good faith effort to ensure that the #
# documents are correct and that the software performs according #
# to its documentation, and we would greatly appreciate hearing of #
# any problems you may encounter, the programs and documents any #
# files created by the programs are provided **AS IS** without any *
# warranty as to correctness, merchantability or fitness for any #
# particular or general use. #
# #
# THE RESPONSIBILITY FOR ANY ADVERSE CONSEQUENCES FROM THE USE OF #
# PROGRAMS OR DOCUMENTS OR ANY FILE OR FILES CREATED BY USE OF THE #
# PROGRAMS OR DOCUMENTS LIES SOLELY WITH THE USERS OF THE PROGRAMS #
# OR DOCUMENTS OR FILE OR FILES AND NOT WITH AUTHORS OF THE #
# PROGRAMS OR DOCUMENTS. #
######################################################################
######################################################################
# #
# The IUCr Policy #
# for the Protection and the Promotion of the STAR File and #
# CIF Standards for Exchanging and Archiving Electronic Data #
# #
# Overview #
# #
# The Crystallographic Information File (CIF)[1] is a standard for #
# information interchange promulgated by the International Union of #
# Crystallography (IUCr). CIF (Hall, Allen & Brown, 1991) is the #
# recommended method for submitting publications to Acta #
# Crystallographica Section C and reports of crystal structure #
# determinations to other sections of Acta Crystallographica #
# and many other journals. The syntax of a CIF is a subset of the #
# more general STAR File[2] format. The CIF and STAR File approaches #
# are used increasingly in the structural sciences for data exchange #
# and archiving, and are having a significant influence on these #
# activities in other fields. #
# #
# Statement of intent #
# #
# The IUCr's interest in the STAR File is as a general data #
# interchange standard for science, and its interest in the CIF, #
# a conformant derivative of the STAR File, is as a concise data #
# exchange and archival standard for crystallography and structural #
# science. #
# #
# Protection of the standards #
# #
# To protect the STAR File and the CIF as standards for #
# interchanging and archiving electronic data, the IUCr, on behalf #
# of the scientific community, #
# #
# # holds the copyrights on the standards themselves, *
# #
# # owns the associated trademarks and service marks, and *
# #
# # holds a patent on the STAR File. *
# #
# These intellectual property rights relate solely to the #
# interchange formats, not to the data contained therein, nor to #
# the software used in the generation, access or manipulation of #
# the data. #
# #
# Promotion of the standards #
# #
# The sole requirement that the IUCr, in its protective role, #
# imposes on software purporting to process STAR File or CIF data #
# is that the following conditions be met prior to sale or #
# distribution. #
# #
# # Software claiming to read files written to either the STAR *
# File or the CIF standard must be able to extract the pertinent #
# data from a file conformant to the STAR File syntax, or the CIF #
# syntax, respectively. #
# #
# # Software claiming to write files in either the STAR File, or *
# the CIF, standard must produce files that are conformant to the #
# STAR File syntax, or the CIF syntax, respectively. #
# #
# # Software claiming to read definitions from a specific data *
# dictionary approved by the IUCr must be able to extract any #
# pertinent definition which is conformant to the dictionary #
# definition language (DDL)[3] associated with that dictionary. #
# #
# The IUCr, through its Committee on CIF Standards, will assist #
# any developer to verify that software meets these conformance #
# conditions. #
# #
# Glossary of terms #
# #
# [1] CIF: is a data file conformant to the file syntax defined #
# at http://www.iucr.org/iucr-top/cif/spec/index.html #
# #
# [2] STAR File: is a data file conformant to the file syntax #
# defined at http://www.iucr.org/iucr-top/cif/spec/star/index.html #
# #
# [3] DDL: is a language used in a data dictionary to define data #
# items in terms of "attributes". Dictionaries currently approved #
# by the IUCr, and the DDL versions used to construct these #
# dictionaries, are listed at #
# http://www.iucr.org/iucr-top/cif/spec/ddl/index.html #
# #
# Last modified: 30 September 2000 #
# #
# IUCr Policy Copyright (C) 2000 International Union of #
# Crystallography #
######################################################################
######################################################################
# CMakeLists.txt for CBFlib #
# #
# Assumed directory structure #
# CBFlib_SOURCE_DIR CBFlib kit containing this file #
# doc Directory with documentation #
# examples Directory with example programs #
# include Directory with header files #
# m4 Directory with m4 files #
# src Directory with source files #
# #
# CBFlib_BINARY_DIR CBFlib build directory #
# usually ${CBFlib_SOURCE_DIR}/build #
# external_packages Directory for HDF5, libtiff, etc. #
# hdf5-1.8.11 #
# tiff-3.9.4-rev-6Feb11 #
# regex-20090805 #
# zlib-1.2.8 #
# data_files Directory for test files #
# bin Directory for executable programs #
# include Directory with build-created headers #
# src Directory with build-created source #
# #
######################################################################
# find_program()'s REQUIRED option was introduced in CMake 3.18.
cmake_minimum_required(VERSION 3.18)
project(CBFlib
LANGUAGES C CXX
VERSION 0.9.8)
set(VERSION_INFO "3:0:1")
# Set timestamps of extracted contents to the time of extraction.
# Resolved by explicitly setting DOWNLOAD_EXTRACT_TIMESTAMP in
# externalproject_add() or fetchcontent_declare(), but the option was
# only introduced in CMake 3.24.
cmake_policy(SET CMP0135 NEW)
# Output directories for static and shared libraries as well as
# binaries. These appear to be required to on Windows and for running
# h5dump elsewhere.
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
option(CBF_ENABLE_FORTRAN "Enable Fortran 90" ON)
if(CBF_ENABLE_FORTRAN)
include(CheckLanguage)
check_language(Fortran)
if(CMAKE_Fortran_COMPILER)
enable_language(Fortran)
else()
message(FATAL_ERROR "Fortran 90 support requested, but no compiler found")
endif()
endif()
option(CBF_ENABLE_ULP "Enable ULP" OFF)
set (CBF_CMAKE_DEBUG "ON")
#
# User setable parameters
#
# make sure that the default is a RELEASE
if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE RELEASE CACHE STRING
"Choose the type of build, options are: None Debug Release."
FORCE)
endif (NOT CMAKE_BUILD_TYPE)
# Check for missing functions: regcomp(3) is in POSIX.1-2001,
# POSIX.1-2008.
include(CheckSymbolExists)
check_symbol_exists(regcomp "regex.h" HAVE_REGCOMP)
#
# Macros
#
#
# CBF_DEBUG_MESSAGE if CBF_CMAKE_DEBUG issue str
#
macro(CBF_DEBUG_MESSAGE str)
if(CBF_CMAKE_DEBUG)
message(STATUS ${str})
endif(CBF_CMAKE_DEBUG)
endmacro (CBF_DEBUG_MESSAGE)
#
# CBF_REQUIRE_DIRECTORY -- require directory dir
#
macro(CBF_REQUIRE_DIRECTORY dir)
if (NOT EXISTS "${dir}")
file(MAKE_DIRECTORY "${dir}")
CBF_DEBUG_MESSAGE("Created directory ${dir}")
endif (NOT EXISTS "${dir}")
endmacro(CBF_REQUIRE_DIRECTORY)
#
# Directories
#
#
# Directories on the kit side
#
set(CBF__SRC "${CBFlib_SOURCE_DIR}/src" )
set(CBF__INCLUDE "${CBFlib_SOURCE_DIR}/include" )
set(CBF__DOC "${CBFlib_SOURCE_DIR}/doc" )
set(CBF__EXAMPLES "${CBFlib_SOURCE_DIR}/examples" )
set(CBF__EXTERNAL_PACKAGES
"${CBFlib_SOURCE_DIR}/external_packages" )
set(CBF__DECTRIS_EXAMPLES
"${CBF__EXAMPLES}/dectris_cbf_template_test" )
#
# Directories on the build side
#
set(CBF__BIN "${CBFlib_BINARY_DIR}/bin" )
set(CBF__LIB "${CBFlib_BINARY_DIR}/lib" )
set(CBF__BIN_INCLUDE "${CBFlib_BINARY_DIR}/include" )
set(CBF__SHARE "${CBFlib_BINARY_DIR}/share" )
set(CBF__EXT_PKG "${CBFlib_BINARY_DIR}/external_packages" )
set(CBF__DATA "${CBFlib_BINARY_DIR}/data_files" )
CBF_REQUIRE_DIRECTORY(${CBF__BIN})
CBF_REQUIRE_DIRECTORY(${CBF__LIB})
CBF_REQUIRE_DIRECTORY(${CBF__BIN_INCLUDE})
CBF_REQUIRE_DIRECTORY(${CBF__SHARE})
CBF_REQUIRE_DIRECTORY(${CBF__EXT_PKG})
CBF_REQUIRE_DIRECTORY(${CBF__DATA})
# Under the (Linux) libtool convention, the single-component SOVERSION
# is the difference between the current and age components of
# VERSION_INFO.
string(REPLACE ":" ";" _cra "${VERSION_INFO}")
list(GET _cra 0 _current)
list(GET _cra 2 _age)
math(EXPR SOVERSION "${_current} - ${_age}")
set(JCBF "${CBFlib_SOURCE_DIR}/jcbf" CACHE STRING "")
set(JAVADIR "${CBFlib_SOURCE_DIR}/java" CACHE STRING "")
set(BIN "${CBFlib_BINARY_DIR}/bin" CACHE STRING "")
set(PYCBF "${CBFlib_SOURCE_DIR}/pycbf" CACHE STRING "")
set(EXAMPLES "${CBFlib_SOURCE_DIR}/examples" CACHE STRING "" )
set(DECTRIS_EXAMPLES "${EXAMPLES}/dectris_cbf_template_test" CACHE STRING "")
set(GRAPHICS "${CBFlib_SOURCE_DIR}/html_graphics" CACHE STRING "")
if(CBF_DONT_USE_LONG_LONG)
set(CBF_NOLLFLAG "-DCBF_DONT_USE_LONG_LONG")
else(CBF_DONT_USE_LONG_LONG)
set(CBF_NOLLFLAG "")
endif(CBF_DONT_USE_LONG_LONG)
#
# Dependencies, external packages
#
# Verify the checksums. The --binary option appears to be required
# for patching the test data on MSYS2.
include(FetchContent)
find_program(PATCH patch REQUIRED)
fetchcontent_declare(cqrlib
URL "https://github.com/yayahjb/cqrlib/archive/refs/tags/CQRlib-1.1.4.tar.gz"
URL_HASH MD5=629a349ed5e8bf6f2a69a2fb1da11c45
PATCH_COMMAND "${PATCH}"
-N -i "${CMAKE_CURRENT_SOURCE_DIR}/patches/cqrlib-1.1.4.patch" -p 1 -t)
fetchcontent_declare(data_input
URL "http://downloads.sf.net/cbflib/CBFlib_${PROJECT_VERSION}_Data_Files_Input.tar.gz"
URL_HASH MD5=f98ae4214b3e57acb42437ea4b685c4d
PATCH_COMMAND "${PATCH}"
-N -i "${CMAKE_CURRENT_SOURCE_DIR}/patches/cbflib-data-input-${PROJECT_VERSION}.patch" -p 1 -t --binary)
fetchcontent_declare(data_output
URL "http://downloads.sf.net/cbflib/CBFlib_${PROJECT_VERSION}_Data_Files_Output.tar.gz"
URL_HASH MD5=716346077fe2bcbe29e5153f0ecbb8e7
PATCH_COMMAND "${PATCH}"
-N -i "${CMAKE_CURRENT_SOURCE_DIR}/patches/cbflib-data-output-${PROJECT_VERSION}.patch" -p 1 -t --binary)
fetchcontent_declare(hdf5
URL "http://downloads.sf.net/cbflib/hdf5-1.14.4-2.tar.gz"
URL_HASH MD5=1791c5f70660bf4ec2e05fc15526c181)
fetchcontent_declare(pcreposix
URL "http://downloads.sf.net/cbflib/pcre-8.38.tar.gz"
URL_HASH MD5=8a353fe1450216b6655dfcf3561716d9)
fetchcontent_declare(tiff
URL "http://downloads.sf.net/cbflib/tiff-4.0.6_rev_3Nov16.tar.gz"
URL_HASH MD5=594d1811ce715f7d5ec586bf5e0c4732)
#
# libm
set(libm "$<$<NOT:$<C_COMPILER_ID:MSVC>>:m>")
#
# CQRlib
set(CBF_WITH_CQRLIB ON CACHE BOOL
"Link against internally built CQRlib library")
mark_as_advanced(CBF_WITH_CQRLIB)
if(CBF_WITH_CQRLIB)
fetchcontent_makeavailable(cqrlib)
else()
find_library(cqrlib_library CQRlib)
find_path(cqrlib_include_dir cqrlib.h)
add_library(CQR UNKNOWN IMPORTED)
set_target_properties(CQR PROPERTIES
IMPORTED_LOCATION "${cqrlib_library}"
INTERFACE_INCLUDE_DIRECTORIES "${cqrlib_include_dir}"
INTERFACE_LINK_LIBRARIES "${libm}")
endif()
#
# INPUT/OUTPUT TEST DATA
#
# If CBF_WITH_DATA_INPUT and/or CBF_WITH_DATA_OUTPUT are set
# externally, the test data in the corresponding directories are
# assumed to be patched.
set(CBF_WITH_DATA_INPUT "" CACHE FILEPATH
"Path to input test data directory")
mark_as_advanced(CBF_WITH_DATA_INPUT)
if(CBF_WITH_DATA_INPUT)
set(data_input "${CBF_WITH_DATA_INPUT}")
else()
fetchcontent_makeavailable(data_input)
set(data_input "${data_input_SOURCE_DIR}")
endif()
set(CBF_WITH_DATA_OUTPUT "" CACHE FILEPATH
"Path to reference output test data directory")
mark_as_advanced(CBF_WITH_DATA_OUTPUT)
if(CBF_WITH_DATA_OUTPUT)
set(data_output "${CBF_WITH_DATA_OUTPUT}")
else()
fetchcontent_makeavailable(data_output)
set(data_output "${data_output_SOURCE_DIR}")
endif()
#
# HDF5
#
# See hdf5's root CMakeLists.txt and config/cmake/HDFLibMacros.cmake.
# Set _h5dump_executable to the path to h5dump and _hdf5_target to the
# real (unaliased) HDF5 target.
set(CBF_WITH_HDF5 ON CACHE BOOL
"Link against internally built HDF5 library")
mark_as_advanced(CBF_WITH_HDF5)
set(HDF5REGISTER "--register" "manual" CACHE INTERNAL
"Flags to register HDF5 plugins")
mark_as_advanced(HDF5REGISTER)
if(CBF_WITH_HDF5)
set(BUILD_TESTING OFF CACHE INTERNAL
"Build HDF5 unit testing")
set(HDF5_EXTERNALLY_CONFIGURED ON CACHE INTERNAL
"HDF5 configured externally")
fetchcontent_makeavailable(hdf5)
set(_h5dump_executable
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/h5dump${CMAKE_EXECUTABLE_SUFFIX}")
if(BUILD_SHARED_LIBS)
set(_hdf5_target hdf5-shared)
else()
set(_hdf5_target hdf5-static)
endif()
else()
if(NOT BUILD_SHARED_LIBS)
# HDF5_USE_STATIC_LIBRARIES does not seem to do what it is
# supposed to, see
# https://gitlab.kitware.com/cmake/cmake/-/issues/24613.
set(HDF5_USE_STATIC_LIBRARIES TRUE)
endif()
find_package(HDF5 REQUIRED)
find_program(_h5dump_executable h5dump REQUIRED)
set(_hdf5_target hdf5::hdf5)
endif()
# The h5dump target already exists with CMake 3.30 and HDF 1.14.4 on
# Windows.
if(NOT TARGET h5dump)
add_executable(h5dump IMPORTED)
set_target_properties(h5dump PROPERTIES
IMPORTED_LOCATION "${_h5dump_executable}")
endif()
# CBFlib must be compiled with H5_USE_110_API. With MSVC, also need
# H5_BUILT_AS_DYNAMIC_LIB if HDF5 is a dynamic library.
add_library(hdf5 ALIAS ${_hdf5_target})
target_compile_definitions(${_hdf5_target}
INTERFACE H5_USE_110_API)
if(BUILD_SHARED_LIBS)
target_compile_definitions(${_hdf5_target}
INTERFACE H5_BUILT_AS_DYNAMIC_LIB)
endif()
#
# PCRE
#
# Linking against an external PCRE1 library (no longer maintained)
# with a libc that has the regex functions will define regcomp(3),
# regerror(3), regexec(3), and regfree(3) twice: do not set
# CBF_WITH_PCRE if libc has the regexec functions. PCRE2 does it
# differently: it defines the regex functions prefixed with pcre2_ and
# maps them onto the unprefixed names with preprocessor directives.
set(CBF_WITH_PCRE OFF CACHE BOOL
"Link against internally built Perl-compatible regular expressions library")
mark_as_advanced(CBF_WITH_PCRE)
if(CBF_WITH_PCRE)
# Do not try to link pcretest against readline, because the PCRE
# build system does not catch the libtinfo dependency (for tputs and
# friends). Note that PCRE-8.38 is not using GNUInstallDirs; later
# versions may.
#
# PCRE 8.38 reads the DEBUG_LOCATION property of the pcregrep and
# pcretest targets--disable both targets.
set(PCRE_BUILD_PCREGREP OFF CACHE INTERNAL "Bulid pcregrep")
set(PCRE_BUILD_TESTS OFF CACHE INTERNAL "Build the tests")
fetchcontent_makeavailable(pcreposix)
# Always use the pcreposix.h from ${pcreposix_SOURCE_DIR} rather
# than a system-supplied header.
target_include_directories(pcreposix BEFORE PUBLIC "${pcreposix_SOURCE_DIR}")
elseif(HAVE_REGCOMP)
add_library(pcreposix INTERFACE IMPORTED)
target_compile_definitions(pcreposix
INTERFACE CBF_REGEXLIB_REGEX)
else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(pcreposix REQUIRED IMPORTED_TARGET libpcreposix)
add_library(pcreposix ALIAS PkgConfig::pcreposix)
endif()
#
# TIFF
#
# LibTIFF to support tiff2cbf. Disable tests if building in-tree; the
# tiff-tests cache variable was introduced in LibTIFF 4.5.0.
set(CBF_WITH_LIBTIFF ON CACHE BOOL
"Link against internally built LibTIFF library")
mark_as_advanced(CBF_WITH_LIBTIFF)
if(CBF_WITH_LIBTIFF)
# The first LibTIFF at https://gitlab.com/libtiff/libtiff with
# native CMake support seems to be 4.0.5. The first version that
# builds on current MSYS2 is 4.0.9.
#
# 4.0.3-rev-29Sep13 appears to have CMakeLists.txt patched in but
# fails on MSYS2: multiple definition of ua_wcsicmp.
set(tiff-contrib OFF CACHE INTERNAL "Build TIFF contrib")
set(tiff-docs OFF CACHE INTERNAL "Build TIFF documentation")
set(tiff-tests OFF CACHE INTERNAL "Build TIFF tests")
set(tiff-tools OFF CACHE INTERNAL "Build TIFF tools")
fetchcontent_makeavailable(tiff)
else()
# find_package(TIFF) appears to miss the dependencies (Lerc, jbig,
# etc) for a static LibTIFF. pkg_check_modules(... IMPORTED_TARGET
# libtiff-4) on the other hand always seems to create a
# shared-library target; see
# https://gitlab.kitware.com/cmake/cmake/-/issues/21714.
#
# Use pkg-config, with the intent of eventually switching to
# cmake_pkg_config(), because e.g. Debian does not ship CMake config
# files in their dev packages.
find_package(PkgConfig REQUIRED)
pkg_check_modules(tiff REQUIRED IMPORTED_TARGET libtiff-4)
add_library(tiff ALIAS PkgConfig::tiff)
endif()
#
# Source files
#
set(
CBF_C_SOURCES
${CBF__SRC}/cbf.c
"${CBF__SRC}/cbf_airy_disk.c"
${CBF__SRC}/cbf_alloc.c
${CBF__SRC}/cbf_ascii.c
${CBF__SRC}/cbf_binary.c
${CBF__SRC}/cbf_byte_offset.c
${CBF__SRC}/cbf_canonical.c
${CBF__SRC}/cbf_codes.c
${CBF__SRC}/cbf_compress.c
${CBF__SRC}/cbf_context.c
${CBF__SRC}/cbf_copy.c
${CBF__SRC}/cbf_file.c
${CBF__SRC}/cbf_getopt.c
${CBF__SRC}/cbf_hdf5.c
${CBF__SRC}/cbf_hdf5_filter.c
${CBF__SRC}/cbf_lex.c
${CBF__SRC}/cbf_minicbf_header.c
${CBF__SRC}/cbf_nibble_offset.c
${CBF__SRC}/cbf_packed.c
${CBF__SRC}/cbf_predictor.c
${CBF__SRC}/cbf_read_binary.c
${CBF__SRC}/cbf_read_mime.c
${CBF__SRC}/cbf_simple.c
${CBF__SRC}/cbf_string.c
${CBF__SRC}/cbf_stx.c
${CBF__SRC}/cbf_tree.c
${CBF__SRC}/cbf_uncompressed.c
${CBF__SRC}/cbf_write.c
${CBF__SRC}/cbf_write_binary.c
${CBF__SRC}/cbf_ws.c
${CBF__SRC}/md5c.c
${CBF__SRC}/img.c
)
# use, i.e. don't skip the full RPATH for the build tree
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# the RPATH to be used when installing, but only if it's not a system directory
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
IF("${isSystemDir}" STREQUAL "-1")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib" )
ENDIF("${isSystemDir}" STREQUAL "-1")
#
# Header files
#
set(
CBF_HEADERS
${CBF__INCLUDE}/cbf.h
${CBF__INCLUDE}/cbf_alloc.h
${CBF__INCLUDE}/cbf_ascii.h
${CBF__INCLUDE}/cbf_binary.h
${CBF__INCLUDE}/cbf_byte_offset.h
${CBF__INCLUDE}/cbf_canonical.h
${CBF__INCLUDE}/cbf_codes.h
${CBF__INCLUDE}/cbf_compress.h
${CBF__INCLUDE}/cbf_context.h
${CBF__INCLUDE}/cbf_copy.h
${CBF__INCLUDE}/cbf_file.h
${CBF__INCLUDE}/cbf_getopt.h
${CBF__INCLUDE}/cbf_hdf5.h
${CBF__INCLUDE}/cbf_hdf5_filter.h
${CBF__INCLUDE}/cbf_lex.h
${CBF__INCLUDE}/cbf_minicbf_header.h
${CBF__INCLUDE}/cbf_nibble_offset.h
${CBF__INCLUDE}/cbf_packed.h
${CBF__INCLUDE}/cbf_predictor.h
${CBF__INCLUDE}/cbf_read_binary.h
${CBF__INCLUDE}/cbf_read_mime.h
${CBF__INCLUDE}/cbf_simple.h
${CBF__INCLUDE}/cbf_string.h
${CBF__INCLUDE}/cbf_stx.h
${CBF__INCLUDE}/cbf_tree.h
${CBF__INCLUDE}/cbf_uncompressed.h
${CBF__INCLUDE}/cbf_write.h
${CBF__INCLUDE}/cbf_write_binary.h
${CBF__INCLUDE}/cbf_ws.h
${CBF__INCLUDE}/global.h
${CBF__INCLUDE}/cbff.h
${CBF__INCLUDE}/md5.h
${CBF__INCLUDE}/img.h
)
if(CBF_ENABLE_ULP)
list(APPEND CBF_HEADERS
"${CBF__INCLUDE}/cbf_ulp.h")
endif()
#
# Documentation files
#
set(
CBF_DOCUMENTS
${CBF__DOC}/CBFlib.html
${CBF__DOC}/CBFlib.txt
${CBF__DOC}/CBFlib_NOTICES.html
${CBF__DOC}/CBFlib_NOTICES.txt
${CBF__DOC}/ChangeLog
${CBF__DOC}/ChangeLog.html
${CBF__DOC}/MANIFEST
${CBF__DOC}/gpl.txt $(DOC)/lgpl.txt
CACHE STRING ""
)
#
# HTML Graphics files
#
set(
JPEGS
${GRAPHICS}/CBFbackground.jpg
${GRAPHICS}/CBFbig.jpg
${GRAPHICS}/CBFbutton.jpg
${GRAPHICS}/cbflibbackground.jpg
${GRAPHICS}/cbflibbig.jpg
${GRAPHICS}/cbflibbutton.jpg
${GRAPHICS}/cifhome.jpg
${GRAPHICS}/iucrhome.jpg
${GRAPHICS}/noticeButton.jpg
CACHE STRING ""
)
# Set up the necessary includes
include_directories(BEFORE SYSTEM
${CBFlib_SOURCE_DIR}/include)
#
# Build the static and shared CBF libraries
#
# Note that HDF5 is a PUBLIC dependency of CBFlib, because cbf_hdf5.h
# includes hdf5.h.
add_library(cbf ${CBF_C_SOURCES})
if(CBF_ENABLE_ULP)
target_compile_definitions(cbf PUBLIC CBF_USE_ULP)
target_sources(cbf PRIVATE "${CBF__SRC}/cbf_ulp.c")
endif()
set_target_properties(cbf PROPERTIES OUTPUT_NAME "cbf")
set_target_properties(cbf PROPERTIES LINKER_LANGUAGE C)
set_target_properties(cbf PROPERTIES SOVERSION "${SOVERSION}")
target_link_libraries(cbf
PUBLIC hdf5
PRIVATE pcreposix
PRIVATE ${libm})
#
# Build the static and shared IMG libraries
#
add_library(img "${CBF__SRC}/img.c")
set_target_properties(img PROPERTIES OUTPUT_NAME "img")
set_target_properties(img PROPERTIES LINKER_LANGUAGE C)
#
# Build all Fortran sources and libraries. The f90cbf library is not
# installed.
if(CBF_ENABLE_FORTRAN)
find_program(M4 m4 REQUIRED)
set(M4FLAGS "-Dfcb_bytes_in_rec=4096" CACHE STRING
"Flags used by the M4 macro processor during Fortran build")
mark_as_advanced(M4FLAGS)
set(f90_sources_m4
"${CMAKE_CURRENT_SOURCE_DIR}/m4/fcb_exit_binary.m4"
"${CMAKE_CURRENT_SOURCE_DIR}/m4/fcb_next_binary.m4"
"${CMAKE_CURRENT_SOURCE_DIR}/m4/fcb_open_cifin.m4"
"${CMAKE_CURRENT_SOURCE_DIR}/m4/fcb_packed.m4"
"${CMAKE_CURRENT_SOURCE_DIR}/m4/fcb_read_bits.m4"
"${CMAKE_CURRENT_SOURCE_DIR}/m4/fcb_read_image.m4"
"${CMAKE_CURRENT_SOURCE_DIR}/m4/fcb_read_xds_i2.m4"
"${CMAKE_CURRENT_SOURCE_DIR}/m4/test_fcb_read_image.m4"
"${CMAKE_CURRENT_SOURCE_DIR}/m4/test_xds_binary.m4")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/src")
foreach(f90srcm4 IN LISTS f90_sources_m4)
get_filename_component(filename "${f90srcm4}" NAME_WE)
set(f90bldsrc "${CMAKE_CURRENT_BINARY_DIR}/src/${filename}.f90")
add_custom_command(
OUTPUT "${f90bldsrc}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/m4"
COMMAND ${M4} -P ${M4FLAGS} "${f90srcm4}" > "${f90bldsrc}"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/m4/fcblib_defines.m4"
"${f90srcm4}"
COMMENT "Generating ${f90bldsrc}")
endforeach()
add_library(fcb
"${CMAKE_CURRENT_BINARY_DIR}/src/fcb_exit_binary.f90"
"${CMAKE_CURRENT_BINARY_DIR}/src/fcb_next_binary.f90"
"${CMAKE_CURRENT_BINARY_DIR}/src/fcb_open_cifin.f90"
"${CMAKE_CURRENT_BINARY_DIR}/src/fcb_packed.f90"
"${CMAKE_CURRENT_BINARY_DIR}/src/fcb_read_bits.f90"
"${CMAKE_CURRENT_BINARY_DIR}/src/fcb_read_image.f90"
"${CMAKE_CURRENT_BINARY_DIR}/src/fcb_read_xds_i2.f90"
"${CBF__SRC}/fcb_atol_wcnt.f90"
"${CBF__SRC}/fcb_ci_strncmparr.f90"
"${CBF__SRC}/fcb_nblen_array.f90"
"${CBF__SRC}/fcb_read_byte.f90"
"${CBF__SRC}/fcb_read_line.f90"
"${CBF__SRC}/fcb_skip_whitespace.f90")
set_target_properties(fcb PROPERTIES OUTPUT_NAME "fcb")
set_target_properties(fcb PROPERTIES LINKER_LANGUAGE C)
install(TARGETS fcb DESTINATION lib)
# Use the pre-generated SWIG wrapper, because current SWIG does not
# support Fortran.
add_library(f90cbf
"${CMAKE_CURRENT_SOURCE_DIR}/f90cbf/f90cbf.f90"
"${CMAKE_CURRENT_SOURCE_DIR}/f90cbf/f90cbf_wrap.c")
target_link_libraries(f90cbf
cbf)
endif()
#
# C and C++ examples
#
add_executable(tiff2cbf
"${CBF__EXAMPLES}/tif_sprint.c"
"${CBF__EXAMPLES}/tiff2cbf.c")
target_link_libraries(tiff2cbf
cbf
tiff)
add_executable(cbf2nexus
"${CBF__EXAMPLES}/cbf2nexus.c")
target_link_libraries(cbf2nexus
cbf)
add_executable(nexus2cbf
"${CBF__EXAMPLES}/nexus2cbf.c")
target_link_libraries(nexus2cbf
cbf
hdf5)
add_executable(minicbf2nexus
"${CBF__EXAMPLES}/minicbf2nexus.c")
target_link_libraries(minicbf2nexus
cbf)
add_executable(adscimg2cbf
"${CBF__EXAMPLES}/adscimg2cbf.c"
"${CBF__EXAMPLES}/adscimg2cbf_sub.c")
target_link_libraries(adscimg2cbf
cbf
"${libm}")
add_executable(cbf2adscimg
"${CBF__EXAMPLES}/cbf2adscimg.c"
"${CBF__EXAMPLES}/cbf2adscimg_sub.c")
target_link_libraries(cbf2adscimg
cbf
"${libm}")
add_executable(convert_f90_swig_wrap
"${CBF__EXAMPLES}/convert_f90_swig_wrap.cpp")
add_executable(convert_image
"${CBF__EXAMPLES}/convert_image.c")
target_link_libraries(convert_image
cbf)
add_executable(convert_minicbf
"${CBF__EXAMPLES}/convert_minicbf.c")
target_link_libraries(convert_minicbf
cbf)
add_executable(makecbf
"${CBF__EXAMPLES}/makecbf.c")
target_link_libraries(makecbf
cbf)
add_executable(cbf_tail
"${CBF__EXAMPLES}/cbf_tail.c")
target_link_libraries(cbf_tail
cbf)
add_executable(cbf_testxfelread
"${CBF__EXAMPLES}/cbf_testxfelread.c")
target_link_libraries(cbf_testxfelread
cbf
"${libm}")
add_executable(changtestcompression
"${CBF__EXAMPLES}/changtestcompression.c")
target_link_libraries(changtestcompression
cbf)
add_executable(img2cif
"${CBF__EXAMPLES}/img2cif.c")
target_link_libraries(img2cif
cbf)
add_executable(cif2cbf
"${CBF__EXAMPLES}/cif2cbf.c")
target_link_libraries(cif2cbf
cbf
CQR
"${libm}")
add_executable(cbf_template_t
"${CBF__DECTRIS_EXAMPLES}/cbf_template_t.c")
target_link_libraries(cbf_template_t
cbf)
add_executable(testcell
"${CBF__EXAMPLES}/testcell.C")
target_link_libraries(testcell
cbf)
add_executable(sauter_test
"${CBF__EXAMPLES}/sauter_test.C")
target_link_libraries(sauter_test
cbf)
add_executable(sequence_match
"${CBF__EXAMPLES}/sequence_match.c")
target_link_libraries(sequence_match
cbf)
add_executable(test_cbf_airy_disk
"${CBF__EXAMPLES}/test_cbf_airy_disk.c")
target_link_libraries(test_cbf_airy_disk
cbf
"${libm}")
if(CBF_ENABLE_ULP)
add_executable(testulp
"${CBF__EXAMPLES}/testulp.c")
target_link_libraries(testulp
cbf)