-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
1909 lines (1677 loc) · 92 KB
/
CMakeLists.txt
File metadata and controls
1909 lines (1677 loc) · 92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
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
########################################################################################################################
# General warnings, instructions, and style guide.
########################################################################################################################
# 1. Please be careful about where to put your tests and variable settings. The order matters!!
#
# 2. CMake configuration files are neither completely case-sensitive nor completely case-insensitive. Therefore, to
# avoid errors, assume everything is case sensitive. Prefer lower case for function names.
#
# 3. Do not use argument turds in "else()" and "endif()" functions. Those arguments are only comments and are entirely
# redundant with the "if()" argument and easily become out of date and misleading since nobody actually reads them.
#
# 4. All messages should start with a capitalized word except in special circumstances where capitalization would be
# incorrect (such as the name of a command).
#
# 5. Indentation is two spaces. Do not use ASCII horizontal tab characters for indentation or alignment.
#
# 6. As with standard mathematical notation, there should be no white space on either side of a function's
# parentheses. This includes functions such as "if", "else", and "endif".
#
# 7. Prefer FALSE and TRUE as Boolean values since these are the names used in Mathematics and most other computer
# languages. Avoid OFF, ON, NO, YES, 0, 1, and especially avoid mixing them.
#
# 8. If a CMakefile file needs to be conditionally enabled, do it in that CMake file rather than around the
# add_subdirectory in the level above. This keeps all the logic for a directory in a single file rather than
# split across two files. It is a bit unfortunate that CMake can't find the lower-level CMakeList files
# on its own, so some of the logic is still necessarily in the level above. There are exceptions to this rule,
# and they're pretty obvious when they occur--as when a single if() protects a whole bunch of add_subdirectory.
########################################################################################################################
# Platform-independent settings
########################################################################################################################
cmake_minimum_required(VERSION 3.15)
#-----------------------------------------------------------------------------------------------------------------------
# CCACHE
# Enable ccache if not already enabled by symlink masquerading and if no other compiler launchers are already defined
#-----------------------------------------------------------------------------------------------------------------------
find_program(CCACHE_EXECUTABLE ccache)
mark_as_advanced(CCACHE_EXECUTABLE)
if(CCACHE_EXECUTABLE)
foreach(LANG C CXX)
if(NOT DEFINED CMAKE_${LANG}_COMPILER_LAUNCHER AND NOT CMAKE_${LANG}_COMPILER MATCHES ".*/ccache")
message(STATUS "Enabling ccache for ${LANG}")
set(CMAKE_${LANG}_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE} CACHE STRING "")
endif()
endforeach()
endif()
# Option for custom compilers
option(SKIP_ABI "Option to use custom CC/CXX" OFF)
if(DEFINED CACHE{SKIP-ABI})
message(DEPRECATION "SKIP-ABI is deprecated. Use SKIP_ABI instead. Example: cmake -DSKIP_ABI=${SKIP-ABI} ...")
set(SKIP_ABI ${SKIP-ABI} CACHE BOOL "Option to use custom CC/CXX" FORCE)
endif()
if(SKIP_ABI) # turn off checks and abi
set(CMAKE_C_ABI_COMPILED FALSE)
set(CMAKE_C_COMPILER_WORKS ON CACHE INTERNAL "")
set(CMAKE_C_STANDARD_LIBRARIES_INIT "")
set(CMAKE_CXX_ABI_COMPILED FALSE)
set(CMAKE_CXX_COMPILER_WORKS ON CACHE INTERNAL "")
set(CMAKE_CXX_STANDARD_LIBRARIES_INIT "")
endif()
#-----------------------------------------------------------------------------------------------------------------------
# Read ROSE version from ROSE_VERSION file before calling project()
# This is needed so that the project version can be set correctly, which affects library versioning
#-----------------------------------------------------------------------------------------------------------------------
set(ROSE_SCM_VERSION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/ROSE_VERSION")
if(NOT EXISTS "${ROSE_SCM_VERSION_FILE}")
message(FATAL_ERROR "ROSE version file not found: ${ROSE_SCM_VERSION_FILE}")
endif()
file(STRINGS ${ROSE_SCM_VERSION_FILE} ROSE_PACKAGE_VERSION LIMIT_COUNT 1)
project(ROSE
VERSION ${ROSE_PACKAGE_VERSION}
LANGUAGES C CXX
)
#-----------------------------------------------------------------------------------------------------------------------
# Adjust CMake's default optimization, debug, and assertion flags for different build types.
#
# "RelWithDebInfo" is intended to be optimized with debug info, but CMake adds -DNDEBUG by default which disables
# assertions. We want assertions enabled by default for this build type. If you don't want assertions then use
# "-DCMAKE_C_FLAGS=-DNDEBUG" and "-DCMAKE_CXX_FLAGS=-DNDEBUG". The optimization level defaults to "-O2", which
# is a compromise between full optimization and the ability to use most features of interactive debuggers.
#
# "Debug" is intended for developers to debug their libraries and tools, but CMake doesn't turn off optimizations. We
# add "-O0" so that all features of interactive debugging work properly, although this has a major negative effect on
# performance. We don't use "-Og" because this doesn't give the best debugging experience (too many local variables
# get optimized out and therefore one cannot inspect them in the debugger).
# -----------------------------------------------------------------------------------------------------------------------
string(REPLACE "-DNDEBUG" "" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
#-----------------------------------------------------------------------------------------------------------------------
# BLT
#-----------------------------------------------------------------------------------------------------------------------
# Use internal BLT if no BLT_SOURCE_DIR is given
if(NOT DEFINED BLT_SOURCE_DIR)
set(BLT_SOURCE_DIR "${PROJECT_SOURCE_DIR}/cmake/blt" CACHE PATH "Path to BLT")
endif()
# Support having a shared BLT outside of the repository if given a BLT_SOURCE_DIR
if(NOT EXISTS ${BLT_SOURCE_DIR}/SetupBLT.cmake)
message(FATAL_ERROR "Given BLT_SOURCE_DIR does not contain SetupBLT.cmake or"
"the BLT git submodule is not present. "
"Either run the following two commands in your git repository: \n"
" git submodule init\n"
" git submodule update\n"
"Or add -DBLT_SOURCE_DIR=/path/to/blt to your CMake command." )
endif()
# If the user sets CMAKE_CXX_STANDARD, use that for BLT_CXX_STD as well
if(CMAKE_CXX_STANDARD)
set(BLT_CXX_STD "c++${CMAKE_CXX_STANDARD}" CACHE STRING "")
elseif(NOT BLT_CXX_STD)
# Default to C++14 if not set so GTest/GMock can build
set(BLT_CXX_STD "c++14" CACHE STRING "")
set(CMAKE_CXX_STANDARD 14)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(${BLT_SOURCE_DIR}/SetupBLT.cmake)
#-----------------------------------------------------------------------------------------------------------------------
# CMAKE POLICIES
#-----------------------------------------------------------------------------------------------------------------------
# CMake 2.8.12 and newer has support for using @rpath in a target install name. This was enabled by setting the target
# property MACOSX_RPATH. The @rpath in an install name is a more flexible and powerful mechanism than @executable_path
# or @loader_path for locating shared libraries.
#
# CMake 3.0 and later prefer CMP0042 to be ON by default. Projects wanting @rpath in a target's install name may remove
# any setting of the INSTALL_NAME_DIR and CMAKE_INSTALL_NAME_DIR variables.
#
# CMP0042 was introduced in CMake version 3.0. CMake version 3.0.2 warns when the policy is not set and uses OLD
# behavior.
if(POLICY_CMP0042)
cmake_policy(SET CMP0042 NEW)
endif()
# CMP0054 causes CMake to only interpret "if()" arguments as variables or keywords when unquoted. CMake 3.1 and above no
# longer implicitly dereference variables or interpret keywords in an if() command argument when it is a Quoted Argument
# or a Bracket Argument. The OLD behavior for this policy is to dereference variables and interpret keywords even if
# they are quoted or bracketed. The NEW behavior is to not dereference variables or interpret keywords that have been
# quoted or bracketed.
if(POLICY CMP0054)
cmake_policy(SET CMP0054 NEW)
endif()
# In CMake 3.12 and above the find_package(<PackageName>) command now searches prefixes specified by the
# <PackageName>_ROOT CMake variable and the <PackageName>_ROOT environment variable. Package roots are maintained as a
# stack so nested calls to all find_* commands inside find modules also search the roots as prefixes. This policy
# provides compatibility with projects that have not been updated to avoid using <PackageName>_ROOT variables for other
# purposes. The OLD behavior for this policy is to ignore <PackageName>_ROOT variables. The NEW behavior for this
# policy is to use <PackageName>_ROOT variables.
#
# Behavior is set to "NEW" because ROSE matrix testing, Livermore's LC RZ/CZ resources, Spack, and RMC/Spock seldom
# install ROSE software dependencies in standard locations because they need to support the ability to install multiple
# versions and configurations of the dependencies.
if(POLICY_CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()
# In CMake 3.27 and above the find_package(<PackageName>) command also searches for upper-case <PACKAGENAME>_ROOT
# variables in addition to the properly-cased <PackageName>_ROOT variables. This allows find_package(Boost) to honor
# the BOOST_ROOT variable (which ROSE sets from the BOOST_HOME environment variable) and find_package(LLVM) to honor
# the LLVM_ROOT variable. The OLD behavior ignores the upper-case variants for compatibility with projects that used
# them for other purposes. The NEW behavior searches both the upper-case and properly-cased variants.
#
# Behavior is set to "NEW" because ROSE explicitly sets BOOST_ROOT and LLVM_ROOT with the intention that
# find_package() should use them to locate these dependencies.
if(POLICY CMP0144)
cmake_policy(SET CMP0144 NEW)
endif()
# This controls whether the "cmake" command is verbose. It has nothing to do with the verbosity the resulting Makefiles.
option(VERBOSE "CMake should be verbose" FALSE)
if(VERBOSE)
set(QUIET FALSE)
set(CMAKE_VERBOSE_MAKEFILE TRUE)
else()
set(QUIET TRUE)
set(CMAKE_VERBOSE_MAKEFILE FALSE)
endif()
option(BUILD_SHARED_LIBS "Build all libraries shared" FALSE)
option(use-lib64-paths "Should ROSE be installed in lib64 paths? (Some Linux distributes expect this)" OFF)
if(use-lib64-paths)
set(ROSE_LIB_DIR_NAME "lib64")
else()
set(ROSE_LIB_DIR_NAME "lib")
endif()
if(WIN32)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-DBOOST_ALL_NO_LIB=1)
endif()
# FIXME: Why do we have to have a copy of some standard built-in modules inside rose?
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" "${CMAKE_SOURCE_DIR}/cmake/modules" ${CMAKE_MODULE_PATH})
# ROSE source and build (binary) directory hierarchies
set(ROSE_TOP_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(ROSE_TOP_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
########################################################################################################################
# ROSE version information
########################################################################################################################
# The ROSE version string was already read from ROSE_VERSION file before the project() command.
# Now read the numerical version from SCM_DATE file.
# All distributions of ROSE also have a config/SCM_DATE file with a numerical version that's updated during the ROSE release process.
set(ROSE_SCM_DATE_FILE "${PROJECT_SOURCE_DIR}/config/SCM_DATE")
if(NOT EXISTS "${ROSE_SCM_DATE_FILE}")
message(FATAL_ERROR "ROSE SCM Date file not found: ${ROSE_SCM_DATE_FILE}")
endif()
file(STRINGS ${ROSE_SCM_VERSION_FILE} ROSE_SCM_VERSION_ID LIMIT_COUNT 1)
file(READ ${ROSE_SCM_DATE_FILE} ROSE_VERSION)
# Fix trailing whitespace
string(STRIP "${ROSE_VERSION}" ROSE_VERSION)
# Print Results
message(STATUS "The ROSE version integer is ${ROSE_VERSION}")
message(STATUS "The ROSE version string is ${ROSE_PACKAGE_VERSION}")
# Parse version into components for package configuration
# Note: PROJECT_VERSION_MAJOR, PROJECT_VERSION_MINOR, etc. are also set by project() command
string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+)" _version_match "${ROSE_PACKAGE_VERSION}")
set(ROSE_VERSION_MAJOR "${CMAKE_MATCH_1}")
set(ROSE_VERSION_MINOR "${CMAKE_MATCH_2}")
set(ROSE_VERSION_PATCH "${CMAKE_MATCH_3}")
set(ROSE_VERSION_BUILD "${CMAKE_MATCH_4}")
# Generate version file for package configuration
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/cmake/RoseConfigVersion.cmake
VERSION ${ROSE_PACKAGE_VERSION}
COMPATIBILITY SameMajorVersion
)
########################################################################################################################
# Initialize the leading part of the Rose::initialize token
########################################################################################################################
# Configuration synopsis used by Rose::initialize. The ROSE_CONFIG_TOKEN is #define'd as a string in rose_config.h and
# ultimately rosePublicConfig.h and the string is a synopsis of some important configuration details. This string is
# passed by user code to the Rose::initialize function which compares it against the same macro compiled into the ROSE
# library. If their contents differ it means that the ROSE header files being used by the user are not the same as the
# ROSE header files that were used to compile librose being linked by the user and bad things will probably happen.
#
# The CMake ROSE_CONFIG_TOKEN variable is the string that becomes the eventual value of the ROSE_CONFIG_TOKEN C
# preprocessor macro. We initialize it here, but other parts of the CMake file might augment its value with additional
# information (e.g., adding the boost version number).
set(ROSE_CONFIG_TOKEN "rose-${ROSE_SCM_VERSION_ID}")
########################################################################################################################
# Boost libraries
########################################################################################################################
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS
"If you get a whole bunch of warnings saying 'New Boost version may have incorrect or missing dependencies and "
"imported targets' it is probably because you're using a Boost version that was released after your CMake version. "
"See [https://github.com/Kitware/CMake/commits/master/Modules/FindBoost.cmake] to see latest supported version and "
"[https://github.com/Microsoft/vcpkg/issues/2459] for a description of the problem. Note that CMake versions "
"3.11.0 through 3.13.2 and possibly later) cannot be compiled (syntax errors) with a GNU C++ compiler that's "
"configured to use a non-default language standard (e.g., C++11 with GCC-5.4 whose default is GNU++03).")
endif()
set(Boost_USE_STATIC_LIBS FALSE)
set(Boost_DEBUG ${VERBOSE})
option(BOOST_USE_MULTITHREADED "Should Boost multithreaded libraries be used?" OFF) # puts -pthread on link and compile
# Honor BOOST_HOME environment variable
if(DEFINED ENV{BOOST_HOME})
set(BOOST_ROOT "$ENV{BOOST_HOME}")
endif()
# Boost 1.47 is no longer supported by ROSE, but is what's installed on Jenkins' CMake test machine. This should
# be changed to the actual minimum supported version once Pei-Hung upgrades the machine. [Matzke 2019-01-21]
#
# First look for the Boost libraries that are required in order to compile ROSE, then additionally look for any optional
# libraries that are useful to ROSE but not required. From a user: "The find_package() change is required for boost
# 1.70 or above on any system when using a recent enough version of cmake. Without it, serialization support will not
# be used. Before boost 1.70, the findBoost() in cmake is used directly, and it will look for boost components that are
# not in the find_package clause. Since 1.70, cmake will load the findBoost() provided by the boost package itself.
# Unfortunately, that findBoost() will only check for components in the find_package() clause. This means that
# serialization is considered not to exist, even if it is there. My change calls find_package again without the
# REQUIRED clause after the first one has succeeded. That way the first clause checks for requires components, and the
# second can check again including optional components. If the version of cmake is high enough you can use an
# OPTIONAL_COMPONENTS clause instead, but that wasn't introduced until 3.11."
find_package(Boost REQUIRED COMPONENTS chrono date_time filesystem iostreams program_options random regex system wave thread serialization)
if(WIN32)
set(BOOST_LIBRARYDIR ${Boost_LIBRARY_DIRS})
set(BOOST_INCLUDEDIR ${Boost_INCLUDE_DIRS}/)
endif()
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
# Defines for rose_config.h
set(ROSE_CONFIG_TOKEN "${ROSE_CONFIG_TOKEN} boost-${Boost_VERSION}")
# Boost version-specific macros
if(Boost_VERSION VERSION_GREATER_EQUAL "1.78.0")
# Resolves compiler warning about Boost placeholders (_1, _2, etc.) in the global namespace, which is deprecate
# Boost now recommends including the <boost/bind/bind.hpp> header and using the boost::placeholders namespace instead
# To resolve this warning, we can use the line of CMake below or Update the code to use the recommended namespace
# To update the code, Modify Sawyer codes to include <boost/bind/bind.hpp> and use boost::placeholders
add_definitions(-DBOOST_BIND_GLOBAL_PLACEHOLDERS)
endif()
# Boost compiler-specific flags
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# Do not supress boost warnings in debug mode
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
# Compiler specific commands, not to be used with MSVC
add_compile_options(-Wno-switch-default) # supress warnings coming from the boost library code itself
add_compile_options(-Wno-deprecated) # supress warnings coming from the boost library code itself
endif()
endif()
# If the boost is compiled with multi-thread support then we must add "-pthread" to all compile and link commands, or
# whatever is appropriate for the system. With GCC it is not sufficient to just add "-lpthread" to the link
# commands--the "-pthread" switch MUST be added to the compile commands as well.
# FIXME: Do we want to use our option(BOOST_USE_MULTITHREADED) or always do this?
if(Boost_THREAD_FOUND)
set(Threads_FIND_QUIETLY ${QUIET})
find_package(Threads REQUIRED)
if(Threads_FOUND)
message(STATUS "Threads found: CMAKE_THREAD_LIBS_INIT=${CMAKE_THREAD_LIBS_INIT}")
endif()
# FIXME: This breaks things
# if(Threads_FOUND)
# if(BOOST_USE_MULTITHREADED) # Something inside this conditional gets OpenCL
# message(WARNING "Setting _REENTRANT")
# set(_REENTRANT 1)
# endif()
# NOTE: -pthread is now added via Threads::Threads target in src/CMakeLists.txt (PUBLIC dependency)
# This ensures proper propagation to external projects via RoseConfig.cmake
add_definitions(-pthread) # Keep for internal ROSE builds (non-target-based code)
set(ROSE_CONFIG_TOKEN "${ROSE_CONFIG_TOKEN} pthread")
endif()
# Boost misconfiguration is often the cause of many issues
message(STATUS "Boost_VERSION: ${Boost_VERSION}" ) # Report Boost version in all modes
message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}") # Report Boost -I in all modes
message(STATUS "Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}") # Report Boost -L in all modes
# Directories where Rose executable, rose library, and rose headers will be installed
set(INCLUDE_INSTALL_DIR "include/rose")
set(BIN_INSTALL_DIR "bin")
set(LIB_INSTALL_DIR "${ROSE_LIB_DIR_NAME}")
set(INSTALL_TARGETS_DEFAULT_ARGS
RUNTIME DESTINATION "${BIN_INSTALL_DIR}"
LIBRARY DESTINATION "${LIB_INSTALL_DIR}"
ARCHIVE DESTINATION "${LIB_INSTALL_DIR}"
COMPONENT Devel)
# A new definition to tweak code for cmake
set(USE_CMAKE ON CACHE BOOL "Define if using CMake")
# ROSE configuration variables for Boost
set(HAVE_BOOST ${Boost_FOUND})
set(HAVE_BOOST_SERIALIZATION_LIB ${Boost_SERIALIZATION_FOUND})
set(HAVE_BOOST_DATE_TIME ${Boost_DATE_TIME_FOUND})
set(HAVE_BOOST_FILESYSTEM ${Boost_FILESYSTEM_FOUND})
set(HAVE_BOOST_PROGRAM_OPTIONS ${Boost_PROGRAM_OPTIONS_FOUND})
set(HAVE_BOOST_REGEX ${Boost_REGEX_FOUND})
set(HAVE_BOOST_SYSTEM ${Boost_SYSTEM_FOUND})
set(HAVE_BOOST_THREAD ${Boost_THREAD_FOUND})
set(HAVE_BOOST_WAVE ${Boost_WAVE_FOUND})
set(USE_ROSE_BOOST_WAVE_SUPPORT ${Boost_WAVE_FOUND})
########################################################################################################################
# Operating system information
########################################################################################################################
# Test whether the host OS (the OS compiling ROSE) is Red Hat Enterprise Linux, and if so, set ROSE_HOST_OS_IS_RHEL to
#the RHEL major version number.
set(ROSE_HOST_OS_IS_RHEL "")
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
execute_process(
COMMAND bash -c ". /etc/os-release && echo -n $ID"
OUTPUT_VARIABLE ROSE_HOST_OS_ID)
if ("${ROSE_HOST_OS_ID}" MATCHES "rhel")
execute_process(
COMMAND bash -c ". /etc/os-release && echo -n \${VERSION_ID%%.*}"
OUTPUT_VARIABLE ROSE_HOST_OS_VERSION_MAJOR)
set(ROSE_HOST_OS_IS_RHEL "${ROSE_HOST_OS_VERSION_MAJOR}")
endif()
endif()
if (ROSE_HOST_OS_IS_RHEL EQUAL 8 AND NOT DEFINED ROSE_ENABLE_BOOST_SERIALIZATION)
message(WARNING "Boost serialization takes a long time to assemble on RHEL8, disable using -DROSE_ENABLE_BOOST_SERIALIZATION=OFF (mute using =ON)")
endif()
option(ROSE_ENABLE_BOOST_SERIALIZATION "Enable Boost serialization" ON)
########################################################################################################################
# Compiler toolchain features
########################################################################################################################
if(MSVC)
set(CMAKE_BUILD_TYPE Release)
# Compiler flags
# /TP to indicate files are C++
# / CLR common intermediate language
# /GL whole program optimization
# /O1 optimization for small files
# /Ob0 disable inline expansion
# /MP multiple processors compilation
# /0s small files
# /wd4716 to turn no return to a warning and not an error
# /w -- suppresses all compiler warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /TP /MP /O1 /Os /GR /EHsc /wd4541 /wd4716 /bigobj /w")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4541 ")
# Linker flags
# /IGNORE:4217 - suppress "symbol 'A' defined in 'B' is imported by 'C' in function 'D'"
# /IGNORE:4286 - suppress "symbol 'A' defined in 'B' is imported by 'C'
set(WINDOWS_EXTRA_LINKER_FLAGS "/INCREMENTAL:NO /IGNORE:4217,4286")
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG " ${CMAKE_SHARED_LINKER_FLAGS_DEBUG} ${WINDOWS_EXTRA_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE " ${CMAKE_SHARED_LINKER_FLAGS_RELEASE} ${WINDOWS_EXTRA_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS_DEBUG " ${CMAKE_MODULE_LINKER_FLAGS_DEBUG} ${WINDOWS_EXTRA_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS_RELEASE " ${CMAKE_MODULE_LINKER_FLAGS_RELEASE} ${WINDOWS_EXTRA_LINKER_FLAGS}")
set(CMAKE_LINKER_FLAGS " ${CMAKE_LINKER_FLAGS} ${WINDOWS_EXTRA_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS " ${CMAKE_SHARED_LINKER_FLAGS} ${WINDOWS_EXTRA_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS " ${CMAKE_MODULE_LINKER_FLAGS} ${WINDOWS_EXTRA_LINKER_FLAGS}")
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} ${WINDOWS_EXTRA_LINKER_FLAGS}")
set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} ${WINDOWS_EXTRA_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${WINDOWS_EXTRA_LINKER_FLAGS}")
else()
if(CMAKE_BUILD_TYPE STREQUAL "Release")
add_compile_options(-w)
endif()
# Ensure C++11 ABI compatibility
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=1")
endif()
if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=1")
endif()
endif()
# Set ROSE_SHLIBPATH_VAR. For Visual Studio, this is PATH. Otherwise, it is just LD_LIBRARY_PATH.
if(MSVC)
set(ROSE_SHLIBPATH_VAR "PATH")
add_definitions("-D__STDC_LIMIT_MACROS")
else()
set(ROSE_SHLIBPATH_VAR "LD_LIBRARY_PATH")
endif()
########################################################################################################################
# Analyzable languages supported by ROSE
########################################################################################################################
# NOTE: We are migrating from hyphenated option names (ENABLE-C) to underscore names (ENABLE_C)
# to follow CMake best practices. Both forms work during the transition period, but hyphenated
# names will trigger deprecation warnings and will be removed in a future release.
# Binary analysis
option(ENABLE_BINARY_ANALYSIS "Enable binary analysis" OFF)
if(DEFINED CACHE{ENABLE-BINARY-ANALYSIS})
message(DEPRECATION "ENABLE-BINARY-ANALYSIS is deprecated. Use ENABLE_BINARY_ANALYSIS instead. Example: cmake -DENABLE_BINARY_ANALYSIS=${ENABLE-BINARY-ANALYSIS} ...")
set(ENABLE_BINARY_ANALYSIS ${ENABLE-BINARY-ANALYSIS} CACHE BOOL "Enable binary analysis" FORCE)
endif()
if(ENABLE_BINARY_ANALYSIS)
set(ROSE_BUILD_BINARY_ANALYSIS_SUPPORT 1)
endif()
# C/C++
option(ENABLE_C "Enable C/C++ analysis" OFF)
if(DEFINED CACHE{ENABLE-C})
message(DEPRECATION "ENABLE-C is deprecated. Use ENABLE_C instead. Example: cmake -DENABLE_C=${ENABLE-C} ...")
set(ENABLE_C ${ENABLE-C} CACHE BOOL "Enable C/C++ analysis" FORCE)
endif()
if(ENABLE_C)
set(ROSE_BUILD_CXX_LANGUAGE_SUPPORT 1)
set(ROSE_BUILD_C_LANGUAGE_SUPPORT 1)
endif()
# CUDA
option(ENABLE_CUDA "Enable CUDA analysis" OFF) # OFF because lack of CUDA is not handled properly
if(DEFINED CACHE{ENABLE-CUDA})
message(DEPRECATION "ENABLE-CUDA is deprecated. Use ENABLE_CUDA instead. Example: cmake -DENABLE_CUDA=${ENABLE-CUDA} ...")
set(ENABLE_CUDA ${ENABLE-CUDA} CACHE BOOL "Enable CUDA analysis" FORCE)
endif()
if(ENABLE_CUDA)
if(APPLE)
message(FATAL_ERROR "CUDA analysis (ENABLE_CUDA) is not supported on macOS")
endif()
find_package(CUDA REQUIRED)
set(ROSE_BUILD_CUDA_LANGUAGE_SUPPORT 1)
endif()
# Java
option(ENABLE_JAVA "Enable Java analysis" OFF)
if(DEFINED CACHE{ENABLE-JAVA})
message(DEPRECATION "ENABLE-JAVA is deprecated. Use ENABLE_JAVA instead. Example: cmake -DENABLE_JAVA=${ENABLE-JAVA} ...")
set(ENABLE_JAVA ${ENABLE-JAVA} CACHE BOOL "Enable Java analysis" FORCE)
endif()
if(ENABLE_JAVA)
message(STATUS "Looking for JAVA ...")
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR VERBOSE)
message(STATUS "JAVA_ROOT is: ${JAVA_ROOT}")
endif()
find_package(Java COMPONENTS Development)
# Set JAVA_RUNTIME for rose_config.h (defines JAVA_JVM_PATH and enables USE_ROSE_JAVA_SUPPORT)
set(JAVA_RUNTIME "${Java_JAVA_EXECUTABLE}")
find_program(GCJ gcj)
find_program(GCJH gcjh)
find_package(JNI)
set(ROSE_BUILD_JAVA_LANGUAGE_SUPPORT 1)
set(USE_ROSE_INTERNAL_JAVA_SUPPORT 1)
get_filename_component(BACKEND_JAVA_COMPILER ${Java_JAVAC_EXECUTABLE} NAME)
endif()
# OpenCL
option(ENABLE_OPENCL "Enable OpenCL analysis" OFF)
if(DEFINED CACHE{ENABLE-OPENCL})
message(DEPRECATION "ENABLE-OPENCL is deprecated. Use ENABLE_OPENCL instead. Example: cmake -DENABLE_OPENCL=${ENABLE-OPENCL} ...")
set(ENABLE_OPENCL ${ENABLE-OPENCL} CACHE BOOL "Enable OpenCL analysis" FORCE)
endif()
if(ENABLE_OPENCL)
find_package(OpenCL)
set(ROSE_BUILD_OPENCL_LANGUAGE_SUPPORT 1)
find_path(with-opencl-inc NAMES cl.h DOC "For OpenCL runtime library")
find_library(with-opencl-lib OpenCL DOC "OpenCL library for runtime examples")
endif()
# Fortran
option(ENABLE_FORTRAN "Enable Fortran analysis." OFF) # OFF because lack of OFP is not handled properly
if(DEFINED CACHE{ENABLE-FORTRAN})
message(DEPRECATION "ENABLE-FORTRAN is deprecated. Use ENABLE_FORTRAN instead. Example: cmake -DENABLE_FORTRAN=${ENABLE-FORTRAN} ...")
set(ENABLE_FORTRAN ${ENABLE-FORTRAN} CACHE BOOL "Enable Fortran analysis." FORCE)
endif()
if(ENABLE_FORTRAN)
if(NOT ENABLE_JAVA)
message(FATAL_ERROR "Fortran analysis also requires Java analysis. Either
turn on ENABLE_JAVA, or turn off ENABLE_FORTRAN")
endif()
set(ROSE_BUILD_FORTRAN_LANGUAGE_SUPPORT 1)
enable_language(Fortran)
# check if gfortran (gnu) was found
if(CMAKE_COMPILER_IS_GNUG77 OR CMAKE_Fortran_COMPILER MATCHES "gfortran")
set(USE_GFORTRAN_IN_ROSE 1)
set(BACKEND_FORTRAN_IS_GNU_COMPILER 1)
endif()
# query fortran compiler version
execute_process(COMMAND ${CMAKE_Fortran_COMPILER} --version
OUTPUT_VARIABLE Fortran_COMPILER_VERSION_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX MATCH "([0-9]+\\.[0-9]+\\.[0-9]+)"
Fortran_COMPILER_VERSION "${Fortran_COMPILER_VERSION_OUTPUT}")
if(Fortran_COMPILER_VERSION)
message(STATUS "Fortran compiler version detected: ${Fortran_COMPILER_VERSION}")
else()
message(WARNING "Failed to detect Fortran compiler version")
endif()
# This is a cache string var assuming we sometimes may expect user to set
set(enable-ofp-version "20200819-JDK8" CACHE STRING "version number for OFP")
# Set rose_config.h macros
set(ROSE_OFP_VERSION_NUMBER "${enable-ofp-version}")
# This is trying to set an environment variable -- is this what we want to do?
set($ENV{CLASSPATH} ${CMAKE_SOURCE_DIR}/src/3rdPartyLibraries/antlr-jars/antlr-3.5.2-complete.jar::${CMAKE_SOURCE_DIR}/rc/3rdPartyLibraries/fortran-parser/OpenFortranParser-${enable-ofp-version}.jar)
endif()
# PHP
option(ENABLE_PHP "Enable PHP analysis" OFF)
if(DEFINED CACHE{ENABLE-PHP})
message(DEPRECATION "ENABLE-PHP is deprecated. Use ENABLE_PHP instead. Example: cmake -DENABLE_PHP=${ENABLE-PHP} ...")
set(ENABLE_PHP ${ENABLE-PHP} CACHE BOOL "Enable PHP analysis" FORCE)
endif()
if(ENABLE_PHP)
set(ROSE_BUILD_PHP_LANGUAGE_SUPPORT 1)
find_path(with-php php DOC "Specify the prefix where PHP (and phc) is installed")
endif()
# Python
option(ENABLE_PYTHON "Enable Python analysis" OFF)
if(DEFINED CACHE{ENABLE-PYTHON})
message(DEPRECATION "ENABLE-PYTHON is deprecated. Use ENABLE_PYTHON instead. Example: cmake -DENABLE_PYTHON=${ENABLE-PYTHON} ...")
set(ENABLE_PYTHON ${ENABLE-PYTHON} CACHE BOOL "Enable Python analysis" FORCE)
endif()
if(ENABLE_PYTHON)
set(ROSE_BUILD_PYTHON_LANGUAGE_SUPPORT 1)
find_package(PythonLibs REQUIRED)
option(WITH-PYTHON "Build code that requires a Python interpreter" ON)
if(WITH-PYTHON)
find_package(PythonInterp)
endif()
endif()
# Ada
option(ENABLE_ADA "Enable Ada analysis" OFF)
if(DEFINED CACHE{ENABLE-ADA})
message(DEPRECATION "ENABLE-ADA is deprecated. Use ENABLE_ADA instead. Example: cmake -DENABLE_ADA=${ENABLE-ADA} ...")
set(ENABLE_ADA ${ENABLE-ADA} CACHE BOOL "Enable Ada analysis" FORCE)
endif()
if(ENABLE_ADA)
set(ROSE_EXPERIMENTAL_ADA_ROSE_CONNECTION_GNAT_HOME "$ENV{GNAT_HOME}")
set(ROSE_EXPERIMENTAL_ADA_ROSE_CONNECTION ON)
endif()
# Libadalang
# I think this name is terrible, considering the autotools equivalent is --enable-experimental_libadalang_frontend, but it follows the established pattern
option(ENABLE_LIBADALANG "Enable experimental libadalang frontend" OFF)
if(DEFINED CACHE{ENABLE-LIBADALANG})
message(DEPRECATION "ENABLE-LIBADALANG is deprecated. Use ENABLE_LIBADALANG instead. Example: cmake -DENABLE_LIBADALANG=${ENABLE-LIBADALANG} ...")
set(ENABLE_LIBADALANG ${ENABLE-LIBADALANG} CACHE BOOL "Enable experimental libadalang frontend" FORCE)
endif()
if(ENABLE_LIBADALANG)
set(ROSE_EXPERIMENTAL_LIBADALANG_ROSE_CONNECTION_GNAT_HOME "$ENV{GNAT_HOME}")
set(ROSE_EXPERIMENTAL_LIBADALANG_ROSE_CONNECTION ON)
endif()
if(ENABLE_ADA OR ENABLE_LIBADALANG)
message(STATUS "Checking the environment variables GNAT_HOME and BOOST_HOME have been set.")
# Force user to define GNAT_HOME
if(NOT DEFINED ENV{GNAT_HOME})
message(FATAL_ERROR "Ada support requires the environment variable GNAT_HOME to be set to an installed GNAT")
endif()
# Force user to define GNAT_HOME as a directory that exists on the system or within the container
if(NOT IS_DIRECTORY "$ENV{GNAT_HOME}")
message(WARNING "GNAT_HOME: $ENV{GNAT_HOME}")
message(FATAL_ERROR "GNAT_HOME does not exist on this system")
endif()
# Force user to define BOOST_HOME
if(NOT DEFINED ENV{BOOST_HOME})
message(FATAL_ERROR "Ada support requires the environment variable BOOST_HOME to be set to an installed boost")
endif()
# Force user to define BOOST_HOME as a directory that exists on the system or within the container
if(NOT IS_DIRECTORY "$ENV{BOOST_HOME}")
message(WARNING "BOOST_HOME: $ENV{BOOST_HOME}")
message(FATAL_ERROR "BOOST_HOME does not exist on this system")
endif()
# Check PATH and LD_LIBRARY_PATH
get_filename_component(USER_PATH $ENV{PATH} ABSOLUTE) # retrieve USER_PATH
get_filename_component(USER_LD_PATH $ENV{LD_LIBRARY_PATH} ABSOLUTE) # retrieve USER_LD_PATH
# Ensure user has GNAT_HOME/bin in their path
string(FIND "${USER_PATH}" "$ENV{GNAT_HOME}/bin" found_gnat_in_path)
if(found_gnat_in_path EQUAL -1)
message(WARNING "GNAT_HOME/bin was not found in users path: ${USER_PATH}")
else()
message(STATUS "Found $ENV{GNAT_HOME}/bin")
endif()
# Ensure user has GNAT_HOME/lib in their LD path
string(FIND "${USER_LD_PATH}" "$ENV{GNAT_HOME}/lib" found_gnat_in_ld_path)
if(found_gnat_in_ld_path EQUAL -1)
message(WARNING "{GNAT_HOME}/lib was not found in users LD_LIBRARY_PATH: ${USER_LD_PATH}")
else()
message(STATUS "Found $ENV{GNAT_HOME}/lib")
endif()
# Ensure user has GNAT_HOME/lib in their LD path
string(FIND "${USER_LD_PATH}" "${BOOST_HOME}/lib" found_boost_in_ld_path)
if(found_boost_in_ld_path EQUAL -1)
message(WARNING "BOOST_HOME not found in users LD_LIBRARY_PATH: ${USER_LD_PATH}")
else()
message(STATUS "Found $ENV{BOOST_HOME}/lib")
endif()
set(BACKEND_ADA_COMPILER "gnat" CACHE STRING "Specify backend Ada compiler, default is gnat")
set(BACKEND_ADA_COMPILER_NAME_WITH_PATH ${BACKEND_ADA_COMPILER})
endif()
# Jovial
option(ENABLE_JOVIAL "Enable Jovial analysis" OFF)
if(DEFINED CACHE{ENABLE-JOVIAL})
message(DEPRECATION "ENABLE-JOVIAL is deprecated. Use ENABLE_JOVIAL instead. Example: cmake -DENABLE_JOVIAL=${ENABLE-JOVIAL} ...")
set(ENABLE_JOVIAL ${ENABLE-JOVIAL} CACHE BOOL "Enable Jovial analysis" FORCE)
endif()
if(ENABLE_JOVIAL)
set(ROSE_BUILD_JOVIAL_LANGUAGE_SUPPORT 1)
endif()
# Null analysis (in order to configure ROSE with no actual analysis since at least one is required)
option(ENABLE_NULL "Enable null analysis (empty analysis that does nothing)" OFF)
if(ENABLE_NULL)
set(ROSE_BUILD_NULL_ANALYSIS 1)
endif()
# Check that at least one analysis is enabled
if(NOT ENABLE_BINARY_ANALYSIS AND NOT ENABLE_C AND NOT ENABLE_CUDA AND NOT ENABLE_JAVA AND
NOT ENABLE_OPENCL AND NOT ENABLE_FORTRAN AND NOT ENABLE_PHP AND NOT ENABLE_PYTHON AND
NOT ENABLE_ADA AND NOT ENABLE_JOVIAL AND NOT ENABLE_LIBADALANG AND NOT ENABLE_NULL)
message(FATAL_ERROR
"ROSE must be configured with at least one analysis feature enabled. The following "
"are the most common features, but see the ROSE documentation for the extensive, complete "
"list."
"\n"
" C/C++ Analysis:\n"
" cmake -DENABLE_C=ON ...\n"
" Enables analysis of C and C++ code using the EDG frontend. Requires EDG and Boost.\n"
" Best supported on RHEL with GCC. Not portable to all platforms.\n"
" Binary Analysis:\n"
" cmake -DENABLE_BINARY_ANALYSIS=ON ...\n"
" Enables analysis of binary executables and object files. Requires only Boost.\n"
" Portable and well-supported on RHEL and Debian-based systems.\n"
" Fortran Analysis:\n"
" cmake -DENABLE_FORTRAN=ON -DENABLE_JAVA=ON ...\n"
" Enables analysis of Fortran code. Requires Java analysis to be enabled.\n"
" Ada Analysis:\n"
" cmake -DENABLE_ADA=ON ...\n"
" Enables analysis of Ada code. Experimental feature.\n"
" Java Analysis:\n"
" cmake -DENABLE_JAVA=ON ...\n"
" Enables analysis of Java code.\n"
" Null Analysis (no actual analysis):\n"
" cmake -DENABLE_NULL=ON ...\n"
" Empty analysis in order to configure ROSE without any true analysis capabilities."
)
endif()
# The C preprocessor is enabled automatically if C, C++, or Fortran is enabled
if(ENABLE_C OR ENABLE_FORTRAN)
set(ENABLE_CPP ON)
set(ROSE_BUILD_CPP_LANGUAGE_SUPPORT 1)
endif()
########################################################################################################################
# EDG (Edison Design Group) frontend C/C++ compiler
########################################################################################################################
option(EDG_COMPILE "Compile EDG source code if available" ON)
# Clang or EDG is required for frontend
option(ENABLE_CLANG_FRONTEND "Enable Clang frontend" OFF)
if(DEFINED CACHE{ENABLE-CLANG-FRONTEND})
message(DEPRECATION "ENABLE-CLANG-FRONTEND is deprecated. Use ENABLE_CLANG_FRONTEND instead. Example: cmake -DENABLE_CLANG_FRONTEND=${ENABLE-CLANG-FRONTEND} ...")
set(ENABLE_CLANG_FRONTEND ${ENABLE-CLANG-FRONTEND} CACHE BOOL "Enable Clang frontend" FORCE)
endif()
if(ENABLE_CLANG_FRONTEND)
# Define macro which is used by source code
set(ROSE_USE_CLANG_FRONTEND 1)
set(EDG_COMPILE OFF)
# Honor LLVM_HOME environment variable if it exists
if(DEFINED ENV{LLVM_HOME})
set(LLVM_ROOT "$ENV{LLVM_HOME}")
set(Clang_ROOT "$ENV{LLVM_HOME}")
endif()
find_package(LLVM REQUIRED)
find_package(Clang REQUIRED)
# find_package may stomp on CLANG_VERSION_MAJOR, so it must be after. At the moment, the package
# sets CLANG_VERSION_MAJOR to 0, but they may correct it in the future, which would make the
# script unnecessary
# also, assuming that you must use clang to compile the clang frontend,
# we could perhaps use BACKEND_CXX_COMPILER_MAJOR_VERSION_NUMBER instead of this script
execute_process(COMMAND "${CMAKE_SOURCE_DIR}/config/getClangMajorVersionNumber.sh" OUTPUT_VARIABLE CLANG_VERSION_MAJOR)
endif()
# Default EDG version
set(EDG_VERSION "6.5" CACHE STRING "major.minor version number for EDG (e.g. 5.0).")
# Check whether we have the EDG source code. Even if we have it, we might pretend (for testing) that we don't.
if(EXISTS "${PROJECT_SOURCE_DIR}/src/frontend/CxxFrontend/EDG/CMakeLists.txt")
if(EDG_COMPILE)
set(have_EDG_source TRUE)
else()
set(have_EDG_source FALSE)
endif()
else()
set(have_EDG_source FALSE)
set(EDG_COMPILE FALSE)
endif()
# Check if we should download the EDG binary tarball. We only need to download it if we're not compiling the
# EDG source code and ROSE is configured to analyze C (and C++).
if(NOT have_EDG_source AND NOT ENABLE_CLANG_FRONTEND)
set(BINARY_EDG 0)
if(ENABLE_C)
set(BINARY_EDG 1)
if(NOT WIN32)
message(FATAL_ERROR "EDG binary download not yet supported, please use EDG git submodule if in ROSE team, otherwise use autotools")
message(STATUS "EDG - downloading EDG-${EDG_VERSION} binary tar file")
if(EXISTS "${PROJECT_BINARY_DIR}/src/frontend/CxxFrontend/EDG.tar.gz")
execute_process(COMMAND "tar" "-zxvf" "-C" "${PROJECT_BINARY_DIR}/src/frontend/CxxFrontend/EDG")
else()
# no need to display this message after the file has been downloaded
if(NOT EXISTS "${PROJECT_BINARY_DIR}/src/frontend/CxxFrontend/EDG/.libs")
message(WARNING "At build time, CMake will attempt to download a required library tarball.\n"
"Please note that EDG binary tarballs are available for only certain configurations.")
endif()
include(${PROJECT_SOURCE_DIR}/cmake/DownloadEDG.cmake)
endif()
endif()
endif()
endif()
set(edg_lib EDG) # the compiled library, the downloaded library, or the dummy library
if(have_EDG_source)
message(STATUS "EDG - will compile EDG-${EDG_VERSION} source code")
elseif(BINARY_EDG)
message(STATUS "EDG - will use EDG-${EDG_VERSION} binary release (download)")
else()
message(STATUS "EDG - not needed; using a nearly empty dummy library")
endif()
########################################################################################################################
# System features
########################################################################################################################
# A set of common features including endian, stdio.h, printf, size of long int, etc.
set(CMAKE_REQUIRED_QUIET ${QUIET})
include(ConfigureChecks)
set(CMAKE_REQUIRED_QUIET FALSE)
find_package(Perl)
########################################################################################################################
# Miscellaneous user-selectable features
########################################################################################################################
option(ENABLE_EXAMPLE_TRANSLATORS_DIRECTORY "Enable compilation and testing of exampleTranslators directory" OFF)
if(DEFINED CACHE{ENABLE-EXAMPLE-TRANSLATORS-DIRECTORY})
message(DEPRECATION "ENABLE-EXAMPLE-TRANSLATORS-DIRECTORY is deprecated. Use ENABLE_EXAMPLE_TRANSLATORS_DIRECTORY instead. Example: cmake -DENABLE_EXAMPLE_TRANSLATORS_DIRECTORY=${ENABLE-EXAMPLE-TRANSLATORS-DIRECTORY} ...")
set(ENABLE_EXAMPLE_TRANSLATORS_DIRECTORY ${ENABLE-EXAMPLE-TRANSLATORS-DIRECTORY} CACHE BOOL "Enable compilation and testing of exampleTranslators directory" FORCE)
endif()
# 1/8/25 we will most likely remove this enable-tests-directory option
option(ENABLE_TESTS_DIRECTORY "Enable compilation and testing of the ROSE/tests directory" OFF)
if(DEFINED CACHE{ENABLE-TESTS-DIRECTORY})
message(DEPRECATION "ENABLE-TESTS-DIRECTORY is deprecated. Use ENABLE_TESTS_DIRECTORY instead. Example: cmake -DENABLE_TESTS_DIRECTORY=${ENABLE-TESTS-DIRECTORY} ...")
set(ENABLE_TESTS_DIRECTORY ${ENABLE-TESTS-DIRECTORY} CACHE BOOL "Enable compilation and testing of the ROSE/tests directory" FORCE)
endif()
# 1/15/24 Turn on ctests until new CMake-Build-RHEL7.sh is merged
if(NOT ENABLE_TESTS_DIRECTORY AND EXISTS "${PROJECT_SOURCE_DIR}/tests/README.md")
set(ENABLE_TESTS_DIRECTORY ON CACHE BOOL "Enable compilation and testing of the ROSE/tests directory" FORCE)
endif()
option(ENABLE_TUTORIAL_DIRECTORY "Enable compilation and testing of the ROSE/tutorial directory" OFF)
if(DEFINED CACHE{ENABLE-TUTORIAL-DIRECTORY})
message(DEPRECATION "ENABLE-TUTORIAL-DIRECTORY is deprecated. Use ENABLE_TUTORIAL_DIRECTORY instead. Example: cmake -DENABLE_TUTORIAL_DIRECTORY=${ENABLE-TUTORIAL-DIRECTORY} ...")
set(ENABLE_TUTORIAL_DIRECTORY ${ENABLE-TUTORIAL-DIRECTORY} CACHE BOOL "Enable compilation and testing of the ROSE/tutorial directory" FORCE)
endif()
option(ENABLE_ADVANCED_WARNINGS "Support for an advanced uniform warning level for ROSE development" OFF)
if(DEFINED CACHE{ENABLE-ADVANCED-WARNINGS})
message(DEPRECATION "ENABLE-ADVANCED-WARNINGS is deprecated. Use ENABLE_ADVANCED_WARNINGS instead. Example: cmake -DENABLE_ADVANCED_WARNINGS=${ENABLE-ADVANCED-WARNINGS} ...")
set(ENABLE_ADVANCED_WARNINGS ${ENABLE-ADVANCED-WARNINGS} CACHE BOOL "Support for an advanced uniform warning level for ROSE development" FORCE)
endif()
if(ENABLE_ADVANCED_WARNINGS)
message(WARNING "Using an advanced uniform warning level for ROSE development")
set(ROSE_USE_UNIFORM_ADVANCED_WARNINGS_SUPPORT 1)
endif()
option(ENABLE_ASSEMBLY_SEMANTICS "Enable semantics-based analysis of assembly code" OFF)
if(DEFINED CACHE{ENABLE-ASSEMBLY-SEMANTICS})
message(DEPRECATION "ENABLE-ASSEMBLY-SEMANTICS is deprecated. Use ENABLE_ASSEMBLY_SEMANTICS instead. Example: cmake -DENABLE_ASSEMBLY_SEMANTICS=${ENABLE-ASSEMBLY-SEMANTICS} ...")
set(ENABLE_ASSEMBLY_SEMANTICS ${ENABLE-ASSEMBLY-SEMANTICS} CACHE BOOL "Enable semantics-based analysis of assembly code" FORCE)
endif()
option(ENABLE_CANDL "Support for ScopLib" OFF)
if(DEFINED CACHE{ENABLE-CANDL})
message(DEPRECATION "ENABLE-CANDL is deprecated. Use ENABLE_CANDL instead. Example: cmake -DENABLE_CANDL=${ENABLE-CANDL} ...")
set(ENABLE_CANDL ${ENABLE-CANDL} CACHE BOOL "Support for ScopLib" FORCE)
endif()
if(ENABLE_CANDL)
find_path(with-candl "include/candl.h"
DOC "Path to a valid Candl installation")
endif()
option(ENABLE_CLOOG "Support for Cloog" OFF)
if(DEFINED CACHE{ENABLE-CLOOG})
message(DEPRECATION "ENABLE-CLOOG is deprecated. Use ENABLE_CLOOG instead. Example: cmake -DENABLE_CLOOG=${ENABLE-CLOOG} ...")
set(ENABLE_CLOOG ${ENABLE-CLOOG} CACHE BOOL "Support for Cloog" FORCE)
endif()
if(ENABLE_CLOOG)
find_path(with-cloog "include/cloog.h"
DOC "Path to a valid Cloog installation")
endif()
option(ENABLE_COMPASS2 "build the Compass2 static analysis tool" OFF)
if(DEFINED CACHE{ENABLE-COMPASS2})
message(DEPRECATION "ENABLE-COMPASS2 is deprecated. Use ENABLE_COMPASS2 instead. Example: cmake -DENABLE_COMPASS2=${ENABLE-COMPASS2} ...")
set(ENABLE_COMPASS2 ${ENABLE-COMPASS2} CACHE BOOL "build the Compass2 static analysis tool" FORCE)
endif()
option(ENABLE_EDG_CUDA "Build EDG 4.0 with CUDA support" OFF)
if(DEFINED CACHE{ENABLE-EDG-CUDA})
message(DEPRECATION "ENABLE-EDG-CUDA is deprecated. Use ENABLE_EDG_CUDA instead. Example: cmake -DENABLE_EDG_CUDA=${ENABLE-EDG-CUDA} ...")
set(ENABLE_EDG_CUDA ${ENABLE-EDG-CUDA} CACHE BOOL "Build EDG 4.0 with CUDA support" FORCE)
endif()
option(ENABLE_EDG_OPENCL "Build EDG 4.0 with OpenCL support" OFF)
if(DEFINED CACHE{ENABLE-EDG-OPENCL})
message(DEPRECATION "ENABLE-EDG-OPENCL is deprecated. Use ENABLE_EDG_OPENCL instead. Example: cmake -DENABLE_EDG_OPENCL=${ENABLE-EDG-OPENCL} ...")
set(ENABLE_EDG_OPENCL ${ENABLE-EDG-OPENCL} CACHE BOOL "Build EDG 4.0 with OpenCL support" FORCE)
endif()
option(ENABLE_EDG_UNION_STRUCT_DEBUGGING "Should EDG Union/Struct debugging support be used?" OFF)
if(DEFINED CACHE{ENABLE-EDG_UNION_STRUCT_DEBUGGING})
message(DEPRECATION "ENABLE-EDG_UNION_STRUCT_DEBUGGING is deprecated. Use ENABLE_EDG_UNION_STRUCT_DEBUGGING instead. Example: cmake -DENABLE_EDG_UNION_STRUCT_DEBUGGING=${ENABLE-EDG_UNION_STRUCT_DEBUGGING} ...")
set(ENABLE_EDG_UNION_STRUCT_DEBUGGING ${ENABLE-EDG_UNION_STRUCT_DEBUGGING} CACHE BOOL "Should EDG Union/Struct debugging support be used?" FORCE)
endif()
if(ENABLE_EDG_UNION_STRUCT_DEBUGGING)
set(USE_ROSE_EDG_DEBUGGING_SUPPORT 1)
endif()
option(ENABLE_FLTK "Enable FLTK")
if(DEFINED CACHE{ENABLE-FLTK})
message(DEPRECATION "ENABLE-FLTK is deprecated. Use ENABLE_FLTK instead. Example: cmake -DENABLE_FLTK=${ENABLE-FLTK} ...")
set(ENABLE_FLTK ${ENABLE-FLTK} CACHE BOOL "Enable FLTK" FORCE)
endif()
if(ENABLE_FLTK)
find_package(FLTK REQUIRED)
endif()
option(ENABLE_GNU_EXTENSIONS "Enable internal support in ROSE for GNU language extensions" OFF)
if(DEFINED CACHE{ENABLE-GNU-EXTENSIONS})
message(DEPRECATION "ENABLE-GNU-EXTENSIONS is deprecated. Use ENABLE_GNU_EXTENSIONS instead. Example: cmake -DENABLE_GNU_EXTENSIONS=${ENABLE-GNU-EXTENSIONS} ...")
set(ENABLE_GNU_EXTENSIONS ${ENABLE-GNU-EXTENSIONS} CACHE BOOL "Enable internal support in ROSE for GNU language extensions" FORCE)
endif()
if(ENABLE_GNU_EXTENSIONS)
set(ROSE_SUPPORT_GNU_EXTENSIONS TRUE)
endif()
option(ENABLE_INTERNALFRONTENDDEVELOPMENT "Enable development mode to reduce files required to support work on
language frontends" OFF)
if(DEFINED CACHE{ENABLE-INTERNALFRONTENDDEVELOPMENT})
message(DEPRECATION "ENABLE-INTERNALFRONTENDDEVELOPMENT is deprecated. Use ENABLE_INTERNALFRONTENDDEVELOPMENT instead. Example: cmake -DENABLE_INTERNALFRONTENDDEVELOPMENT=${ENABLE-INTERNALFRONTENDDEVELOPMENT} ...")
set(ENABLE_INTERNALFRONTENDDEVELOPMENT ${ENABLE-INTERNALFRONTENDDEVELOPMENT} CACHE BOOL "Enable development mode to reduce files required to support work on language frontends" FORCE)
endif()
if(ENABLE_INTERNALFRONTENDDEVELOPMENT)
set(ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT 1)
endif()
option(ENABLE_MICROSOFT_EXTENSIONS "Enable internal support in ROSE for GNU language extensions" OFF)
if(DEFINED CACHE{ENABLE-MICROSOFT-EXTENSIONS})
message(DEPRECATION "ENABLE-MICROSOFT-EXTENSIONS is deprecated. Use ENABLE_MICROSOFT_EXTENSIONS instead. Example: cmake -DENABLE_MICROSOFT_EXTENSIONS=${ENABLE-MICROSOFT-EXTENSIONS} ...")
set(ENABLE_MICROSOFT_EXTENSIONS ${ENABLE-MICROSOFT-EXTENSIONS} CACHE BOOL "Enable internal support in ROSE for GNU language extensions" FORCE)
endif()
if(ENABLE_MICROSOFT_EXTENSIONS)
set(ROSE_SUPPORT_MICROSOFT_EXTENSIONS TRUE)
set(ROSE_USE_MICROSOFT_EXTENSIONS TRUE)
endif()
if(ENABLE_JOVIAL) # Find dependencies Aterm and Stratego
if(NOT DEFINED ATERM_ROOT) # Require location of aterm to be specified by the user at config time
message(FATAL_ERROR "Jovial Support Requires Aterm. Please define -DATERM_ROOT with the path of an Aterm installation on your system")
endif()
if(NOT EXISTS "${ATERM_ROOT}" OR NOT IS_DIRECTORY "${ATERM_ROOT}")
message(WARNING "${ATERM_ROOT} does not exist or is not a directory.")
message(FATAL_ERROR "Jovial Support Requires Aterm. Please set ATERM_ROOT to indicate the path of Aterm.")
endif()
include(FindAterm) # Find Aterm based on ATERM_ROOT
find_aterm()
# Error if we cannot find aterm
if(NOT USE_ROSE_ATERM_SUPPORT)
message(FATAL_ERROR "Support for experimental_jovial_frontend requires Aterm library support.\nPlease define ATERM_ROOT with location of Aterm install.")
else()
message(STATUS "Found aterm: ${ATERM_ROOT}")
endif()
if(NOT DEFINED STRATEGO_ROOT) # Require location of sglri executable
message(FATAL_ERROR "Jovial support requires the Stratego sglri executable. Please define -DSTRATEGO_ROOT with the path of a Stratego installation on your system")
endif()
include(FindSGLRI) # Find Stratego based on STRATEGO_ROOT
find_sglri()
endif()
option(ENABLE_PPL "Support for Parma Polyhedral Library" OFF)
if(DEFINED CACHE{ENABLE-PPL})
message(DEPRECATION "ENABLE-PPL is deprecated. Use ENABLE_PPL instead. Example: cmake -DENABLE_PPL=${ENABLE-PPL} ...")
set(ENABLE_PPL ${ENABLE-PPL} CACHE BOOL "Support for Parma Polyhedral Library" FORCE)
endif()
if(ENABLE_PPL)
find_path(with-ppl "include/ppl.h" DOC "Path to Parma Polyhedral Library installation")
find_library(libppl ppl)
endif()
option(ENABLE_PURIFY_API "Enable purify API in code" OFF)
if(DEFINED CACHE{ENABLE-PURIFY-API})
message(DEPRECATION "ENABLE-PURIFY-API is deprecated. Use ENABLE_PURIFY_API instead. Example: cmake -DENABLE_PURIFY_API=${ENABLE-PURIFY-API} ...")
set(ENABLE_PURIFY_API ${ENABLE-PURIFY-API} CACHE BOOL "Enable purify API in code" FORCE)
endif()
if(ENABLE_PURIFY_API)
set(USE_PURIFY_API 1)