-
Notifications
You must be signed in to change notification settings - Fork 139
/
CMakeLists.txt
144 lines (121 loc) · 5.29 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
# 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.16)
project(SymCC)
set(LLVM_VERSION "" CACHE STRING "LLVM version to use. The corresponding LLVM dev package must be installed.")
set(SYMCC_RT_BACKEND "qsym" CACHE STRING "The symbolic backend to use. Please check symcc-rt to get a list of the available backends.")
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)
# Find LLVM
find_package(LLVM ${LLVM_VERSION} 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 17)
message(WARNING "The software has been developed for LLVM 8 through 17; \
it is unlikely to work with other versions!")
endif()
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_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
-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_MODULE_PATH=${CMAKE_MODULE_PATH}
-DCMAKE_SYSROOT=${CMAKE_SYSROOT}
-DSYMCC_RT_BACKEND=${SYMCC_RT_BACKEND}
-DLLVM_VERSION=${LLVM_PACKAGE_VERSION}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DZ3_TRUST_SYSTEM_VERSION=${Z3_TRUST_SYSTEM_VERSION})
ExternalProject_Add(SymCCRuntime
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(SymCCRuntime BINARY_DIR)
set(SYMCC_RUNTIME_DIR ${BINARY_DIR})
if (${TARGET_32BIT})
ExternalProject_Add(SymCCRuntime32
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(SymCCRuntime32 BINARY_DIR)
set(SYMCC_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 18)
message(WARNING "The software has been developed for LLVM 8 through 18; \
it is unlikely to work with other versions!")
endif()
add_definitions(${LLVM_DEFINITIONS})
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-Wredundant-decls -Wcast-align -Wmissing-include-dirs -Wswitch-default \
-Wextra -Wall -Winvalid-pch -Wredundant-decls -Wformat=2 \
-Wmissing-format-attribute -Wformat-nonliteral -Werror -Wno-error=deprecated-declarations")
# 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(SymCC MODULE
compiler/Symbolizer.cpp
compiler/Pass.cpp
compiler/Runtime.cpp
compiler/Main.cpp)
set_target_properties(SymCC PROPERTIES OUTPUT_NAME "symcc")
if (NOT LLVM_ENABLE_RTTI)
set_target_properties(SymCC 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()
if (${LLVM_VERSION_MAJOR} LESS 13)
set(CLANG_LOAD_PASS "-Xclang -load -Xclang ")
else()
set(CLANG_LOAD_PASS "-fpass-plugin=")
endif()
configure_file("compiler/symcc.in" "symcc" @ONLY)
configure_file("compiler/sym++.in" "sym++" @ONLY)
add_subdirectory(test)