forked from Boolector/boolector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
527 lines (447 loc) · 14.6 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
# Boolector: Satisfiablity Modulo Theories (SMT) solver.
#
# Copyright (C) 2007-2021 by the authors listed in the AUTHORS file.
#
# This file is part of Boolector.
# See COPYING for more information on using this software.
#
cmake_minimum_required(VERSION 3.3)
#-----------------------------------------------------------------------------#
project(boolector)
set(VERSION "3.2.3")
string(TIMESTAMP TIME)
#-----------------------------------------------------------------------------#
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
list(APPEND CMAKE_PREFIX_PATH "${PROJECT_SOURCE_DIR}/deps/install")
#-----------------------------------------------------------------------------#
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()
# 3-valued option IGNORE/OFF/ON
macro(option3vl var description)
set(${var} IGNORE CACHE STRING "${description}")
# Provide drop down menu options in cmake-gui
set_property(CACHE ${var} PROPERTY STRINGS IGNORE ON OFF)
endmacro()
# Set option only if it still has initial value IGNORE (do not overwrite user
# configurations)
macro(set_option var value)
if(${var} STREQUAL "IGNORE")
set(${var} ${value})
endif()
endmacro()
#-----------------------------------------------------------------------------#
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)
message(STATUS "LIB directory is '${CMAKE_BINARY_DIR}/lib'")
message(STATUS "BIN directory is '${CMAKE_BINARY_DIR}/bin'")
#-----------------------------------------------------------------------------#
option3vl(ASAN "Compile with ASAN support")
option3vl(UBSAN "Compile with UBSan support")
option3vl(CHECK "Enable assertions even for optimized compilation")
option3vl(GCOV "Compile with coverage support")
option3vl(GPROF "Compile with profiling support")
option3vl(LOG "Compile with logging support (default for Debug builds)")
option3vl(PYTHON "Build Python API")
option3vl(TIME_STATS "Compile with time statistics")
option3vl(TESTING "Configure unit and regression testing")
option3vl(USE_CADICAL "Use and link with CaDiCaL")
option3vl(USE_CMS "Use and link with CryptoMiniSat")
option3vl(USE_LINGELING "Use and link with Lingeling (default)")
option3vl(USE_MINISAT "Use and link with MiniSat")
option3vl(USE_PICOSAT "Use and link with PicoSAT")
option(ONLY_CADICAL "Only use CaDiCaL" OFF)
option(ONLY_CMS "Only use CryptoMiniSat" OFF)
option(ONLY_LINGELING "Only use Lingeling" OFF)
option(ONLY_MINISAT "Only use MiniSat" OFF)
option(ONLY_PICOSAT "Only use PicoSAT" OFF)
option(USE_PYTHON2 "Prefer Python 2.7" )
option(USE_PYTHON3 "Prefer Python 3" )
option(USE_GMP "Use GMP for bit-vector implementation" OFF)
#-----------------------------------------------------------------------------#
# Automatically build shared libraries if Python bindings are enabled.
if(PYTHON)
if(USE_PYTHON2)
find_package(PythonInterp 2.7 REQUIRED)
elseif(USE_PYTHON3)
find_package(PythonInterp 3 REQUIRED)
else()
find_package(PythonInterp REQUIRED)
endif()
# Explicitly check for a compatible version of Python libs.
find_package(PythonLibs
${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}.${PYTHON_VERSION_PATCH}
REQUIRED)
# Produce a python module that only links against system libraries. SAT
# solvers and libboolector should be included in the module itself.
if(NOT BUILD_SHARED_LIBS)
add_check_c_cxx_flag("-fPIC")
# Disable MiniSat since the static library is not compiled with -fPIC by
# default.
message(STATUS "Disabling MiniSat for static Python builds. "
"Use --shared if you need MiniSat.")
set_option(USE_MINISAT OFF)
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(UBSAN)
add_required_c_cxx_flag("-fsanitize=undefined")
set(BUILD_SHARED_LIBS ON)
endif()
if(NOT BUILD_SHARED_LIBS)
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
endif()
#-----------------------------------------------------------------------------#
# Default values for 3-valued options
set_option(USE_CADICAL ON)
set_option(USE_CMS ON)
set_option(USE_LINGELING ON)
set_option(USE_MINISAT ON)
set_option(USE_PICOSAT ON)
#-----------------------------------------------------------------------------#
# Note: Do not set these flags the cmake way as we need them for generating
# btorconfig.h and they are else not yet added to CMAKE_C(XX)_FLAGS at
# file generation time (configure_file).
add_required_c_flag("-std=gnu99")
add_required_cxx_flag("-std=gnu++11")
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")
foreach(flag ${FLAGS})
add_required_c_cxx_flag("${flag}")
endforeach()
if(IS_WINDOWS_BUILD)
add_definitions("-DBTOR_WINDOWS_BUILD")
endif()
#-----------------------------------------------------------------------------#
set(build_types Debug Release)
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type set, options are: ${build_types}")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Options are: ${build_types}" FORCE)
# Provide drop down menu options in cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${build_types})
endif()
message(STATUS "Building ${CMAKE_BUILD_TYPE} build")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_required_c_cxx_flag("-g")
add_check_c_cxx_flag("-g3")
add_check_c_cxx_flag("-ggdb")
set_option(LOG ON)
set_option(TESTING ON)
set_option(TIME_STATS ON)
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
add_check_c_cxx_flag("-O3")
if(NOT CHECK)
add_definitions("-DNDEBUG")
endif()
set_option(LOG OFF)
set_option(TIME_STATS OFF)
endif()
#-----------------------------------------------------------------------------#
if(GCOV)
include(CodeCoverage)
APPEND_COVERAGE_COMPILER_FLAGS()
setup_target_for_coverage_lcov(
NAME coverage
EXECUTABLE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test
DEPENDENCIES boolector-bin)
endif()
if(GPROF)
add_required_c_cxx_flag("-pg")
endif()
if(NOT LOG)
add_definitions("-DNBTORLOG")
endif()
include(CheckSignals)
if(HAVE_SIGNALS)
add_definitions("-DBTOR_HAVE_SIGNALS")
endif()
include(CheckTimeUtils)
if(NOT HAVE_TIME_UTILS)
set(TIME_STATS OFF)
endif()
if(TIME_STATS)
add_definitions("-DBTOR_TIME_STATISTICS")
endif()
include(CheckNoExportDynamic)
#-----------------------------------------------------------------------------#
if(ONLY_CADICAL)
set(USE_CMS OFF)
set(USE_LINGELING OFF)
set(USE_MINISAT OFF)
set(USE_PICOSAT OFF)
set(USE_CADICAL ON)
elseif(ONLY_CMS)
set(USE_CADICAL OFF)
set(USE_LINGELING OFF)
set(USE_MINISAT OFF)
set(USE_PICOSAT OFF)
set(USE_CMS ON)
elseif(ONLY_LINGELING)
set(USE_CADICAL OFF)
set(USE_CMS OFF)
set(USE_MINISAT OFF)
set(USE_PICOSAT OFF)
set(USE_LINGELING ON)
elseif(ONLY_MINISAT)
set(USE_CADICAL OFF)
set(USE_CMS OFF)
set(USE_LINGELING OFF)
set(USE_PICOSAT OFF)
set(USE_MINISAT ON)
elseif(ONLY_PICOSAT)
set(USE_CADICAL OFF)
set(USE_CMS OFF)
set(USE_LINGELING OFF)
set(USE_MINISAT OFF)
set(USE_PICOSAT ON)
endif()
#-----------------------------------------------------------------------------#
find_package(Btor2Tools REQUIRED)
if(NOT IS_WINDOWS_BUILD)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads)
if(Threads_FOUND)
set(LIBRARIES ${LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
add_definitions("-DBTOR_HAVE_PTHREADS")
endif()
endif()
if(USE_GMP)
find_package(GMP)
if(GMP_FOUND)
add_definitions("-DBTOR_USE_GMP")
endif()
endif()
if(USE_LINGELING)
find_package(Lingeling)
endif()
if(USE_CADICAL)
find_package(CaDiCaL)
endif()
if(USE_CMS)
find_package(CryptoMiniSat)
endif()
if(USE_PICOSAT)
find_package(PicoSAT)
endif()
if(USE_MINISAT)
find_package(MiniSat)
endif()
if(NOT USE_LINGELING
AND NOT USE_CADICAL
AND NOT USE_CMS
AND NOT USE_PICOSAT
AND NOT USE_MINISAT)
message(FATAL_ERROR "No SAT solver configured")
elseif(NOT Lingeling_FOUND
AND NOT CaDiCaL_FOUND
AND NOT CryptoMiniSat_FOUND
AND NOT PicoSAT_FOUND
AND NOT MiniSat_FOUND)
message(FATAL_ERROR "No SAT solver found")
endif()
if(Lingeling_FOUND)
if(NOT Lingeling_INCLUDE_DIR)
message(FATAL_ERROR "Lingeling headers not found")
else()
add_definitions("-DBTOR_USE_LINGELING")
endif()
endif()
if(CaDiCaL_FOUND)
if(NOT CaDiCaL_INCLUDE_DIR)
message(FATAL_ERROR "CaDiCaL headers not found")
else()
add_definitions("-DBTOR_USE_CADICAL")
endif()
endif()
if(CryptoMiniSat_FOUND)
if(NOT CryptoMiniSat_INCLUDE_DIR)
message(FATAL_ERROR "CryptoMiniSat headers not found")
else()
add_definitions("-DBTOR_USE_CMS")
endif()
endif()
if(PicoSAT_FOUND)
if(NOT PicoSAT_INCLUDE_DIR)
message(FATAL_ERROR "PicoSAT headers not found")
else()
add_definitions("-DBTOR_USE_PICOSAT")
endif()
endif()
if(MiniSat_FOUND)
if(NOT MiniSat_INCLUDE_DIR)
message(FATAL_ERROR "MiniSAT headers not found")
else()
add_definitions("-DBTOR_USE_MINISAT")
endif()
endif()
#-----------------------------------------------------------------------------#
# Extract info from Git for btorconfig.h
find_package(Git)
set(GIT_DIRTY "")
set(GIT_SHA1 "")
set(GIT_BRANCH "")
if(GIT_FOUND)
# Get current git branch, result is != 0 if this is not a git repository
execute_process(
COMMAND ${GIT_EXECUTABLE} -C ${PROJECT_SOURCE_DIR} rev-parse --abbrev-ref HEAD
RESULT_VARIABLE GIT_RESULT
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if("${GIT_RESULT}" STREQUAL "0")
set(GIT_BRANCH "${GIT_BRANCH}-")
# Extract sha1 of HEAD
execute_process(
COMMAND ${GIT_EXECUTABLE} -C ${PROJECT_SOURCE_DIR} rev-parse HEAD
OUTPUT_VARIABLE GIT_SHA1
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Result is != 0 if worktree is dirty
execute_process(
COMMAND ${GIT_EXECUTABLE} -C ${PROJECT_SOURCE_DIR} diff --quiet
RESULT_VARIABLE GIT_RESULT
)
if(NOT "${GIT_RESULT}" STREQUAL "0")
set(GIT_DIRTY "-dirty")
endif()
endif()
endif()
# TODO: definitions added via add_definititions
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/src/btorconfig.h.in
${CMAKE_CURRENT_BINARY_DIR}/src/btorconfig.h)
#-----------------------------------------------------------------------------#
# Regression tests
if(TESTING)
enable_testing()
endif()
#-----------------------------------------------------------------------------#
# Source directories
include_directories(src ${CMAKE_CURRENT_BINARY_DIR}/src)
add_subdirectory(src)
if(TESTING)
add_subdirectory(test)
endif()
if(PYTHON)
add_subdirectory(src/api/python)
endif()
add_subdirectory(examples/api/c)
#-----------------------------------------------------------------------------#
set(ARCHIVE_NAME "boolector-${VERSION}")
add_custom_target(dist
COMMAND git archive --prefix=${ARCHIVE_NAME}/ HEAD
| xz > ${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar.xz
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
#-----------------------------------------------------------------------------#
# Install config and configversion for Boolector to add support for
# find_package(Boolector).
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/BoolectorConfigVersion.cmake
VERSION ${VERSION}
COMPATIBILITY SameMajorVersion
)
# Install the config, configversion and custom find modules
install(FILES
${CMAKE_CURRENT_LIST_DIR}/cmake/BoolectorConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/BoolectorConfigVersion.cmake
DESTINATION lib/cmake/Boolector
)
#-----------------------------------------------------------------------------#
# Print Boolector configuration
if(NOT WIN32)
string(ASCII 27 Esc)
set(Green "${Esc}[32m")
set(Blue "${Esc}[34m")
set(ResetColor "${Esc}[m")
endif()
macro(config_info msg value)
message(STATUS "${Blue}${msg}: ${Green}${value}${ResetColor}")
endmacro()
macro(config_info_bool msg value)
if(${value})
config_info("${msg}" "yes")
else()
config_info("${msg}" "no")
endif()
endmacro()
config_info("Build type" "${CMAKE_BUILD_TYPE}")
config_info_bool("Shared build" "${BUILD_SHARED_LIBS}")
config_info_bool("ASAN support" ASAN)
config_info_bool("UBSAN support" UBSAN)
config_info_bool("Assertions enabled" CHECK)
config_info_bool("Testing" TESTING)
config_info_bool("gcov support" GCOV)
config_info_bool("gprof support" GPROF)
config_info_bool("Logging support" LOG)
config_info_bool("Python bindings" PYTHON)
config_info_bool("Time statistics" TIME_STATS)
config_info_bool("CaDiCaL" CaDiCaL_FOUND)
config_info_bool("CryptoMiniSat" CryptoMiniSat_FOUND)
config_info_bool("Lingeling" Lingeling_FOUND)
config_info_bool("MiniSat" MiniSat_FOUND)
config_info_bool("PicoSAT" PicoSAT_FOUND)
config_info_bool("GMP" USE_GMP)