forked from eurecom-s3/symcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
120 lines (102 loc) · 4.38 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
# This file is part of SymCC.
#
# SymCC is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# SymCC is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# SymCC. If not, see <https://www.gnu.org/licenses/>.
cmake_minimum_required(VERSION 3.5)
project(SymbolicCompiler)
option(QSYM_BACKEND "Use the Qsym backend instead of our own" OFF)
option(TARGET_32BIT "Make the compiler work correctly with -m32" OFF)
# We need to build the runtime as an external project because CMake otherwise
# doesn't allow us to build it twice with different options (one 32-bit version
# and one 64-bit variant).
include(ExternalProject)
set(SYM_RUNTIME_BUILD_ARGS
-DCMAKE_AR=${CMAKE_AR}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
-DCMAKE_C_FLAGS_INIT=${CMAKE_C_FLAGS_INIT}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DCMAKE_CXX_FLAGS_INIT=${CMAKE_CXX_FLAGS_INIT}
-DCMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS}
-DCMAKE_EXE_LINKER_FLAGS_INIT=${CMAKE_EXE_LINKER_FLAGS_INIT}
-DCMAKE_MODULE_LINKER_FLAGS=${CMAKE_MODULE_LINKER_FLAGS}
-DCMAKE_MODULE_LINKER_FLAGS_INIT=${CMAKE_MODULE_LINKER_FLAGS_INIT}
-DCMAKE_SHARED_LINKER_FLAGS=${CMAKE_SHARED_LINKER_FLAGS}
-DCMAKE_SHARED_LINKER_FLAGS_INIT=${CMAKE_SHARED_LINKER_FLAGS_INIT}
-DCMAKE_SYSROOT=${CMAKE_SYSROOT}
-DQSYM_BACKEND=${QSYM_BACKEND}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DZ3_TRUST_SYSTEM_VERSION=${Z3_TRUST_SYSTEM_VERSION})
ExternalProject_Add(SymRuntime
SOURCE_DIR ${CMAKE_SOURCE_DIR}/runtime
CMAKE_ARGS
${SYM_RUNTIME_BUILD_ARGS}
-DCMAKE_EXPORT_COMPILE_COMMANDS=${CMAKE_EXPORT_COMPILE_COMMANDS}
-DZ3_DIR=${Z3_DIR}
-DLLVM_DIR=${LLVM_DIR}
INSTALL_COMMAND ""
BUILD_ALWAYS TRUE)
ExternalProject_Get_Property(SymRuntime BINARY_DIR)
set(SYM_RUNTIME_DIR ${BINARY_DIR})
if (${TARGET_32BIT})
ExternalProject_Add(SymRuntime32
SOURCE_DIR ${CMAKE_SOURCE_DIR}/runtime
CMAKE_ARGS
${SYM_RUNTIME_BUILD_ARGS}
-DCMAKE_C_FLAGS="${CMAKE_C_FLAGS} -m32"
-DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -m32"
-DZ3_DIR=${Z3_32BIT_DIR}
-DLLVM_DIR=${LLVM_32BIT_DIR}
INSTALL_COMMAND ""
BUILD_ALWAYS TRUE)
ExternalProject_Get_Property(SymRuntime32 BINARY_DIR)
set(SYM_RUNTIME_32BIT_DIR ${BINARY_DIR})
endif()
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake from ${LLVM_DIR}")
if (${LLVM_VERSION_MAJOR} LESS 8 OR ${LLVM_VERSION_MAJOR} GREATER 11)
message(WARNING "The software has been developed for LLVM 8 through 11; \
it is unlikely to work with other versions!")
endif()
add_definitions(${LLVM_DEFINITIONS})
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 \
-Wredundant-decls -Wcast-align -Wmissing-include-dirs -Wswitch-default \
-Wextra -Wall -Winvalid-pch -Wredundant-decls -Wformat=2 \
-Wmissing-format-attribute -Wformat-nonliteral -Werror")
# Mark nodelete to work around unload bug in upstream LLVM 5.0+
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-z,nodelete")
# This is the compiler pass that we later load into clang or opt. If LLVM is
# built without RTTI we have to disable it for our library too, otherwise we'll
# get linker errors.
add_library(Symbolize MODULE
compiler/Symbolizer.cpp
compiler/Pass.cpp
compiler/Runtime.cpp
compiler/Main.cpp)
if (NOT LLVM_ENABLE_RTTI)
set_target_properties(Symbolize PROPERTIES COMPILE_FLAGS "-fno-rtti")
endif()
find_program(CLANG_BINARY "clang"
HINTS ${LLVM_TOOLS_BINARY_DIR}
DOC "The clang binary to use in the symcc wrapper script.")
find_program(CLANGPP_BINARY "clang++"
HINTS ${LLVM_TOOLS_BINARY_DIR}
DOC "The clang binary to use in the sym++ wrapper script.")
if (NOT CLANG_BINARY)
message(FATAL_ERROR "Clang not found; please make sure that the version corresponding to your LLVM installation is available.")
endif()
configure_file("compiler/symcc.in" "symcc" @ONLY)
configure_file("compiler/sym++.in" "sym++" @ONLY)
add_subdirectory(test)