-
Notifications
You must be signed in to change notification settings - Fork 116
/
CMakeLists.txt
191 lines (170 loc) · 7.26 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
cmake_minimum_required(VERSION 3.23)
project(Teaching-Software-Analysis
VERSION 1.0
DESCRIPTION "Teaching-Software-Analysis is an open course for learning software analysis"
HOMEPAGE_URL "https://github.com/SVF-tools/Teaching-Software-Analysis"
LANGUAGES C CXX
)
# Check if the LLVM_DIR environment variable is defined and set it accordingly
if (DEFINED LLVM_DIR)
set(ENV{LLVM_DIR} "${LLVM_DIR}")
elseif (DEFINED ENV{LLVM_DIR})
set(LLVM_DIR $ENV{LLVM_DIR})
else()
message(FATAL_ERROR "\
WARNING: The LLVM_DIR var was not set !\n\
Please set this to environment variable to point to the LLVM_DIR directory or set this variable to cmake configuration\n(e.g. on linux: export LLVM_DIR=/path/to/LLVM/dir) \n or \n \n(make the project via: cmake -DLLVM_DIR=your_path_to_LLVM) ")
endif()
# If the LLVM_DIR environment variable is set, configure CMake build flags and standards for C++ and C
if (DEFINED ENV{LLVM_DIR})
# Set the C++ standard to C++17 and configure compiler flags based on the build type
set(CMAKE_CXX_STANDARD 17)
if(CMAKE_BUILD_TYPE MATCHES "Debug")
set(CMAKE_CXX_FLAGS "-fPIC -std=gnu++17 -O0 -fno-rtti -Wno-deprecated")
else()
set(CMAKE_CXX_FLAGS "-fPIC -std=gnu++17 -O3 -fno-rtti -Wno-deprecated")
endif()
set(CMAKE_C_FLAGS "-fPIC")
# Check if compiler is GNU and version is less than 9
if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9)
# Link filesystem library globally
link_libraries(stdc++fs)
endif()
endif()
# Locate and use the LLVM package for the project
find_package(LLVM REQUIRED CONFIG)
message(STATUS "LLVM STATUS:
Version ${LLVM_VERSION}
Includes ${LLVM_INCLUDE_DIRS}
Libraries ${LLVM_LIBRARY_DIRS}
Build type ${LLVM_BUILD_TYPE}
Dynamic lib ${LLVM_LINK_LLVM_DYLIB}"
)
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
include(AddLLVM)
# Add LLVM definitions to the compile options
add_definitions(${LLVM_DEFINITIONS})
include_directories(${LLVM_INCLUDE_DIRS})
# Abort configuration if LLVM is not found
if(NOT "${LLVM_FOUND}")
message(FATAL_ERROR "Failed to find supported LLVM version")
endif()
# Add the LLVM include and library directories for all subsequent targets
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_LIBRARY_DIRS})
add_definitions(${LLVM_DEFINITIONS})
# Determine how to link with LLVM (dynamically with a single shared library or statically with multiple libraries)
if(LLVM_LINK_LLVM_DYLIB)
message(STATUS "Linking to LLVM dynamic shared library object")
set(llvm_libs LLVM)
else()
message(STATUS "Linking to separate LLVM static libraries")
llvm_map_components_to_libnames(llvm_libs
bitwriter
core
ipo
irreader
instcombine
instrumentation
target
linker
analysis
scalaropts
support
)
endif()
# Re-include AddLLVM module and configure LLVM/CMake settings
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
include(AddLLVM)
# Configure additional compile options for RTTI and exception handling based on LLVM settings
if(NOT LLVM_ENABLE_RTTI)
add_compile_options("-fno-rtti")
endif()
if(NOT LLVM_ENABLE_EH)
add_compile_options("-fno-exceptions")
endif()
# Check if the SVF_DIR environment variable is defined and set it accordingly
if (DEFINED SVF_DIR)
set(ENV{SVF_DIR} "${SVF_DIR}")
elseif (DEFINED ENV{SVF_DIR})
set(SVF_DIR $ENV{SVF_DIR})
else()
message(FATAL_ERROR "\
WARNING: The SVF_DIR var was not set !\n\
Please set this to environment variable to point to the SVF_DIR directory or set this variable to cmake configuration\n
(e.g. on linux: export SVF_DIR=/path/to/SVF/dir) \n or \n \n(make the project via: cmake -DSVF_DIR=your_path_to_SVF) ")
endif()
# Locate and configure SVF package based on the build type (Debug or Release)
if(CMAKE_BUILD_TYPE MATCHES "Debug")
MESSAGE (STATUS "building SVF in debug mode")
if (EXISTS "${SVF_DIR}/Debug-build")
set(SVF_BIN "${SVF_DIR}/Debug-build")
else()
set(SVF_BIN "${SVF_DIR}/Release-build")
endif()
else()
MESSAGE (STATUS "building SVF in release mode")
set(SVF_BIN "${SVF_DIR}/Release-build")
endif()
find_package(SVF CONFIG HINTS ${SVF_DIR} ${SVF_BIN})
message(STATUS "SVF STATUS:
Found: ${SVF_FOUND}
Version: ${SVF_VERSION}
Build mode: ${SVF_BUILD_TYPE}
C++ standard: ${SVF_CXX_STANDARD}
RTTI enabled: ${SVF_ENABLE_RTTI}
Exceptions enabled: ${SVF_ENABLE_EXCEPTIONS}
Install root directory: ${SVF_INSTALL_ROOT}
Install binary directory: ${SVF_INSTALL_BIN_DIR}
Install library directory: ${SVF_INSTALL_LIB_DIR}
Install include directory: ${SVF_INSTALL_INCLUDE_DIR}
Install 'extapi.bc' file path: ${SVF_INSTALL_EXTAPI_FILE}")
# Map LLVM components to their library names for use in linking
llvm_map_components_to_libnames(llvm_libs bitwriter core ipo irreader instcombine instrumentation target linker analysis scalaropts support)
# Check if SVF is found and handle importing with modern CMake methods or legacy methods
if("${SVF_FOUND}")
message(STATUS "Found installed SVF instance; importing using modern CMake methods")
# Ensure compatibility between SVF and LLVM in terms of RTTI and exception handling
if(NOT (${SVF_ENABLE_RTTI} STREQUAL ${LLVM_ENABLE_RTTI}))
message(FATAL_ERROR "SVF & LLVM RTTI support mismatch (SVF: ${SVF_ENABLE_RTTI}, LLVM: ${LLVM_ENABLE_RTTI})!")
endif()
if(NOT (${SVF_ENABLE_EXCEPTIONS} STREQUAL ${LLVM_ENABLE_EH}))
message(FATAL_ERROR "SVF & LLVM exceptions support mismatch (SVF: ${SVF_ENABLE_EXCEPTIONS}, LLVM: ${LLVM_ENABLE_EH})!")
endif()
# Include SVF include directories and link the library directories
include_directories(SYSTEM ${SVF_INSTALL_INCLUDE_DIR})
link_directories(${SVF_INSTALL_LIB_DIR})
else()
message(STATUS "Failed to find installed SVF instance; using legacy import method")
message(FATAL_ERROR "SVF & LLVM RTTI support mismatch (SVF: ${SVF_ENABLE_RTTI}, LLVM: ${LLVM_ENABLE_RTTI})!")
endif()
# Set the SVF library components
set(SVF_LIB SvfLLVM SvfCore)
# Find and configure Z3 package, first trying the system Z3 with CMake, then fallback to SVF's Z3 instance
# Find Z3 and its include directory from the top-level include file
find_library(
Z3_LIBRARIES
REQUIRED
NAMES z3
HINTS ${Z3_DIR} ENV Z3_DIR
PATH_SUFFIXES bin lib)
find_path(
Z3_INCLUDES
REQUIRED
NAMES z3++.h
HINTS ${Z3_DIR} ENV Z3_DIR
PATH_SUFFIXES include z3)
message(STATUS "Z3 STATUS:
Z3 library file: ${Z3_LIBRARIES}
Z3 include directory: ${Z3_INCLUDES}")
# Add the Z3 include directory and link the Z3 library to all targets of SVF
set(CMAKE_INSTALL_RPATH ${Z3_INCLUDES})
link_libraries(${Z3_LIBRARIES})
include_directories(SYSTEM ${Z3_INCLUDES})
add_subdirectory(HelloWorld)
add_subdirectory(CodeGraph)
add_subdirectory(Assignment-1)
add_subdirectory(Assignment-2)
add_subdirectory(Assignment-3)
add_subdirectory(Assignment-4)