-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathCMakeLists.txt
125 lines (101 loc) · 3.58 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
cmake_minimum_required(VERSION 3.3)
project(btor2tools)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include(GNUInstallDirs)
#-----------------------------------------------------------------------------#
option(ASAN "Compile with ASAN support" OFF)
option(BUILD_BTOR2AIGER "Build btor2aiger binary" OFF)
option(BUILD_TOOLS "Build btorsim, catbtor, btorsplit binaries" ON)
option(CHECK "Enable assertions for optimized builds" OFF)
option(BUILD_SHARED_LIBS "Build as shared library" ON)
#-----------------------------------------------------------------------------#
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
macro(add_c_flag flag)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
message(STATUS "Configuring with C flag '${flag}'")
endmacro()
macro(add_cxx_flag flag)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
message(STATUS "Configuring with CXX flag '${flag}'")
endmacro()
macro(add_c_cxx_flag flag)
add_c_flag(${flag})
add_cxx_flag(${flag})
endmacro()
macro(add_check_c_flag flag)
string(REGEX REPLACE "[-=]" "_" flagname ${flag})
check_c_compiler_flag("${flag}" HAVE_FLAG${flagname})
if(HAVE_FLAG${flagname})
add_c_flag(${flag})
endif()
endmacro()
macro(add_check_cxx_flag flag)
string(REGEX REPLACE "[-=]" "_" flagname ${flag})
check_cxx_compiler_flag("${flag}" HAVE_FLAG${flagname})
if(HAVE_FLAG${flagname})
add_cxx_flag(${flag})
endif()
endmacro()
macro(add_check_c_cxx_flag flag)
add_check_c_flag(${flag})
add_check_cxx_flag(${flag})
endmacro()
macro(add_required_cxx_flag flag)
string(REGEX REPLACE "[-=]" "_" flagnamename ${flag})
check_cxx_compiler_flag("${flag}" HAVE_FLAG${flagname})
if (NOT HAVE_FLAG${flagname})
message(FATAL_ERROR "Required compiler flag ${flag} not supported")
endif()
add_cxx_flag(${flag})
endmacro()
macro(add_required_c_flag flag)
string(REGEX REPLACE "[-=]" "_" flagname ${flag})
check_c_compiler_flag("${flag}" HAVE_FLAG${flagname})
if (NOT HAVE_FLAG${flagname})
message(FATAL_ERROR "Required compiler flag ${flag} not supported")
endif()
add_c_flag(${flag})
endmacro()
macro(add_required_c_cxx_flag flag)
add_required_c_flag(${flag})
add_required_cxx_flag(${flag})
endmacro()
#-----------------------------------------------------------------------------#
add_check_c_cxx_flag("-W")
add_check_c_cxx_flag("-Wall")
add_check_c_cxx_flag("-Wextra")
add_check_c_cxx_flag("-Wredundant-decls")
add_check_c_flag("-std=gnu99")
add_required_cxx_flag("-std=gnu++11")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_check_c_cxx_flag("-g3")
add_check_c_cxx_flag("-ggdb")
else()
add_check_c_cxx_flag("-O3")
if(NOT CHECK)
add_check_c_cxx_flag("-DNDEBUG")
endif()
endif()
if(ASAN)
# -fsanitize=address requires CMAKE_REQUIRED_FLAGS to be explicitely set,
# otherwise the -fsanitize=address check will fail while linking.
set(CMAKE_REQUIRED_FLAGS -fsanitize=address)
add_required_c_cxx_flag("-fsanitize=address")
unset(CMAKE_REQUIRED_FLAGS)
add_check_c_cxx_flag("-fno-omit-frame-pointer")
add_required_c_cxx_flag("-fsanitize-recover=address")
set(BUILD_SHARED_LIBS ON)
endif()
if(BUILD_BTOR2AIGER)
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/deps/aiger/aiger.c")
message(FATAL_ERROR
"Could not find AIGER sources. Execute script setup-aiger.sh.")
endif()
list(APPEND CMAKE_PREFIX_PATH "${PROJECT_SOURCE_DIR}/deps/install")
find_package(Boolector)
endif()
add_subdirectory(src)