-
Notifications
You must be signed in to change notification settings - Fork 109
/
CMakeLists.txt
120 lines (100 loc) · 4.95 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
cmake_minimum_required(VERSION 3.4.1)
project(hobbes)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIRS})
find_package(Readline REQUIRED)
include_directories(${Readline_INCLUDE_DIRS})
set(CURSES_NEED_NCURSES TRUE)
find_package(Curses REQUIRED)
include_directories(${CURSES_INCLUDE_DIRS})
find_package(LLVM REQUIRED CONFIG)
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})
set(CMAKE_CXX_STANDARD 14)
if (${LLVM_PACKAGE_VERSION} VERSION_LESS "3.6")
set(jit_lib jit)
elseif(${LLVM_PACKAGE_VERSION} VERSION_LESS "11.0")
set(jit_lib mcjit)
else()
set(jit_lib mcjit orcjit)
endif()
find_program(llvm-config llvm-config PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
find_program(llvm-config llvm-config)
if (${LLVM_PACKAGE_VERSION} VERSION_LESS "4.0")
execute_process(COMMAND ${llvm-config} --libs x86 ipo ${jit_lib}
OUTPUT_VARIABLE llvm_libs
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${llvm-config} --ldflags
OUTPUT_VARIABLE llvm_ldflags
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${llvm-config} --system-libs
OUTPUT_VARIABLE sys_libs
OUTPUT_STRIP_TRAILING_WHITESPACE)
else()
execute_process(COMMAND ${llvm-config} --libs x86 ipo ${jit_lib} --link-static
OUTPUT_VARIABLE llvm_libs
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${llvm-config} --ldflags
OUTPUT_VARIABLE llvm_ldflags
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${llvm-config} --system-libs --ignore-libllvm
OUTPUT_VARIABLE sys_libs
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
message(STATUS "llvm libs: ${llvm_libs}")
message(STATUS "llvm ldflags: ${llvm_ldflags}")
message(STATUS "llvm syslibs: ${sys_libs}")
file(GLOB_RECURSE lib_headers lib/*.H)
file(GLOB_RECURSE lib_source lib/*.C)
set(lib_files ${lib_headers} ${lib_source})
include_directories(include)
file(GLOB test_files test/*.C)
file(GLOB hi_files bin/hi/*.C)
file(GLOB_RECURSE hog_files bin/hog/*.C)
if(UNIX AND NOT APPLE)
set(LINUX TRUE)
endif()
if(APPLE)
set(sys_libs ${sys_libs} pthread dl)
set(cxx_flags "-Wreorder")
endif()
if(LINUX)
set(sys_libs ${sys_libs} pthread dl rt)
set(cxx_flags "-Werror=old-style-cast -Werror -Wall -Wextra -Winit-self -Wreturn-type -Wunused-variable -Wsign-compare -Warray-bounds -Wunknown-pragmas -Wuninitialized -Wstrict-aliasing -Wunused-value -Wunused-label -Wswitch -Wcast-align -Wctor-dtor-privacy -Wmissing-noreturn -Wunused-parameter -Wreorder")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${cxx_flags}")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
option(USE_ASAN_UBSAN "Use address,undefined sanitizers" OFF)
if(USE_ASAN_AND_UBSAN)
# _FORTIFY_SOURCE doesn't play well with asan
# https://github.com/google/sanitizers/issues/247
add_definitions(-U_FORTIFY_SOURCE)
add_compile_options("-fno-omit-frame-pointer;-fsanitize=address,undefined;-fno-optimize-sibling-calls;-fno-sanitize-recover=all")
add_link_options("-fsanitize=address,undefined;-fno-optimize-sibling-calls;-fno-sanitize-recover=all")
add_compile_options("$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:-fsanitize=local-bounds,float-divide-by-zero,nullability,signed-integer-overflow,shift,integer-divide-by-zero>")
add_link_options("$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:-fsanitize=local-bounds,float-divide-by-zero,nullability,signed-integer-overflow,shift,integer-divide-by-zero>")
add_compile_options("$<$<CXX_COMPILER_ID:GNU>:--param=max-vartrack-size=60000000>")
message(STATUS "address and undefined sanitizers enabled")
endif()
add_library(hobbes STATIC ${lib_files})
target_link_libraries(hobbes PUBLIC ${llvm_ldflags} ${llvm_libs} ${ZLIB_LIBRARIES} ${CURSES_LIBRARIES} ${sys_libs})
add_library(hobbes-pic STATIC ${lib_files})
target_link_libraries(hobbes-pic PUBLIC ${llvm_ldflags} ${llvm_libs} ${ZLIB_LIBRARIES} ${CURSES_LIBRARIES} ${sys_libs})
set_property(TARGET hobbes-pic PROPERTY POSITION_INDEPENDENT_CODE TRUE)
add_executable(hi ${hi_files})
target_link_libraries(hi PUBLIC "-rdynamic" PRIVATE hobbes ${Readline_LIBRARIES})
add_executable(hog ${hog_files})
target_link_libraries(hog PRIVATE hobbes)
enable_testing()
add_executable(mock-proc test/mocks/proc.C)
add_executable(hobbes-test ${test_files})
target_link_libraries(hobbes-test PRIVATE hobbes)
add_test(hobbes-test hobbes-test)
find_package(PythonInterp 2.7 REQUIRED)
set_property(TARGET hobbes-test PROPERTY COMPILE_FLAGS "-DPYTHON_EXECUTABLE=\"${PYTHON_EXECUTABLE}\" -DSCRIPT_DIR=\"${CMAKE_SOURCE_DIR}/scripts/\"")
install(TARGETS hobbes hobbes-pic DESTINATION "lib")
install(TARGETS hi hog hobbes-test DESTINATION "bin")
install(DIRECTORY "include/hobbes" DESTINATION "include")
install(DIRECTORY "scripts" DESTINATION "scripts")