-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
147 lines (123 loc) · 4.05 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
cmake_minimum_required(VERSION 3.21)
# 3.21 - CMAKE_<LANG>_LINKER_LAUNCHER
project(stabilizer CXX)
enable_language(C)
# Enabling C language is required for find_package(LLVM)
option(BUILD_TESTING "Build the testing project." ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
include(GNUInstallDirs)
### libLLVMStabilizer.so
add_library(LLVMStabilizer MODULE)
find_package(LLVM ${STABILIZER_LLVM_VERSION} REQUIRED CONFIG)
target_include_directories(LLVMStabilizer PRIVATE ${LLVM_INCLUDE_DIRS})
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
target_compile_definitions(LLVMStabilizer PRIVATE ${LLVM_DEFINITIONS_LIST})
target_sources(LLVMStabilizer
PRIVATE
pass/IntrinsicLibcalls.h
pass/LowerIntrinsics.cpp
pass/Stabilizer.cpp
)
### libstabilizer.so
add_library(stabilizer MODULE)
target_include_directories(stabilizer
PRIVATE
Heap-Layers
DieHard/src/include
DieHard/src/include/math
DieHard/src/include/rng
DieHard/src/include/static
DieHard/src/include/util
)
target_sources(stabilizer
PRIVATE
runtime/Arch.h
runtime/Context.h
runtime/Debug.cpp
runtime/Debug.h
runtime/Function.cpp
runtime/Function.h
runtime/FunctionLocation.h
runtime/Heap.cpp
runtime/Heap.h
runtime/Intrinsics.cpp
runtime/Jump.h
runtime/MMapSource.h
runtime/MemRange.h
runtime/Trap.h
runtime/Util.h
runtime/libstabilizer.cpp
)
### SZCC
if (NOT ${CMAKE_CURRENT_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/szcc ${CMAKE_CURRENT_BINARY_DIR}/szcc COPYONLY)
endif()
file(CREATE_LINK ${CMAKE_CURRENT_BINARY_DIR}/szcc ${CMAKE_CURRENT_BINARY_DIR}/szcc++ SYMBOLIC)
file(CREATE_LINK ${CMAKE_CURRENT_BINARY_DIR}/szcc ${CMAKE_CURRENT_BINARY_DIR}/clang SYMBOLIC)
file(CREATE_LINK ${CMAKE_CURRENT_BINARY_DIR}/szcc ${CMAKE_CURRENT_BINARY_DIR}/clang++ SYMBOLIC)
### Installation
macro(install_symlink filepath sympath)
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${filepath} ${sympath})")
install(CODE "message(\"-- Created symlink: ${sympath} -> ${filepath}\")")
endmacro(install_symlink)
install(
TARGETS LLVMStabilizer stabilizer
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(
PROGRAMS
${CMAKE_CURRENT_BINARY_DIR}/szcc
TYPE BIN
)
install(
FILES LICENSE
TYPE DOC
)
install_symlink(${CMAKE_INSTALL_FULL_BINDIR}/szcc ${CMAKE_INSTALL_FULL_BINDIR}/szcc++)
install_symlink(${CMAKE_INSTALL_FULL_BINDIR}/szcc ${CMAKE_INSTALL_FULL_DOCDIR}/clang)
install_symlink(${CMAKE_INSTALL_FULL_BINDIR}/szcc ${CMAKE_INSTALL_FULL_DOCDIR}/clang++)
### Testing
if (BUILD_TESTING)
# Generate toolchain file for the tests
set(STABILIZER_ENV_LAUNCHER
cmake -E env
LD_LIBRARY_PATH=$<TARGET_FILE_DIR:LLVMStabilizer>:$ENV{LD_LIBRARY_PATH}
SZ_CODE=1
SZ_HEAP=1
SZ_STACK=1
)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/StabilizerToolchain.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake/StabilizerToolchain.cmake.tmp
@ONLY
)
file(GENERATE
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/cmake/StabilizerToolchain.cmake
INPUT ${CMAKE_CURRENT_BINARY_DIR}/cmake/StabilizerToolchain.cmake.tmp
)
# Add tests project
include(ExternalProject)
ExternalProject_Add(
tests
DEPENDS LLVMStabilizer stabilizer
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests
CMAKE_ARGS
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_CURRENT_BINARY_DIR}/cmake/StabilizerToolchain.cmake
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
INSTALL_COMMAND ""
)
# CRAP: workaround for launching tests from the root dir
# https://discourse.cmake.org/t/testing-in-a-superbuild/1906
ExternalProject_Get_Property(tests BINARY_DIR)
file(RELATIVE_PATH ctest_dir "${CMAKE_CURRENT_BINARY_DIR}" "${BINARY_DIR}")
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/CTestTestfile.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake/CTestTestfile.cmake.tmp
)
file(GENERATE
OUTPUT CTestTestfile.cmake
INPUT ${CMAKE_CURRENT_BINARY_DIR}/cmake/CTestTestfile.cmake.tmp
)
endif()