-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
159 lines (126 loc) · 4.44 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
# Copyright (c) 2018 Trail of Bits, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Fix behavior of CMAKE_CXX_STANDARD when targeting macOS.
if (POLICY CMP0025)
cmake_policy(SET CMP0025 NEW)
endif ()
if (DEFINED VCPKG_ROOT)
message(WARNING "Building with VCPKG")
include(cmake/vcpkg_helper.cmake)
else()
message(WARNING "Running the standard CMake build; if this is a mistake, reconfigure again and pass `-DVCPKG_ROOT=/path/to/vcpkg`")
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
endif()
project(rellic)
cmake_minimum_required(VERSION 3.2)
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/settings.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils.cmake")
FindAndSelectClangCompiler()
enable_language(C CXX ASM)
set(RELLIC_SOURCE_DIR "${PROJECT_SOURCE_DIR}")
# warnings and compiler settings
if(NOT DEFINED WIN32)
set(PROJECT_CXXFLAGS
${GLOBAL_CXXFLAGS}
-Werror
# -Wconversion
-pedantic
-Wno-unreachable-code-return
)
endif()
list(APPEND PROJECT_INCLUDEDIRECTORIES ${CMAKE_CURRENT_BINARY_DIR})
# this is needed for the #include directives with absolutes paths to work correctly; it must
# also be set to PUBLIC since rellic-lift includes some files directly
list(APPEND PROJECT_INCLUDEDIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR})
#
# libraries
#
# llvm
find_package(LLVM REQUIRED CONFIG HINTS ${FINDPACKAGE_LLVM_HINTS})
string(REPLACE "." ";" LLVM_VERSION_LIST ${LLVM_PACKAGE_VERSION})
list(GET LLVM_VERSION_LIST 0 LLVM_MAJOR_VERSION)
list(GET LLVM_VERSION_LIST 1 LLVM_MINOR_VERSION)
set(LLVM_LIBRARIES
LLVMCore LLVMSupport LLVMAnalysis LLVMipo LLVMIRReader
LLVMBitReader LLVMBitWriter LLVMTransformUtils LLVMScalarOpts
LLVMLTO
)
list(APPEND PROJECT_LIBRARIES ${LLVM_LIBRARIES})
list(APPEND PROJECT_DEFINITIONS ${LLVM_DEFINITIONS})
list(APPEND PROJECT_INCLUDEDIRECTORIES ${LLVM_INCLUDE_DIRS})
# clang
find_package(Clang REQUIRED)
set(CLANG_LIBS clangIndex clangCodeGen clangASTMatchers clangTooling)
list(APPEND PROJECT_LIBRARIES ${CLANG_LIBS})
# z3
find_package(Z3 CONFIG 4.7.1 REQUIRED)
list(APPEND PROJECT_LIBRARIES z3::libz3)
# Potentially fixup bad LLVM z3 linkage
get_target_property(LLVMSupport_LIBS LLVMSupport INTERFACE_LINK_LIBRARIES)
list(FIND LLVMSupport_LIBS "Z3" _index)
if (${_index} GREATER -1)
list(REMOVE_ITEM LLVMSupport_LIBS Z3)
list(APPEND LLVMSupport_LIBS z3::libz3)
set_target_properties(LLVMSupport PROPERTIES
INTERFACE_LINK_LIBRARIES "${LLVMSupport_LIBS}")
endif()
# google log module
find_package(glog CONFIG QUIET)
if (NOT glog_FOUND)
find_package(glog REQUIRED)
list(APPEND PROJECT_LIBRARIES glog)
else()
list(APPEND PROJECT_LIBRARIES glog::glog)
endif()
# gflags
find_package(gflags CONFIG QUIET)
if (NOT gflags_FOUND)
find_package(gflags REQUIRED)
endif()
list(APPEND PROJECT_LIBRARIES gflags)
set(RELLIC_LLVM_VERSION "${LLVM_MAJOR_VERSION}.${LLVM_MINOR_VERSION}")
#
# helper macro to set target properties
#
macro(add_project_properties target)
target_link_libraries(${target} PRIVATE ${PROJECT_LIBRARIES})
target_include_directories(${target} SYSTEM PUBLIC ${PROJECT_INCLUDEDIRECTORIES})
target_compile_definitions(${target} PUBLIC ${PROJECT_DEFINITIONS})
target_compile_options(${target} PRIVATE ${PROJECT_CXXFLAGS})
endmacro()
#
# rellic libraries
#
add_subdirectory(rellic)
#
# rellic executables
#
add_subdirectory(tools)
#
# tests
#
enable_testing()
find_package(Clang CONFIG REQUIRED)
get_target_property(CLANG_PATH clang LOCATION)
message(STATUS "Clang path for tests: \"${CLANG_PATH}\"")
# Tests that survive a complete roundtrip
add_test(NAME test_roundtrip_rebuild
COMMAND scripts/roundtrip.py $<TARGET_FILE:${RELLIC_DECOMP}> tests/tools/decomp/ "${CLANG_PATH}"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
# Tests that may not roundtrip yet, but should emit C
add_test(NAME test_roundtrip_translate_only
COMMAND scripts/roundtrip.py --translate-only $<TARGET_FILE:${RELLIC_DECOMP}> tests/tools/decomp/failing-rebuild/ "${CLANG_PATH}"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)