-
Notifications
You must be signed in to change notification settings - Fork 149
/
CMakeLists.txt
2603 lines (2305 loc) · 108 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
# C M A K E L I S T S . T X T
# BRL-CAD
#
# Copyright (c) 2010-2024 United States Government as represented by
# the U.S. Army Research Laboratory.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
#
# 3. The name of the author may not be used to endorse or promote
# products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# NOTE: BRL-CAD as a collective work is distributed under the LGPL.
# BRL-CAD's build system is under the BSD license.
# See the COPYING file for more details.
#
# *******************************************************************
# *** BRL-CAD's CMakeLists.txt ***
# *******************************************************************
#
# This file defines the toplevel build logic for BRL-CAD. As
# reasonably possible, proper ordering and separation of tests should
# be added to the labeled sections below as follows:
#
# Stage 0 - project information
# Stage 1 - define top level options
# Stage 2 - check programs
# Stage 3 - check compiler characteristics
# Stage 4 - check libraries
# Stage 5 - check headers
# Stage 6 - check types/structures
# Stage 7 - check functions
# Stage 8 - check system services
# Stage 9 - define the BRL-CAD build targets
#
# There is an output summary printed at the end to report key info
# about the final build configuration. Details are available in the
# CMakeCache.txt file in the build directory.
#
# ***********************************************************
# * Stage 0 of 9 - Project Info *
# ***********************************************************
cmake_minimum_required(VERSION 3.18)
#---------------------------------------------------------------------
# BRL-CAD's version is centrally stored in include/conf/. See HACKING
# for details on updating the version.
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/include/conf/MAJOR" BRLCAD_VERSION_MAJOR)
string(STRIP ${BRLCAD_VERSION_MAJOR} BRLCAD_VERSION_MAJOR)
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/include/conf/MINOR" BRLCAD_VERSION_MINOR)
string(STRIP ${BRLCAD_VERSION_MINOR} BRLCAD_VERSION_MINOR)
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/include/conf/PATCH" BRLCAD_VERSION_PATCH)
string(STRIP ${BRLCAD_VERSION_PATCH} BRLCAD_VERSION_PATCH)
set(BRLCAD_VERSION "${BRLCAD_VERSION_MAJOR}.${BRLCAD_VERSION_MINOR}.${BRLCAD_VERSION_PATCH}")
if(DEFINED BRLCAD_VERSION_AMEND)
set(BRLCAD_VERSION "${BRLCAD_VERSION}-${BRLCAD_VERSION_AMEND}")
endif(DEFINED BRLCAD_VERSION_AMEND)
#######
project(
BRLCAD
VERSION ${BRLCAD_VERSION}
DESCRIPTION "Open Source Solid Modeling"
HOMEPAGE_URL "https://brlcad.org"
LANGUAGES C CXX
)
#######
# Policy CMP0009: FILE GLOB_RECURSE calls should not follow symlinks by default
if(POLICY CMP0009)
cmake_policy(SET CMP0009 NEW)
endif(POLICY CMP0009)
# Policy CMP0060 tells CMake to use full paths in link specifications
if(POLICY CMP0060)
cmake_policy(SET CMP0060 NEW)
endif(POLICY CMP0060)
# Policy CMP0074 allows CMake to search
# "prefixes specified by the <PackageName>_ROOT in find_package"
# https://cmake.org/cmake/help/git-stage/policy/CMP0074.html
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif(POLICY CMP0074)
# cmake_dependent_option() supports full Condition Syntax
if(POLICY CMP0127)
cmake_policy(SET CMP0127 NEW)
endif(POLICY CMP0127)
message("CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}")
message("CMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR}")
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/COPYING")
message(FATAL_ERROR "Invalid brlcad directory: ${CMAKE_SOURCE_DIR}")
endif(NOT EXISTS "${CMAKE_SOURCE_DIR}/COPYING")
if(CMAKE_ORIGINAL_SRC_DIR)
if(NOT "${CMAKE_ORIGINAL_SRC_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
message(FATAL_ERROR "Got ${CMAKE_ORIGINAL_SOURCE_DIR}/CMakeLists.txt from ${CMAKE_SOURCE_DIR}")
endif(NOT "${CMAKE_ORIGINAL_SRC_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
endif(CMAKE_ORIGINAL_SRC_DIR)
set(CMAKE_ORIGINAL_SRC_DIR "${CMAKE_SOURCE_DIR}" CACHE PATH "Source of original CMakeLists.txt file" FORCE)
#---------------------------------------------------------------------
# CMake derives much of its functionality from modules, typically
# stored in one directory - let CMake know where to find them. If we
# are a subbuild, let the parent's CMAKE_MODULE_PATH supply files before
# our own, otherwise misc/CMake takes first priority.
set(BRLCAD_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(BRLCAD_CMAKE_DIR "${BRLCAD_SOURCE_DIR}/misc/CMake")
list(APPEND CMAKE_MODULE_PATH "${BRLCAD_CMAKE_DIR}")
#---------------------------------------------------------------------
# GitHub is using .gitattributes to specify language types on files,
# so we need it if we want to correct language identifications. On the
# other hand, we DON'T want someone to use it to mark file patterns as
# text or binary - that is much too easy to get wrong, and the
# consequences can sometimes be very subtly incorrect/hard to debug.
#
# Introspect the .gitattributes file looking for problematic keywords
if(EXISTS "${BRLCAD_SOURCE_DIR}/.gitattributes")
file(STRINGS "${BRLCAD_SOURCE_DIR}/.gitattributes" ALINES)
set(dangerous_keywords "text;crlf;diff;eol")
foreach(aline ${ALINES})
if (NOT "${aline}" MATCHES "^#.*")
foreach(kwrd ${dangerous_keywords})
if ("${aline}" MATCHES ".*${kwrd}.*")
message(
FATAL_ERROR
"\nBRL-CAD does not use its .gitattributes file for identifying whether files are text or binary. This limitation prevents subtle errors from creeping in due to inadvertent pattern matches. See ${BRLCAD_SOURCE_DIR}/doc/git/mime_types.txt for an in-depth discussion of how to address cases where specific line endings are needed in text files.\n"
)
endif()
endforeach()
endif()
endforeach()
endif(EXISTS "${BRLCAD_SOURCE_DIR}/.gitattributes")
#---------------------------------------------------------------------
# Let CMake know where to look for our counting file for configuration
# passes. It will impact whether we print certain messages
set(BRLCAD_CNT_FILE "${BRLCAD_BINARY_DIR}/CMakeTmp/BRLCAD_BUILD_COUNT")
if(NOT EXISTS ${BRLCAD_CNT_FILE})
set(BRLCAD_PRINT_MSGS 1)
else(NOT EXISTS ${BRLCAD_CNT_FILE})
set(BRLCAD_PRINT_MSGS 0)
endif(NOT EXISTS ${BRLCAD_CNT_FILE})
# Now that we know whether or not we're supposed to, print the CMake version
if(BRLCAD_PRINT_MSGS)
message(STATUS "CMake version: ${CMAKE_VERSION}")
endif(BRLCAD_PRINT_MSGS)
#---------------------------------------------------------------------
# Management of build types
include(BRLCAD_Build_Types)
#---------------------------------------------------------------------
# Setup and checks related to system environment settings. Some of
# these impact search results needed to set default options, so we
# do this early in the process.
include(BRLCAD_Environment_Setup)
# We do NOT want CMake looking in the User Package Registry - have encountered
# at least one case where stale or incorrect information there has resulted in
# an incorrect include directory for Eigen based on bext build info.
set(CMAKE_FIND_USE_PACKAGE_REGISTRY FALSE)
# Populate these early, even though their main use is in
# misc/CMake/BRLCAD_ExternalDeps.cmake - find_program and find_package calls
# may also make use of them, particularly BRLCAD_EXT_NOINSTALL_DIR
set(BRLCAD_EXT_DIR_ENV "$ENV{BRLCAD_EXT_DIR}")
if(BRLCAD_EXT_DIR_ENV AND NOT DEFINED BRLCAD_EXT_DIR)
set(BRLCAD_EXT_DIR ${BRLCAD_EXT_DIR_ENV})
endif(BRLCAD_EXT_DIR_ENV AND NOT DEFINED BRLCAD_EXT_DIR)
if(DEFINED BRLCAD_EXT_DIR)
# Make sure we cache the BRLCAD_EXT_DIR setting - if we don't, then a re-configure
# with CMake is going to ignore a previously specified directory
set(BRLCAD_EXT_DIR "${BRLCAD_EXT_DIR}" CACHE PATH "BRL-CAD external dependency sources")
if(NOT DEFINED BRLCAD_EXT_INSTALL_DIR AND EXISTS "${BRLCAD_EXT_DIR}/install")
set(BRLCAD_EXT_INSTALL_DIR "${BRLCAD_EXT_DIR}/install")
endif(NOT DEFINED BRLCAD_EXT_INSTALL_DIR AND EXISTS "${BRLCAD_EXT_DIR}/install")
# Need to handle the case where BRLCAD_EXT_DIR is a symlink - if it
# is, we need to expand the symlink in order for the tar tricks we use
# later for file copying to work...
if(DEFINED BRLCAD_EXT_INSTALL_DIR AND IS_SYMLINK ${BRLCAD_EXT_INSTALL_DIR})
file(REAL_PATH "${BRLCAD_EXT_INSTALL_DIR}" EXT_PATH)
set(BRLCAD_EXT_INSTALL_DIR "${EXT_PATH}")
endif(DEFINED BRLCAD_EXT_INSTALL_DIR AND IS_SYMLINK ${BRLCAD_EXT_INSTALL_DIR})
# For noinstall we don't need to worry about symlinks since we'll be using
# the contents in place.
if(NOT DEFINED BRLCAD_EXT_NOINSTALL_DIR AND EXISTS "${BRLCAD_EXT_DIR}/noinstall")
set(BRLCAD_EXT_NOINSTALL_DIR "${BRLCAD_EXT_DIR}/noinstall")
endif(NOT DEFINED BRLCAD_EXT_NOINSTALL_DIR AND EXISTS "${BRLCAD_EXT_DIR}/noinstall")
endif(DEFINED BRLCAD_EXT_DIR)
# If we're doing the non-src-other build, we've got to have bext for at least a
# few custom components no matter how many system packages are installed.
if(NOT DEFINED BRLCAD_EXT_NOINSTALL_DIR OR NOT DEFINED BRLCAD_EXT_INSTALL_DIR)
message(
WARNING
"External dependencies will be downloaded, configured, and built automatically as-needed. Set BRLCAD_EXT_DIR to specify instead."
)
message(
STATUS
"BRLCAD_EXT_DIR specifies prebuilt external dependencies directory\n"
"containing 'install' and 'noinstall' folders, outputs from installing\n"
"https://github.com/BRL-CAD/bext.\n"
)
endif(NOT DEFINED BRLCAD_EXT_NOINSTALL_DIR OR NOT DEFINED BRLCAD_EXT_INSTALL_DIR)
# By default, we don't bundle bext into the source tarball for performance
# reasons, but the support is there if the dev wants to pay the price in time
# and disk space.
if(NOT DEFINED CPACK_INCLUDE_EXT)
set(CPACK_INCLUDE_EXT OFF)
endif(NOT DEFINED CPACK_INCLUDE_EXT)
# Before we do a lot of configure work, check whether we've got a type mismatch
# between bext and the BRL-CAD build type. If not, on Windows at least, it's a
# fatal error.
#
# NOTE: This test must come AFTER the inclusion of BRLCAD_Build_Types
if(CMAKE_BUILD_TYPE AND EXISTS "${BRLCAD_EXT_NOINSTALL_DIR}")
find_program(DUMPBIN_EXEC dumpbin)
set(TEST_BINFILE ${BRLCAD_EXT_NOINSTALL_DIR}/bin/strclear.exe)
if(DUMPBIN_EXEC AND EXISTS ${TEST_BINFILE})
# dumpbin doesn't like CMake style paths
file(TO_NATIVE_PATH "${TEST_BINFILE}" TBFN)
# https://stackoverflow.com/a/28304716/2037687
execute_process(COMMAND ${DUMPBIN_EXEC} /dependents ${TBFN} OUTPUT_VARIABLE DB_OUT ERROR_VARIABLE DB_OUT)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
if("${DB_OUT}" MATCHES ".*MSVCP[0-9]*d.dll.*" OR "${DB_OUT}" MATCHES ".*MSVCP[0-9]*D.dll.*")
message(
FATAL_ERROR
"Release build specified, but supplied bext binaries in ${BRLCAD_EXT_DIR} are compiled as Debug binaries."
)
endif("${DB_OUT}" MATCHES ".*MSVCP[0-9]*d.dll.*" OR "${DB_OUT}" MATCHES ".*MSVCP[0-9]*D.dll.*")
endif("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
if(NOT "${DB_OUT}" MATCHES ".*MSVCP[0-9]*d.dll.*" AND NOT "${DB_OUT}" MATCHES ".*MSVCP[0-9]*D.dll.*")
message(
FATAL_ERROR
"Debug build specified, but supplied bext binaries in ${BRLCAD_EXT_DIR} are compiled as Release binaries."
)
endif(NOT "${DB_OUT}" MATCHES ".*MSVCP[0-9]*d.dll.*" AND NOT "${DB_OUT}" MATCHES ".*MSVCP[0-9]*D.dll.*")
endif("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
endif(DUMPBIN_EXEC AND EXISTS ${TEST_BINFILE})
endif(CMAKE_BUILD_TYPE AND EXISTS "${BRLCAD_EXT_NOINSTALL_DIR}")
#---------------------------------------------------------------------
# Define various utilities.
include(BRLCAD_Util)
#---------------------------------------------------------------------
# Define an option to use OBJECT libraries. If we are building with object
# libraries, we need position independent code.
include(CMakeDependentOption)
cmake_dependent_option(
USE_OBJECT_LIBS
"Use OBJECT libraries"
ON
"NOT MSVC"
OFF
)
mark_as_advanced(USE_OBJECT_LIBS)
if(USE_OBJECT_LIBS)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
endif(USE_OBJECT_LIBS)
#---------------------------------------------------------------------
# Record the CMake command line arguments (more or less) in
# CMakeFiles/CMakeOutput.log
record_cmdline_args()
#---------------------------------------------------------------------
# Set up the necessary support for timing of the configuration and
# build processes
string(TIMESTAMP CONFIG_DATE "%Y%m%d")
string(TIMESTAMP CONFIG_DATESTAMP "%a, %d %b %Y %H:%M:%S UTC" UTC)
#---------------------------------------------------------------------
# Mark the time at which the configuration process began.
set(CONFIG_DELTA_START "${CMAKE_BINARY_DIR}/CMakeTmp/CONFIG_DELTA_START")
execute_process(
COMMAND "${CMAKE_COMMAND}" -DSTAMP_FILE=${CONFIG_DELTA_START} -P "${BRLCAD_CMAKE_DIR}/scripts/timestamp.cmake"
)
#---------------------------------------------------------------------
# Define relative install locations and output directories. Don't set
# these if they have already been set by some other means (like a
# higher level CMakeLists.txt file including this one).
# For output directories - where built library and executable
# files will be placed after building but prior to install. The
# necessary variables change between single and multi configuration
# build systems, so it is necessary to handle both cases on a
# conditional basis.
include(Path_Setup)
#---------------------------------------------------------------------
# For cleaning files as part of the distclean command, CMake needs
# to be aware of what various generators will (or might) write out
# in each build directory.
set(DISTCLEAN_OUTFILES CTestTestfile.cmake Testing/Temporary/CTestCostData.txt Testing/Temporary/LastTest.log)
if("${CMAKE_GENERATOR}" MATCHES "Make")
set(DISTCLEAN_OUTFILES ${DISTCLEAN_OUTFILES} Makefile)
endif("${CMAKE_GENERATOR}" MATCHES "Make")
if("${CMAKE_GENERATOR}" MATCHES "Ninja")
set(DISTCLEAN_OUTFILES ${DISTCLEAN_OUTFILES} build.ninja rules.ninja .ninja_log)
endif("${CMAKE_GENERATOR}" MATCHES "Ninja")
#---------------------------------------------------------------------
# CMake's default "make test" target is a bit limited - define
# our own "unit" and "check" targets that automate more of the
# dependency updating process.
include(BRLCAD_Test_Wrappers)
#---------------------------------------------------------------------
# Load macros that will be used to define the BRL-CAD
# build logic
include(BRLCAD_Options)
include(BRLCAD_Targets)
include(CheckTypeSize)
include(CheckCSourceCompiles)
include(CheckCXXSourceCompiles)
#---------------------------------------------------------------------
# print out the title with a pretty box computed to wrap around
box_print("*** Configuring BRL-CAD Release ${BRLCAD_VERSION}, Build ${CONFIG_DATE} ***" "*")
#---------------------------------------------------------------------
# Set up include paths for generated header files.
include_directories(${CMAKE_BINARY_DIR}/${INCLUDE_DIR}/brlcad)
#---------------------------------------------------------------------
# We want to check /usr/local by default, so add it if it exists
if(IS_DIRECTORY /usr/local)
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} /usr/local)
if(IS_DIRECTORY /usr/local/include)
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} /usr/local/include)
endif(IS_DIRECTORY /usr/local/include)
endif(IS_DIRECTORY /usr/local)
#---------------------------------------------------------------------
# Intricacies involved with setting the install path mostly revolve
# around build type dependent install directories. Also needs the
# current version defined.
include(BRLCAD_Install_Prefix)
#---------------------------------------------------------------------
# RPath is used on platforms such as Linux to allow programs to be
# relocatable. It is also used to help programs run from their
# positions in the build directory.
#
# Managing this is somewhat involved - there are lots of situations
# where the logic will work because of a full path present in the
# rpath settings and mask a problem with the relative lookup.
# We want the full RPATH set in the build tree so we can run programs without
# needing to set LD_LIBRARY_PATH
set(CMAKE_SKIP_BUILD_RPATH FALSE)
# We DON'T want the final install directory RPATH set in the build directory -
# it should only be set to the installation value when actually installed.
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
# 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 following logic is what allows binaries to run successfully in the build
# directory AND install directory.
# This will need to be overridden for some targets that have a different
# relative position to LIB_DIR using the INSTALL_RPATH target property.
# However, we can cover the most common case for RPATH setting using the
# global default.
if(NOT APPLE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_DIR}:$ORIGIN/../${LIB_DIR}")
else(NOT APPLE)
# For OSX, use the INSTALL_NAME_DIR target property
set(CMAKE_INSTALL_RPATH "@executable_path/../${LIB_DIR}")
set(CMAKE_INSTALL_NAME_DIR "@executable_path/../${LIB_DIR}")
endif(NOT APPLE)
#---------------------------------------------------------------------
# For certain platforms (in particular Visual C++) we want to keep some pre-defined
# flags that are commonly used in the build logic.
if(NOT DEFINED CMAKE_C_FLAGS_DEFAULT)
set(CMAKE_C_FLAGS_DEFAULT "${CMAKE_C_FLAGS}" CACHE STRING "Default C flags" FORCE)
endif(NOT DEFINED CMAKE_C_FLAGS_DEFAULT)
mark_as_advanced(CMAKE_C_FLAGS_DEFAULT)
if(NOT DEFINED CMAKE_CXX_FLAGS_DEFAULT)
set(CMAKE_CXX_FLAGS_DEFAULT "${CMAKE_CXX_FLAGS}" CACHE STRING "Default CXX flags" FORCE)
endif(NOT DEFINED CMAKE_CXX_FLAGS_DEFAULT)
mark_as_advanced(CMAKE_CXX_FLAGS_DEFAULT)
# OpenBSD 6.6 doesn't tolerate these flags when using #include <iostream>,
# so we have to test
#---------------------------------------------------------------------
# We need compiler support for certain C and C++ standards when we
# build. Set CMake's flags accordingly for what source code syntax
# (i.e., -std=xxx flags) and API (i.e., -D_POSIX_C_SOURCE defines) to
# permit and utilize respectively. Common profiles:
#
# 2011-2016: C11 & C++11 (reliably targets: 2013)
# ISO/IEC 9899:2011 __STDC_VERSION__==201112L
# ISO/IEC 14882:2011 __cplusplus==201103L
# IEEE 1003.1-2008 -D_POSIX_C_SOURCE=200809L
# Open Group Single UNIX Specification, Version 4 (2008+) -D_XOPEN_SOURCE=700
# 2014-2017: C11 & C++14 (reliably targets: 2016)
# ISO/IEC 9899:2011 __STDC_VERSION__==201112L
# ISO/IEC 14882:2014 __cplusplus==201402L
# IEEE 1003.1-2008 -D_POSIX_C_SOURCE=200809L
# Open Group Single UNIX Specification, Version 4 (2008+) -D_XOPEN_SOURCE=700
# 2017-2020: C11 & C++17 (reliably targets: 2019)
# ISO/IEC 9899:2011 __STDC_VERSION__==201112L
# ISO/IEC 14882:2017 __cplusplus==201703L
# IEEE 1003.1-2008 -D_POSIX_C_SOURCE=200809L
# Open Group Single UNIX Specification, Version 4 (2008+) -D_XOPEN_SOURCE=700
#
# Sources: https://sourceforge.net/p/predef/wiki/Standards/
include(BRLCAD_API_Flag)
set(API_FLAGS)
brlcad_api_flag("-D_POSIX_C_SOURCE=200809L" API_FLAGS)
brlcad_api_flag("-D_XOPEN_SOURCE=700" API_FLAGS)
# C
unset(C_STANDARD_FLAGS)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(C_STANDARD_FLAGS "${CMAKE_C_FLAGS_DEFAULT} ${CMAKE_C${CMAKE_C_STANDARD}_STANDARD_COMPILE_OPTION} ${API_FLAGS}")
string(STRIP "${C_STANDARD_FLAGS}" C_STANDARD_FLAGS)
# C++
unset(CXX_STANDARD_FLAGS)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(
CXX_STANDARD_FLAGS
"${CMAKE_CXX_FLAGS_DEFAULT} ${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION} ${API_FLAGS}"
)
string(STRIP "${CXX_STANDARD_FLAGS}" CXX_STANDARD_FLAGS)
#---------------------------------------------------------------------
# We will need a brlcad_config.h.in file to hold all the #cmakedefine
# statements, which will in turn be used to generate a brlcad_conf.h
# file. In autotools this process is handled by autoheader - in the
# case of CMake we wrap the CHECK_* functions and the creation of the
# entry in the brlcad_config.h.in file into one step via a macro.
#
# To avoid hitting the disk I/O any harder than necessary, we store
# the eventual contents of brlcad_config.h.in as a CMake string until
# it is ready to process.
#
# We also allow for multiple projects with this macro, in case
# subprojects are also managing a config.h.in a file of their own.
set(CONFIG_H_FILE "${BRLCAD_BINARY_DIR}/include/brlcad_config.h.in")
set(CMAKE_CURRENT_PROJECT BRLCAD)
define_property(
GLOBAL
PROPERTY BRLCAD_CONFIG_H_CONTENTS
BRIEF_DOCS "config.h.in contents"
FULL_DOCS "config.h.in contents for BRL-CAD project"
)
if(NOT COMMAND CONFIG_H_APPEND)
function(CONFIG_H_APPEND PROJECT_NAME NEW_CONTENTS)
if(PROJECT_NAME)
get_property(${PROJECT_NAME}_CONFIG_H_CONTENTS GLOBAL PROPERTY ${PROJECT_NAME}_CONFIG_H_CONTENTS)
set(${PROJECT_NAME}_CONFIG_H_FILE_CONTENTS "${${PROJECT_NAME}_CONFIG_H_CONTENTS}${NEW_CONTENTS}")
set_property(GLOBAL PROPERTY ${PROJECT_NAME}_CONFIG_H_CONTENTS "${${PROJECT_NAME}_CONFIG_H_FILE_CONTENTS}")
endif(PROJECT_NAME)
endfunction(CONFIG_H_APPEND NEW_CONTENTS)
endif(NOT COMMAND CONFIG_H_APPEND)
config_h_append(BRLCAD "/**** Define statements for CMake ****/\n")
config_h_append(BRLCAD "#if !defined(BRLCADBUILD)\n")
config_h_append(BRLCAD " # pragma message \"Warning: included brlcad_config.h (compile-time API) without BRLCADBUILD defined\"\n"
)
config_h_append(BRLCAD "#endif\n")
config_h_append(BRLCAD "#if !defined(HAVE_CONFIG_H)\n")
config_h_append(BRLCAD " # pragma message \"Warning: included brlcad_config.h (compile-time API) without HAVE_CONFIG_H defined\"\n"
)
config_h_append(BRLCAD "#endif\n")
config_h_append(BRLCAD "#ifndef __CONFIG_H__\n")
config_h_append(BRLCAD "#define __CONFIG_H__\n")
# Set up some of the define statements for path information and other basics
config_h_append(BRLCAD "#define PACKAGE \"brlcad\"\n")
config_h_append(BRLCAD "#define PACKAGE_NAME \"BRL-CAD\"\n")
#----------------------------------------------------------------------
# Let our code know what the minimum active C++ standard is - behavior
# of some C++ functionality differs at runtime based on version.
config_h_append(BRLCAD "#define CXX_STANDARD ${CMAKE_CXX_STANDARD}\n")
# *******************************************************************
if(BRLCAD_PRINT_MSGS)
message("***********************************************************")
message("* Stage 1 of 9 - Top Level Configure Options *")
message("***********************************************************")
endif(BRLCAD_PRINT_MSGS)
include(BRLCAD_User_Options)
# global msvc-specific configuration setup
if("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
# Auto-reconfiguration - by default, a CMake generated build system
# will re-run CMake if it detects that build system logic has
# changed. This is normally a good thing, but becomes problematic
# when using Visual Studio - recent versions of MSVC will
# individually prompt for a re-loading of generated solution files
# one at a time. Since BRL-CAD has over a thousand such files in a
# default build, the only viable approach is to close Visual Studio,
# re-run CMake manually, and re-open the project in Visual Studio.
set(CMAKE_SUPPRESS_REGENERATION ON)
# make visual studio default to a more useful output summary instead
# of minimal lines with no compilation context.
if(NOT DEFINED CMAKE_VERBOSE_MAKEFILE)
set(CMAKE_VERBOSE_MAKEFILE ON)
endif(NOT DEFINED CMAKE_VERBOSE_MAKEFILE)
endif("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
# *******************************************************************
if(BRLCAD_PRINT_MSGS)
message("***********************************************************")
message("* Stage 2 of 9 - Check for Programs *")
message("***********************************************************")
endif(BRLCAD_PRINT_MSGS)
# Load various wrapper macros for checking libraries, headers and
# functions
include(BRLCAD_CheckFunctions)
# A variety of tools, such as the benchmark utilities, need
# a Bourne shell and other commands - check for them.
include(FindShellDeps)
# If using dtrace, we will need to find it
if(BRLCAD_ENABLE_DTRACE)
find_program(DTRACE_EXEC NAMES dtrace DOC "path to dtrace executable")
endif(BRLCAD_ENABLE_DTRACE)
# SWIG is an automatic generator of wrappers for various
# software languages
find_package(SWIG)
mark_as_advanced(SWIG_EXECUTABLE)
mark_as_advanced(SWIG_DIR)
mark_as_advanced(SWIG_VERSION)
# Doxygen is a tool for generating formatted documentation
# from structured source code comments.
include(Doxygen)
find_package(Doxygen)
# Define high level features of BRL-CAD. We define the features here,
# to allow for the possibility that this is a Doxygen-only build (i.e.
# we won't be processing most of the build logic and are just setting
# up for our Doxygen run.
doxygen_feature("Portability Library" DESCRIPTION "Portability layer that makes sure basic low level system functionality is present across all platforms via a uniform API.")
doxygen_feature("Solid Raytracing" DESCRIPTION "Ray/geometry intersection calculations that report not just first surface hits but in/out pairs of hits to support the characterization of closed geometric volumes.")
# If we ONLY want to produce Doxygen output, there's no point in doing
# the full configure and bext build process
if(BRLCAD_DOXYGEN_ONLY)
file(MAKE_DIRECTORY "${BRLCAD_BINARY_DIR}/doc")
add_subdirectory(misc/doxygen)
doxygen_feature_summary("${BRLCAD_BINARY_DIR}/CMakeTmp/features.dox")
return()
endif(BRLCAD_DOXYGEN_ONLY)
# *******************************************************************
if(BRLCAD_PRINT_MSGS)
message("***********************************************************")
message("* Stage 3 of 9 - Check for Compiler Characteristics *")
message("***********************************************************")
endif(BRLCAD_PRINT_MSGS)
# load our compiler testing macro definitions
include(CompilerFlags)
# Clear out most CMake-assigned defaults - We're managing
# our own compile flags, and don't (for example) want NDEBUG
# if we have debugging flags enabled for a Release build.
# At the same time, pull in any flags that have been set
# in the environment.
clear_build_flags()
# We need the C and C++ standards
set(CMAKE_C_FLAGS "${C_STANDARD_FLAGS}")
set(CMAKE_CXX_FLAGS "${CXX_STANDARD_FLAGS}")
# try to use -pipe to speed up the compiles
check_c_flag(pipe)
check_cxx_flag(pipe)
# Enable visibility restrictions. We have to deal with this on Windows, so
# enable it wherever we can to keep the code working across all platforms.
check_c_flag(fvisibility=hidden)
check_cxx_flag(fvisibility=hidden)
# If we can, hide internal library symbols
if(FVISIBILITY_HIDDEN_CXX_FLAG_FOUND)
set(HIDE_INTERNAL_SYMBOLS 1)
endif(FVISIBILITY_HIDDEN_CXX_FLAG_FOUND)
if(MSVC)
# On platforms other than MSVC, the hidden symbols are a convenience and may
# not be supported by system lib headers. With Visual Studio, they are a
# necessity - define an extra flag so we know to always set them in that
# case in order to properly link against the system libs.
set(HIDE_INTERNAL_SYMBOLS 1)
set(HIDE_INTERNAL_SYMBOLS_EXT 1)
endif(MSVC)
# check for -fno-strict-aliasing
# XXX - THIS FLAG IS REQUIRED if any level of optimization is
# enabled with GCC as we do use aliasing and type-punning.
check_c_flag(fno-strict-aliasing)
check_cxx_flag(fno-strict-aliasing)
# check for -fno-common (libtcl needs it on darwin)
check_c_flag(fno-common)
check_cxx_flag(fno-common)
# check for -fexceptions
# this is needed to resolve __Unwind_Resume when compiling and
# linking against openNURBS in librt for any -static binaries
check_c_flag(fexceptions)
check_cxx_flag(fexceptions)
# check for -ftemplate-depth-NN this is needed in libpc and
# other code using boost where the template instantiation depth
# needs to be increased from the default ANSI minimum of 17.
check_cxx_flag(ftemplate-depth-128)
# dynamic SSE optimizations for NURBS processing
#
# XXX disable the SSE flags for now as they can cause illegal instructions.
# the test needs to also be tied to run-time functionality since gcc
# may still output SSE instructions (e.g., for cross-compiling).
# CHECK_C_FLAG(msse)
# CHECK_C_FLAG(msse2)
# CHECK_C_FLAG(msse3)
# TODO - should be using this with MSVC, but it breaks the BUILD_SLEEP
# try_compile below with errors that appear to be coming from Windows
# headers??
# CHECK_C_FLAG("Za")
# 64bit compilation flags
if(${CMAKE_WORD_SIZE} MATCHES "64BIT" AND NOT CMAKE_CL_64)
check_c_flag(m64 VARS 64BIT_FLAG)
check_c_flag("arch x86_64" VARS 64BIT_FLAG)
check_c_flag(64 VARS 64BIT_FLAG)
check_c_flag("mabi=64" VARS 64BIT_FLAG)
check_c_flag(q64 VARS 64BIT_FLAG)
if(64BIT_FLAG AND ${CMAKE_WORD_SIZE} MATCHES "64BIT")
add_new_flag(C 64BIT_FLAG ALL)
add_new_flag(CXX 64BIT_FLAG ALL)
add_new_flag(SHARED_LINKER 64BIT_FLAG ALL)
add_new_flag(EXE_LINKER 64BIT_FLAG ALL)
endif(64BIT_FLAG AND ${CMAKE_WORD_SIZE} MATCHES "64BIT")
endif(${CMAKE_WORD_SIZE} MATCHES "64BIT" AND NOT CMAKE_CL_64)
# 32 bit compilation flags
if(${CMAKE_WORD_SIZE} MATCHES "32BIT" AND NOT ${BRLCAD_WORD_SIZE} MATCHES "AUTO" AND NOT MSVC)
check_c_flag(m32 VARS 32BIT_FLAG)
check_c_flag("arch i686" VARS 32BIT_FLAG)
check_c_flag(32 VARS 32BIT_FLAG)
check_c_flag("mabi=32" VARS 32BIT_FLAG)
check_c_flag(q32 VARS 32BIT_FLAG)
if(32BIT_FLAG AND ${CMAKE_WORD_SIZE} MATCHES "32BIT")
add_new_flag(C 32BIT_FLAG ALL)
add_new_flag(CXX 32BIT_FLAG ALL)
add_new_flag(SHARED_LINKER 32BIT_FLAG ALL)
add_new_flag(EXE_LINKER 32BIT_FLAG ALL)
endif(32BIT_FLAG AND ${CMAKE_WORD_SIZE} MATCHES "32BIT")
endif(${CMAKE_WORD_SIZE} MATCHES "32BIT" AND NOT ${BRLCAD_WORD_SIZE} MATCHES "AUTO" AND NOT MSVC)
# Debugging flags
if(BRLCAD_DEBUGGING)
check_c_flag(g GROUPS DEBUG_C_FLAGS)
check_cxx_flag(g GROUPS DEBUG_CXX_FLAGS)
check_c_flag(ggdb3 GROUPS DEBUG_C_FLAGS)
check_cxx_flag(ggdb3 GROUPS DEBUG_CXX_FLAGS)
set(debug_config_list "ALL")
add_new_flag(C DEBUG_C_FLAGS "${debug_config_list}")
add_new_flag(CXX DEBUG_CXX_FLAGS "${debug_config_list}")
# TODO - need to figure out a way to actually test linker flags
add_new_flag(SHARED_LINKER DEBUG_C_FLAGS "${debug_config_list}")
add_new_flag(EXE_LINKER DEBUG_C_FLAGS "${debug_config_list}")
mark_as_advanced(DEBUG_FLAGS)
endif(BRLCAD_DEBUGGING)
# Warn if no minimum compilation linkage is set for Mac systems
if(APPLE AND "${CMAKE_BUILD_TYPE}" STREQUAL "Release" AND "$ENV{MACOSX_DEPLOYMENT_TARGET}" STREQUAL "")
message(
WARNING
"}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}\nMACOSX_DEPLOYMENT_TARGET should be set for release builds\nto something less than the latest release for portability\ne.g., export MACOSX_DEPLOYMENT_TARGET=10.5\nSee https://github.com/brlcad/MacOSX-SDKs\n}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}"
)
endif(APPLE AND "${CMAKE_BUILD_TYPE}" STREQUAL "Release" AND "$ENV{MACOSX_DEPLOYMENT_TARGET}" STREQUAL "")
# Most external projects have their own logic for handling
# the C inline issue - BRL-CAD needs a fine-grained approach.
# C and C++ sources require different treatment for the same build
# target, since C++11 doesn't allow inline to be re-defined.
check_c_inline(C_INLINE)
if(NOT HAVE_INLINE_KEYWORD AND HAVE___INLINE_KEYWORD)
config_h_append(BRLCAD "#ifndef __cplusplus\n")
config_h_append(BRLCAD "# define inline __inline\n")
config_h_append(BRLCAD "#endif /* !__cplusplus */\n")
elseif(HAVE_INLINE_KEYWORD)
# this ugly hack is to avoid broken Mac OS X (10.13 era) ctype
# headers that drop the inline keyword when compiling c99.
config_h_append(BRLCAD "#if !defined(inline) && !defined(__cplusplus)\n")
config_h_append(BRLCAD "# define inline inline\n")
config_h_append(BRLCAD "#endif /* !inline && !__cplusplus */\n")
endif(NOT HAVE_INLINE_KEYWORD AND HAVE___INLINE_KEYWORD)
# If building optimized, set _FORTIFY_SOURCE to 2. Provides
# compile-time best-practice error checking on certain libc functions
# (e.g., memcpy), and provides run-time checks on buffer lengths and
# memory regions. Unfortunately, glibc-1.6 made _FORTIFY_SOURCE spew
# an unquellable warning if optimization is disabled so we can't tie
# the flag to debug builds.
#
# TODO (3/2024) - is glibc-1.6 old enough now that we could fold this into the
# debug build flags?
if(${BRLCAD_OPTIMIZED} MATCHES "ON")
config_h_append(BRLCAD "#ifndef _FORTIFY_SOURCE\n# define _FORTIFY_SOURCE 2\n#endif\n")
endif(${BRLCAD_OPTIMIZED} MATCHES "ON")
# Enable this flag for additional reporting of undefined symbols.
# TODO: Fixing these is a work in progress.
# CHECK_C_COMPILER_FLAG("Wl,--no-undefined" NO_UNDEFINED_LINKER_FLAG)
# ******************************************************************* #
# For some tests, we need Werror to make sure the test actually fails
cmake_push_check_state(RESET)
check_c_flag(Werror VARS ERROR_FLAG)
if(ERROR_FLAG)
set(CMAKE_REQUIRED_FLAGS "-Werror")
endif(ERROR_FLAG)
# Check whether the compiler supports __attribute__((format (__printf__, 1, 2)))
check_c_source_compiles(
"int pf(const char *f, ...) __attribute__((format (__printf__, 1, 2))); int pf(const char *f, ...){return 1;} int main(int argc, char *argv[]) {return pf(\"%c\",'a');}"
HAVE_PRINTF12_ATTRIBUTE
)
if(HAVE_PRINTF12_ATTRIBUTE)
config_h_append(BRLCAD "#define HAVE_PRINTF12_ATTRIBUTE 1\n")
endif(HAVE_PRINTF12_ATTRIBUTE)
# Check whether the compiler supports __attribute__((format (__printf__, 2, 3)))
check_c_source_compiles(
"int pf(void *o, const char *f, ...) __attribute__((format (__printf__, 2, 3))); int pf(void *o, const char *f, ...){return 1;} int main(int argc, char *argv[]) {return pf((void *)0, \"%c\",'a');}"
HAVE_PRINTF23_ATTRIBUTE
)
if(HAVE_PRINTF23_ATTRIBUTE)
config_h_append(BRLCAD "#define HAVE_PRINTF23_ATTRIBUTE 1\n")
endif(HAVE_PRINTF23_ATTRIBUTE)
# Check whether the compiler supports __attribute__((format (__scanf__, 2, 3)))
check_c_source_compiles(
"int sf(void *o, const char *f, ...) __attribute__((format (__scanf__, 2, 3))); int sf(void *o, const char *f, ...){return 1;} int main(int argc, char *argv[]) {int i = 1; return sf((void *)0, \"%d\", &i);}"
HAVE_SCANF23_ATTRIBUTE
)
if(HAVE_SCANF23_ATTRIBUTE)
config_h_append(BRLCAD "#define HAVE_SCANF23_ATTRIBUTE 1\n")
endif(HAVE_SCANF23_ATTRIBUTE)
# Check whether the compiler supports __attribute__((deprecated))
check_c_source_compiles(
"__attribute__((deprecated)) void func(void); void func(void){} void func2(void){} int main(int argc, char *argv[]) {func2(); return 0;}"
HAVE_DEPRECATED_ATTRIBUTE
)
if(HAVE_DEPRECATED_ATTRIBUTE)
config_h_append(BRLCAD "#define HAVE_DEPRECATED_ATTRIBUTE 1\n")
endif(HAVE_DEPRECATED_ATTRIBUTE)
# Check whether the compiler supports __declspec(deprecated())
check_c_source_compiles(
"__declspec(deprecated(\"DEPRECATED\")) void func(void); void func(void){} void func2(void){} int main(int argc, char *argv[]) {func2(); return 0;}"
HAVE_DEPRECATED_DECLSPEC
)
if(HAVE_DEPRECATED_DECLSPEC)
config_h_append(BRLCAD "#define HAVE_DEPRECATED_DECLSPEC 1\n")
endif(HAVE_DEPRECATED_DECLSPEC)
# Check whether the compiler supports __attribute__((__noreturn__))
check_c_source_compiles(
"#include <stdlib.h>
__attribute__((__noreturn__)) void noret(void); void noret(void){exit(1);} int main(int argc, char *argv[]) {noret(); return 0;}"
HAVE_NORETURN_ATTRIBUTE
)
if(HAVE_NORETURN_ATTRIBUTE)
config_h_append(BRLCAD "#define HAVE_NORETURN_ATTRIBUTE 1\n")
endif(HAVE_NORETURN_ATTRIBUTE)
# Check whether the compiler supports __declspec(noreturn)
check_c_source_compiles(
"#include <stdlib.h>
__declspec(noreturn) void noret(void) {exit(1);} int main(int argc, char *argv[]) {noret(); return 0;}"
HAVE_NORETURN_DECLSPEC
)
if(HAVE_NORETURN_DECLSPEC)
config_h_append(BRLCAD "#define HAVE_NORETURN_DECLSPEC 1\n")
endif(HAVE_NORETURN_DECLSPEC)
# Check whether the compiler supports __attribute__((analyzer_noreturn))
check_c_source_compiles(
"__attribute__((analyzer_noreturn)) void anoret(void); void anoret(void){return;} int main(int argc, char *argv[]) {anoret(); return 0;}"
HAVE_ANALYZER_NORETURN_ATTRIBUTE
)
if(HAVE_ANALYZER_NORETURN_ATTRIBUTE)
config_h_append(BRLCAD "#define HAVE_ANALYZER_NORETURN_ATTRIBUTE 1\n")
endif(HAVE_ANALYZER_NORETURN_ATTRIBUTE)
# Check whether the compiler supports __attribute__((always_inline))
check_c_source_compiles(
"__attribute__((always_inline)) inline void always_inline(void); inline void always_inline(void){return;} int main(int argc, char *argv[]) {always_inline(); return 0;}"
HAVE_ALWAYS_INLINE_ATTRIBUTE
)
if(HAVE_ALWAYS_INLINE_ATTRIBUTE)
config_h_append(BRLCAD "#define HAVE_ALWAYS_INLINE_ATTRIBUTE 1\n")
endif(HAVE_ALWAYS_INLINE_ATTRIBUTE)
# Check whether the compiler supports __forceinline
check_c_source_compiles(
"__forceinline inline void always_inline(void); inline void always_inline(void){return;} int main(int argc, char *argv[]) {always_inline(); return 0;}"
HAVE_FORCEINLINE
)
if(HAVE_FORCEINLINE)
config_h_append(BRLCAD "#define HAVE_FORCEINLINE 1\n")
endif(HAVE_FORCEINLINE)
# Check whether the compiler supports __attribute__((const))
check_c_source_compiles(
"__attribute__((const)) void func(void); void func(void){return;} int main(int argc, char *argv[]) {func(); return 0;}"
HAVE_CONST_ATTRIBUTE
)
if(HAVE_CONST_ATTRIBUTE)
config_h_append(BRLCAD "#define HAVE_CONST_ATTRIBUTE 1\n")
endif(HAVE_CONST_ATTRIBUTE)
# Check whether the compiler supports __attribute__((pure))
check_c_source_compiles(
"__attribute__((pure)) void func(void); void func(void){return;} int main(int argc, char *argv[]) {func(); return 0;}"
HAVE_PURE_ATTRIBUTE
)
if(HAVE_PURE_ATTRIBUTE)
config_h_append(BRLCAD "#define HAVE_PURE_ATTRIBUTE 1\n")
endif(HAVE_PURE_ATTRIBUTE)
# Check whether the compiler supports __attribute__((cold))
check_c_source_compiles(
"__attribute__((cold)) void func(void); void func(void){return;} int main(int argc, char *argv[]) {func(); return 0;}"
HAVE_COLD_ATTRIBUTE
)
if(HAVE_COLD_ATTRIBUTE)
config_h_append(BRLCAD "#define HAVE_COLD_ATTRIBUTE 1\n")
endif(HAVE_COLD_ATTRIBUTE)
# Check whether the compiler supports __attribute__((hot))
check_c_source_compiles(
"__attribute__((hot)) void func(void); void func(void){return;} int main(int argc, char *argv[]) {func(); return 0;}"
HAVE_HOT_ATTRIBUTE
)
if(HAVE_HOT_ATTRIBUTE)
config_h_append(BRLCAD "#define HAVE_HOT_ATTRIBUTE 1\n")
endif(HAVE_HOT_ATTRIBUTE)
# Check whether the compiler supports __attribute__((nonnull))
check_c_source_compiles(
"__attribute__((nonnull)) int *func(int *); int *func(int *v){(*v)-=1; return v;} int main(int argc, char *argv[]) {int v = 1; int *vp = func(&v); return *vp;}"
HAVE_NONNULL_ATTRIBUTE
)
if(HAVE_NONNULL_ATTRIBUTE)
config_h_append(BRLCAD "#define HAVE_NONNULL_ATTRIBUTE 1\n")
endif(HAVE_NONNULL_ATTRIBUTE)
# Check whether the compiler supports __attribute__((warn_unused_result))
check_c_source_compiles(
"__attribute__((warn_unused_result)) int *func(int *); int *func(int *v){(*v)-=1; return v;} int main(int argc, char *argv[]) {int v = 1; int *vp = func(&v); return *vp;}"
HAVE_WARN_UNUSED_RESULT_ATTRIBUTE
)
if(HAVE_WARN_UNUSED_RESULT_ATTRIBUTE)
config_h_append(BRLCAD "#define HAVE_WARN_UNUSED_RESULT_ATTRIBUTE 1\n")
endif(HAVE_WARN_UNUSED_RESULT_ATTRIBUTE)
# Check whether the compiler supports __attribute__((flatten))
check_c_source_compiles(
"__attribute__((flatten)) int *func(int *v){(*v)-=1; return v;} __attribute((flatten)) int main(int argc, char *argv[]) {int v = 1; int *vp = func(&v); return *vp;}"
HAVE_FLATTEN_ATTRIBUTE
)
if(HAVE_FLATTEN_ATTRIBUTE)
config_h_append(BRLCAD "#define HAVE_FLATTEN_ATTRIBUTE 1\n")
endif(HAVE_FLATTEN_ATTRIBUTE)
# Silence check for unused arguments (used to silence clang warnings about
# unused options on the command line). By default clang generates a lot of
# warnings about such arguments, and we don't really care.
check_c_flag(Qunused-arguments)
check_cxx_flag(Qunused-arguments)
cmake_pop_check_state()
# The following tests are almost entirely for gcc/llvm style flags, so
# we don't unnecessarily slow down the Windows build.
if(NOT MSVC)
# This is nominally a header test, but because it can impact the C/C++ flags
# we do it before the final caching of BRL-CAD flags. We need this because
# pthread headers on some BSD platforms still haven't been scrubbed for
# c90/posix.1 compliance - see r70785
brlcad_include_file(pthread.h PROBE_PTHREAD_H)
if(NOT PROBE_PTHREAD_H)
cmake_push_check_state(RESET)
# pthread.h on FreeBSD 10 and some older Linucies use non-c90 types
set(CMAKE_REQUIRED_DEFINITIONS "-Dclockid_t=clock_t")
set(CMAKE_REQUIRED_FLAGS "-pthread")
brlcad_include_file(pthread.h PROBE_PTHREAD_H_CLOCKID_T)
if(PROBE_PTHREAD_H_CLOCKID_T)
set(C_STANDARD_FLAGS "${C_STANDARD_FLAGS} -Dclockid_t=clock_t -pthread")
set(CXX_STANDARD_FLAGS "${CXX_STANDARD_FLAGS} -Dclockid_t=clock_t -pthread")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Dclockid_t=clock_t -pthread")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Dclockid_t=clock_t -pthread")
endif(PROBE_PTHREAD_H_CLOCKID_T)
endif(NOT PROBE_PTHREAD_H)
# -O3/-Ofast can enable -ffast-math which can provoke a stack
# corruption in the shadow computations because of strict aliasing
# getting enabled. we _require_ -fno-strict-aliasing until someone
# changes how lists are managed. -fast-math results in non-IEEE
# floating point math among a handful of other optimizations that
# cause substantial error in ray tracing and tessellation (and
# probably more).
check_c_flag(O3 GROUPS OPTIMIZE_C_FLAGS)
check_cxx_flag(O3 GROUPS OPTIMIZE_CXX_FLAGS)
# goes a step beyond O3, possibly using dangerous imprecise math
# CHECK_C_FLAG(Ofast GROUPS OPTIMIZE_C_FLAGS)
# CHECK_CXX_FLAG(Ofast GROUPS OPTIMIZE_CXX_FLAGS)
# binaries will not necessarily work on a different machine
# CHECK_C_FLAG(march=native GROUPS OPTIMIZE_C_FLAGS)
# CHECK_CXX_FLAG(march=native GROUPS OPTIMIZE_CXX_FLAGS)
# perform interprocedural analysis, slows compilation heavily
check_c_flag(fipa-pta GROUPS OPTIMIZE_C_FLAGS)
check_cxx_flag(fipa-pta GROUPS OPTIMIZE_CXX_FLAGS)
# enabled at -O2, but not in older compilers
check_c_flag(fstrength-reduce GROUPS OPTIMIZE_C_FLAGS)
check_cxx_flag(fstrength-reduce GROUPS OPTIMIZE_CXX_FLAGS)
# enabled at -O2, but not in older compilers
check_c_flag(fexpensive-optimizations GROUPS OPTIMIZE_C_FLAGS)
check_cxx_flag(fexpensive-optimizations GROUPS OPTIMIZE_CXX_FLAGS)
# enabled at -O3, but not in older compilers