Enable -Werror. (#5969)
[cvc5.git] / CMakeLists.txt
1 #####################
2 ## CMakeLists.txt
3 ## Top contributors (to current version):
4 ## Mathias Preiner, Aina Niemetz, Gereon Kremer
5 ## This file is part of the CVC4 project.
6 ## Copyright (c) 2009-2020 by the authors listed in the file AUTHORS
7 ## in the top-level source directory and their institutional affiliations.
8 ## All rights reserved. See the file COPYING in the top-level source
9 ## directory for licensing information.
10 ##
11 cmake_minimum_required(VERSION 3.9)
12
13 #-----------------------------------------------------------------------------#
14 # Project configuration
15
16 project(cvc4)
17
18 include(GNUInstallDirs)
19
20 set(CVC4_MAJOR 1) # Major component of the version of CVC4.
21 set(CVC4_MINOR 9) # Minor component of the version of CVC4.
22 set(CVC4_RELEASE 0) # Release component of the version of CVC4.
23
24 # Extraversion component of the version of CVC4.
25 set(CVC4_EXTRAVERSION "-prerelease")
26
27 # Shared library versioning. Increment SOVERSION for every new CVC4 release.
28 set(CVC4_SOVERSION 7)
29
30 # Full release string for CVC4.
31 if(CVC4_RELEASE)
32 set(CVC4_RELEASE_STRING
33 "${CVC4_MAJOR}.${CVC4_MINOR}.${CVC4_RELEASE}${CVC4_EXTRAVERSION}")
34 else()
35 set(CVC4_RELEASE_STRING "${CVC4_MAJOR}.${CVC4_MINOR}${CVC4_EXTRAVERSION}")
36 endif()
37
38 set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
39 set(CMAKE_C_STANDARD 99)
40 set(CMAKE_CXX_STANDARD 17)
41 set(CMAKE_CXX_EXTENSIONS OFF)
42 set(CMAKE_CXX_STANDARD_REQUIRED ON)
43
44 # Generate compile_commands.json, which can be used for various code completion
45 # plugins.
46 set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
47
48 #-----------------------------------------------------------------------------#
49 # Policies
50
51 # Required for FindGLPK since it sets CMAKE_REQUIRED_LIBRARIES
52 if(POLICY CMP0075)
53 cmake_policy(SET CMP0075 NEW)
54 endif()
55
56 #-----------------------------------------------------------------------------#
57 # Tell CMake where to find our dependencies
58
59 if(ABC_DIR)
60 list(APPEND CMAKE_PREFIX_PATH "${ABC_DIR}")
61 endif()
62 if(ANTLR_DIR)
63 list(APPEND CMAKE_PREFIX_PATH "${ANTLR_DIR}")
64 endif()
65 if(CADICAL_DIR)
66 list(APPEND CMAKE_PREFIX_PATH "${CADICAL_DIR}")
67 endif()
68 if(CRYPTOMINISAT_DIR)
69 list(APPEND CMAKE_PREFIX_PATH "${CRYPTOMINISAT_DIR}")
70 endif()
71 if(CXXTEST_DIR)
72 list(APPEND CMAKE_PREFIX_PATH "${CXXTEST_DIR}")
73 endif()
74 if(DRAT2ER_DIR)
75 list(APPEND CMAKE_PREFIX_PATH "${DRAT2ER_DIR}")
76 endif()
77 if(GLPK_DIR)
78 list(APPEND CMAKE_PREFIX_PATH "${GLPK_DIR}")
79 endif()
80 if(GMP_DIR)
81 list(APPEND CMAKE_PREFIX_PATH "${GMP_DIR}")
82 endif()
83 if(KISSAT_DIR)
84 list(APPEND CMAKE_PREFIX_PATH "${KISSAT_DIR}")
85 endif()
86 if(LFSC_DIR)
87 list(APPEND CMAKE_PREFIX_PATH "${LFSC_DIR}")
88 endif()
89 if(POLY_DIR)
90 list(APPEND CMAKE_PREFIX_PATH "${POLY_DIR}")
91 endif()
92 if(SYMFPU_DIR)
93 list(APPEND CMAKE_PREFIX_PATH "${SYMFPU_DIR}")
94 endif()
95
96 # By default the contrib/get-* scripts install dependencies to deps/install.
97 list(APPEND CMAKE_PREFIX_PATH "${PROJECT_SOURCE_DIR}/deps/install")
98
99 #-----------------------------------------------------------------------------#
100
101 include(Helpers)
102
103 #-----------------------------------------------------------------------------#
104 # User options
105
106 # License
107 option(ENABLE_GPL "Enable GPL dependencies")
108
109 # General build options
110 #
111 # >> 3-valued: IGNORE ON OFF
112 # > allows to detect if set by user (default: IGNORE)
113 # > only necessary for options set for build types
114 cvc4_option(ENABLE_ASAN "Enable ASAN build")
115 cvc4_option(ENABLE_UBSAN "Enable UBSan build")
116 cvc4_option(ENABLE_TSAN "Enable TSan build")
117 cvc4_option(ENABLE_ASSERTIONS "Enable assertions")
118 cvc4_option(ENABLE_COMP_INC_TRACK
119 "Enable optimizations for incremental SMT-COMP tracks")
120 cvc4_option(ENABLE_DEBUG_SYMBOLS "Enable debug symbols")
121 cvc4_option(ENABLE_DUMPING "Enable dumping")
122 cvc4_option(ENABLE_MUZZLE "Suppress ALL non-result output")
123 cvc4_option(ENABLE_PROOFS "Enable proof support")
124 cvc4_option(ENABLE_STATISTICS "Enable statistics")
125 cvc4_option(ENABLE_TRACING "Enable tracing")
126 cvc4_option(ENABLE_UNIT_TESTING "Enable unit testing")
127 cvc4_option(ENABLE_VALGRIND "Enable valgrind instrumentation")
128 cvc4_option(ENABLE_SHARED "Build as shared library")
129 cvc4_option(ENABLE_STATIC_BINARY
130 "Build static binaries with statically linked system libraries")
131 # >> 2-valued: ON OFF
132 # > for options where we don't need to detect if set by user (default: OFF)
133 option(ENABLE_BEST "Enable dependencies known to give best performance")
134 option(ENABLE_COVERAGE "Enable support for gcov coverage testing")
135 option(ENABLE_DEBUG_CONTEXT_MM "Enable the debug context memory manager")
136 option(ENABLE_PROFILING "Enable support for gprof profiling")
137
138 # Optional dependencies
139 #
140 # >> 3-valued: IGNORE ON OFF
141 # > allows to detect if set by user (default: IGNORE)
142 # > only necessary for options set for ENABLE_BEST
143 cvc4_option(USE_ABC "Use ABC for AIG bit-blasting")
144 cvc4_option(USE_CADICAL "Use CaDiCaL SAT solver")
145 cvc4_option(USE_CLN "Use CLN instead of GMP")
146 cvc4_option(USE_CRYPTOMINISAT "Use CryptoMiniSat SAT solver")
147 cvc4_option(USE_GLPK "Use GLPK simplex solver")
148 cvc4_option(USE_KISSAT "Use Kissat SAT solver")
149 cvc4_option(USE_EDITLINE "Use Editline for better interactive support")
150 # >> 2-valued: ON OFF
151 # > for options where we don't need to detect if set by user (default: OFF)
152 option(USE_DRAT2ER "Include drat2er for making eager BV proofs")
153 option(USE_LFSC "Use LFSC proof checker")
154 option(USE_POLY "Use LibPoly for polynomial arithmetic")
155 option(USE_SYMFPU "Use SymFPU for floating point support")
156 option(USE_PYTHON2 "Force Python 2 (deprecated)")
157
158 # Custom install directories for dependencies
159 # If no directory is provided by the user, we first check if the dependency was
160 # installed via the corresponding contrib/get-* script and if not found, we
161 # check the intalled system version. If the user provides a directory we
162 # immediately fail if the dependency was not found at the specified location.
163 set(ABC_DIR "" CACHE STRING "Set ABC install directory")
164 set(ANTLR_DIR "" CACHE STRING "Set ANTLR3 install directory")
165 set(CADICAL_DIR "" CACHE STRING "Set CaDiCaL install directory")
166 set(CRYPTOMINISAT_DIR "" CACHE STRING "Set CryptoMiniSat install directory")
167 set(CXXTEST_DIR "" CACHE STRING "Set CxxTest install directory")
168 set(DRAT2ER_DIR "" CACHE STRING "Set drat2er install directory")
169 set(GLPK_DIR "" CACHE STRING "Set GLPK install directory")
170 set(GMP_DIR "" CACHE STRING "Set GMP install directory")
171 set(KISSAT_DIR "" CACHE STRING "Set Kissat install directory")
172 set(LFSC_DIR "" CACHE STRING "Set LFSC install directory")
173 set(POLY_DIR "" CACHE STRING "Set LibPoly install directory")
174 set(SYMFPU_DIR "" CACHE STRING "Set SymFPU install directory")
175
176 # Prepend binaries with prefix on make install
177 set(PROGRAM_PREFIX "" CACHE STRING "Program prefix on make install")
178
179 # Supprted language bindings based on new C++ API
180 option(BUILD_BINDINGS_PYTHON "Build Python bindings based on new C++ API ")
181 option(BUILD_BINDINGS_JAVA "Build Java bindings based on new C++ API ")
182
183 # Build limitations
184 option(BUILD_LIB_ONLY "Only build the library")
185
186 #-----------------------------------------------------------------------------#
187 # Internal cmake variables
188
189 set(OPTIMIZATION_LEVEL 3)
190 set(GPL_LIBS "")
191
192 #-----------------------------------------------------------------------------#
193 # Determine number of threads available, used to configure (default) parallel
194 # execution of custom test targets (can be overriden with ARGS=-jN).
195
196 include(ProcessorCount)
197 ProcessorCount(CTEST_NTHREADS)
198 if(CTEST_NTHREADS EQUAL 0)
199 set(CTEST_NTHREADS 1)
200 endif()
201
202 #-----------------------------------------------------------------------------#
203 # Build types
204
205 # Note: Module CodeCoverage requires the name of the debug build to conform
206 # to cmake standards (first letter uppercase).
207 set(BUILD_TYPES Production Debug Testing Competition)
208
209 if(ENABLE_ASAN OR ENABLE_UBSAN OR ENABLE_TSAN)
210 set(CMAKE_BUILD_TYPE Debug)
211 endif()
212
213 # Set the default build type to Production
214 if(NOT CMAKE_BUILD_TYPE)
215 set(CMAKE_BUILD_TYPE
216 Production CACHE STRING "Options are: ${BUILD_TYPES}" FORCE)
217 # Provide drop down menu options in cmake-gui
218 set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${BUILD_TYPES})
219 endif()
220
221 # Check if specified build type is valid.
222 list(FIND BUILD_TYPES ${CMAKE_BUILD_TYPE} FOUND_BUILD_TYPE)
223 if(${FOUND_BUILD_TYPE} EQUAL -1)
224 message(FATAL_ERROR
225 "'${CMAKE_BUILD_TYPE}' is not a valid build type. "
226 "Available builds are: ${BUILD_TYPES}")
227 endif()
228
229 message(STATUS "Building ${CMAKE_BUILD_TYPE} build")
230 include(Config${CMAKE_BUILD_TYPE})
231
232 #-----------------------------------------------------------------------------#
233 # Compiler flags
234
235 add_check_c_cxx_flag("-O${OPTIMIZATION_LEVEL}")
236 add_check_c_cxx_flag("-Wall")
237 add_check_c_cxx_flag("-Werror")
238 add_check_c_cxx_flag("-Wno-unused-private-field")
239 add_check_c_flag("-fexceptions")
240 add_check_cxx_flag("-Wsuggest-override")
241 add_check_cxx_flag("-Wnon-virtual-dtor")
242 add_check_c_cxx_flag("-Wimplicit-fallthrough")
243 add_check_c_cxx_flag("-Wshadow")
244
245 # Temporarily disable -Wclass-memaccess to suppress 'no trivial copy-assignment'
246 # cdlist.h warnings. Remove when fixed.
247 add_check_cxx_flag("-Wno-class-memaccess")
248
249 if (WIN32)
250 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--stack,100000000")
251 endif ()
252
253 #-----------------------------------------------------------------------------#
254 # Use ld.gold if available
255
256 execute_process(COMMAND ${CMAKE_C_COMPILER}
257 -fuse-ld=gold
258 -Wl,--version ERROR_QUIET OUTPUT_VARIABLE LD_VERSION)
259 if ("${LD_VERSION}" MATCHES "GNU gold")
260 string(APPEND CMAKE_EXE_LINKER_FLAGS " -fuse-ld=gold")
261 string(APPEND CMAKE_SHARED_LINKER_FLAGS " -fuse-ld=gold")
262 string(APPEND CMAKE_MODULE_LINKER_FLAGS " -fuse-ld=gold")
263 message(STATUS "Using GNU gold linker.")
264 endif ()
265
266 #-----------------------------------------------------------------------------#
267 # Option defaults (three-valued options (cvc4_option(...)))
268 #
269 # These options are only set if their value is IGNORE. Otherwise, the user
270 # already set the option, which we don't want to overwrite.
271
272 if(ENABLE_STATIC_BINARY)
273 cvc4_set_option(ENABLE_SHARED OFF)
274 else()
275 cvc4_set_option(ENABLE_SHARED ON)
276 endif()
277
278 #-----------------------------------------------------------------------------#
279 # Set options for best configuration
280
281 if(ENABLE_BEST)
282 cvc4_set_option(USE_ABC ON)
283 cvc4_set_option(USE_CADICAL ON)
284 cvc4_set_option(USE_CLN ON)
285 cvc4_set_option(USE_CRYPTOMINISAT ON)
286 cvc4_set_option(USE_GLPK ON)
287 cvc4_set_option(USE_EDITLINE ON)
288 endif()
289
290 # Only enable unit testing if assertions are enabled. Otherwise, unit tests
291 # that expect AssertionException to be thrown will fail.
292 if(NOT ENABLE_ASSERTIONS)
293 message(WARNING "Disabling unit tests since assertions are disabled.")
294 set(ENABLE_UNIT_TESTING OFF)
295 endif()
296
297 #-----------------------------------------------------------------------------#
298 # Shared/static libraries
299 #
300 # This needs to be set before any find_package(...) command since we want to
301 # search for static libraries with suffix .a.
302
303 if(ENABLE_SHARED)
304 set(BUILD_SHARED_LIBS ON)
305 if(ENABLE_STATIC_BINARY)
306 set(ENABLE_STATIC_BINARY OFF)
307 message(WARNING "Disabling static binary since shared build is enabled.")
308 endif()
309
310 # Embed the installation prefix as an RPATH in the executable such that the
311 # linker can find our libraries (such as libcvc4parser) when executing the
312 # cvc4 binary. This is for example useful when installing CVC4 with a custom
313 # prefix on macOS (e.g. when using homebrew in a non-standard directory). If
314 # we do not set this option, then the linker will not be able to find the
315 # required libraries when trying to run CVC4.
316 #
317 # Also embed the installation prefix of the installed contrib libraries as an
318 # RPATH. This allows to install a dynamically linked binary that depends on
319 # dynamically linked libraries. This is dangerous, as the installed binary
320 # breaks if the contrib library is removed or changes in other ways, we thus
321 # print a big warning and only allow if installing to a custom installation
322 # prefix.
323 #
324 # More information on RPATH in CMake:
325 # https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling
326 set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR};${PROJECT_SOURCE_DIR}/deps/install/lib")
327 else()
328 # When building statically, we *only* want static archives/libraries
329 if (WIN32)
330 set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a)
331 else()
332 set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
333 endif()
334 set(BUILD_SHARED_LIBS OFF)
335 cvc4_set_option(ENABLE_STATIC_BINARY ON)
336
337 # Never build unit tests as static binaries, otherwise we'll end up with
338 # ~300MB per unit test.
339 if(ENABLE_UNIT_TESTING)
340 message(WARNING "Disabling unit tests since static build is enabled.")
341 set(ENABLE_UNIT_TESTING OFF)
342 endif()
343
344 if (BUILD_BINDINGS_PYTHON)
345 message(FATAL_ERROR "Building Python bindings is not possible "
346 "when building statically")
347 endif()
348 endif()
349
350 #-----------------------------------------------------------------------------#
351 # Enable the ctest testing framework
352
353 # This needs to be enabled here rather than in subdirectory test in order to
354 # allow calling ctest from the root build directory.
355 enable_testing()
356
357 #-----------------------------------------------------------------------------#
358 # Check GCC version.
359 #
360 # GCC version 4.5.1 builds MiniSat incorrectly with -O2, which results in
361 # incorrect answers.
362
363 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
364 execute_process(
365 COMMAND ${CMAKE_CXX_COMPILER} -dumpversion
366 OUTPUT_VARIABLE GCC_VERSION
367 OUTPUT_STRIP_TRAILING_WHITESPACE)
368 if(GCC_VERSION VERSION_EQUAL "4.5.1")
369 message(FATAL_ERROR
370 "GCC 4.5.1's optimizer is known to build MiniSat incorrectly "
371 "(and by extension CVC4).")
372 endif()
373 endif()
374
375 #-----------------------------------------------------------------------------#
376 # Check options, find packages and configure build.
377
378 if(USE_PYTHON2)
379 find_package(PythonInterp 2.7 REQUIRED)
380 else()
381 find_package(PythonInterp 3 REQUIRED)
382 endif()
383
384 find_package(GMP REQUIRED)
385
386 if(ENABLE_ASAN)
387 # -fsanitize=address requires CMAKE_REQUIRED_FLAGS to be explicitely set,
388 # otherwise the -fsanitize=address check will fail while linking.
389 set(CMAKE_REQUIRED_FLAGS -fsanitize=address)
390 add_required_c_cxx_flag("-fsanitize=address")
391 unset(CMAKE_REQUIRED_FLAGS)
392 add_required_c_cxx_flag("-fno-omit-frame-pointer")
393 add_check_c_cxx_flag("-fsanitize-recover=address")
394 endif()
395
396 if(ENABLE_UBSAN)
397 add_required_c_cxx_flag("-fsanitize=undefined")
398 add_definitions(-DCVC4_USE_UBSAN)
399 endif()
400
401 if(ENABLE_TSAN)
402 # -fsanitize=thread requires CMAKE_REQUIRED_FLAGS to be explicitely set,
403 # otherwise the -fsanitize=thread check will fail while linking.
404 set(CMAKE_REQUIRED_FLAGS -fsanitize=thread)
405 add_required_c_cxx_flag("-fsanitize=thread")
406 unset(CMAKE_REQUIRED_FLAGS)
407 endif()
408
409 if(ENABLE_ASSERTIONS)
410 add_definitions(-DCVC4_ASSERTIONS)
411 else()
412 add_definitions(-DNDEBUG)
413 endif()
414
415 if(ENABLE_COVERAGE)
416 include(CodeCoverage)
417 APPEND_COVERAGE_COMPILER_FLAGS()
418 add_definitions(-DCVC4_COVERAGE)
419 # Note: The ctest command returns a non-zero exit code if tests fail or run
420 # into a timeout. As a consequence, the coverage report is not generated. To
421 # prevent this we always return with exit code 0 after the ctest command has
422 # finished.
423 setup_target_for_coverage_gcovr_html(
424 NAME coverage
425 EXECUTABLE
426 ctest -j${CTEST_NTHREADS} -LE "example"
427 --output-on-failure $$ARGS || exit 0
428 DEPENDS
429 build-tests)
430 endif()
431
432 if(ENABLE_DEBUG_CONTEXT_MM)
433 add_definitions(-DCVC4_DEBUG_CONTEXT_MEMORY_MANAGER)
434 endif()
435
436 if(ENABLE_DEBUG_SYMBOLS)
437 add_check_c_cxx_flag("-ggdb3")
438 endif()
439
440 if(ENABLE_COMP_INC_TRACK)
441 add_definitions(-DCVC4_SMTCOMP_APPLICATION_TRACK)
442 endif()
443
444 if(ENABLE_MUZZLE)
445 add_definitions(-DCVC4_MUZZLE)
446 endif()
447
448 if(ENABLE_DUMPING)
449 add_definitions(-DCVC4_DUMPING)
450 endif()
451
452 if(ENABLE_PROFILING)
453 add_definitions(-DCVC4_PROFILING)
454 add_check_c_cxx_flag("-pg")
455 endif()
456
457 if(ENABLE_PROOFS)
458 set(RUN_REGRESSION_ARGS ${RUN_REGRESSION_ARGS} --enable-proof)
459 add_definitions(-DCVC4_PROOF)
460 endif()
461
462 if(ENABLE_TRACING)
463 add_definitions(-DCVC4_TRACING)
464 endif()
465
466 if(ENABLE_STATISTICS)
467 add_definitions(-DCVC4_STATISTICS_ON)
468 endif()
469
470 if(ENABLE_VALGRIND)
471 find_package(Valgrind REQUIRED)
472 add_definitions(-DCVC4_VALGRIND)
473 endif()
474
475 if(USE_ABC)
476 find_package(ABC REQUIRED)
477 add_definitions(-DCVC4_USE_ABC ${ABC_ARCH_FLAGS})
478 endif()
479
480 if(USE_CADICAL)
481 find_package(CaDiCaL REQUIRED)
482 add_definitions(-DCVC4_USE_CADICAL)
483 endif()
484
485 if(USE_CLN)
486 set(GPL_LIBS "${GPL_LIBS} cln")
487 find_package(CLN 1.2.2 REQUIRED)
488 set(CVC4_USE_CLN_IMP 1)
489 set(CVC4_USE_GMP_IMP 0)
490 else()
491 set(CVC4_USE_CLN_IMP 0)
492 set(CVC4_USE_GMP_IMP 1)
493 endif()
494
495 if(USE_CRYPTOMINISAT)
496 # CryptoMiniSat requires pthreads support
497 set(THREADS_PREFER_PTHREAD_FLAG ON)
498 find_package(Threads REQUIRED)
499 if(THREADS_HAVE_PTHREAD_ARG)
500 add_c_cxx_flag(-pthread)
501 endif()
502 find_package(CryptoMiniSat REQUIRED)
503 add_definitions(-DCVC4_USE_CRYPTOMINISAT)
504 endif()
505
506 if(USE_DRAT2ER)
507 find_package(Drat2Er REQUIRED)
508 add_definitions(-DCVC4_USE_DRAT2ER)
509 endif()
510
511 if(USE_GLPK)
512 set(GPL_LIBS "${GPL_LIBS} glpk")
513 find_package(GLPK REQUIRED)
514 add_definitions(-DCVC4_USE_GLPK)
515 endif()
516
517 if(USE_KISSAT)
518 find_package(Kissat REQUIRED)
519 add_definitions(-DCVC4_USE_KISSAT)
520 endif()
521
522 if(USE_LFSC)
523 set(RUN_REGRESSION_ARGS ${RUN_REGRESSION_ARGS} --with-lfsc)
524 find_package(LFSC REQUIRED)
525 add_definitions(-DCVC4_USE_LFSC)
526 endif()
527
528 if(USE_POLY)
529 find_package(Poly REQUIRED)
530 add_definitions(-DCVC4_USE_POLY)
531 set(CVC4_USE_POLY_IMP 1)
532 else()
533 set(CVC4_USE_POLY_IMP 0)
534 endif()
535
536 if(USE_EDITLINE)
537 find_package(Editline REQUIRED)
538 set(HAVE_LIBEDITLINE 1)
539 if(Editline_COMPENTRY_FUNC_RETURNS_CHARPTR)
540 set(EDITLINE_COMPENTRY_FUNC_RETURNS_CHARP 1)
541 endif()
542 endif()
543
544 if(USE_SYMFPU)
545 find_package(SymFPU REQUIRED)
546 add_definitions(-DCVC4_USE_SYMFPU)
547 set(CVC4_USE_SYMFPU 1)
548 else()
549 set(CVC4_USE_SYMFPU 0)
550 endif()
551
552 if(GPL_LIBS)
553 if(NOT ENABLE_GPL)
554 message(FATAL_ERROR
555 "Bad configuration detected: BSD-licensed code only, but also requested "
556 "GPLed libraries: ${GPL_LIBS}")
557 endif()
558 set(CVC4_GPL_DEPS 1)
559 endif()
560
561 #-----------------------------------------------------------------------------#
562 # Generate CVC4's cvc4autoconfig.h header
563
564 include(ConfigureCVC4)
565 if(NOT ENABLE_SHARED)
566 set(CVC4_STATIC_BUILD ON)
567 endif()
568 configure_file(cvc4autoconfig.h.in cvc4autoconfig.h)
569 unset(CVC4_STATIC_BUILD)
570 include_directories(${CMAKE_CURRENT_BINARY_DIR})
571
572 #-----------------------------------------------------------------------------#
573 # Add subdirectories
574
575 # signatures needs to come before src since it adds source files to libcvc4.
576 if(ENABLE_PROOFS)
577 add_subdirectory(proofs/signatures)
578 endif()
579
580 add_subdirectory(doc)
581 add_subdirectory(src)
582 add_subdirectory(test)
583
584 if(BUILD_BINDINGS_PYTHON)
585 set(BUILD_BINDINGS_PYTHON_VERSION ${PYTHON_VERSION_MAJOR})
586 add_subdirectory(src/api/python)
587 endif()
588
589 if(BUILD_BINDINGS_JAVA)
590 message(FATAL_ERROR
591 "Java bindings for the new API are not implemented yet.")
592 endif()
593
594 #-----------------------------------------------------------------------------#
595 # Package configuration
596 #
597 # Export CVC4 targets to support find_package(CVC4) in other cmake projects.
598
599 include(CMakePackageConfigHelpers)
600
601 # If we install a dynamically linked binary that also uses dynamically used
602 # libraries from deps/install/lib, we need to be cautious. Changing these
603 # shared libraries from deps/install/lib most probably breaks the binary.
604 # We only allow such an installation for custom installation prefixes
605 # (in the assumption that only reasonably experienced users use this and
606 # also that custom installation prefixes are not used for longer periods of
607 # time anyway). Also, we print a big warning with further instructions.
608 if(NOT ENABLE_STATIC_BINARY)
609 # Get the libraries that cvc4 links against
610 get_target_property(libs cvc4 INTERFACE_LINK_LIBRARIES)
611 set(LIBS_SHARED_FROM_DEPS "")
612 foreach(lib ${libs})
613 # Filter out those that are linked dynamically and come from deps/install
614 if(lib MATCHES ".*/deps/install/lib/.*\.so")
615 list(APPEND LIBS_SHARED_FROM_DEPS ${lib})
616 endif()
617 endforeach()
618 list(LENGTH LIBS_SHARED_FROM_DEPS list_len)
619 # Check if we actually use such "dangerous" libraries
620 if(list_len GREATER 0)
621 # Print a generic warning
622 install(CODE "message(WARNING \"You are installing a dynamically linked \
623 binary of CVC4 which may be a problem if you are using any dynamically \
624 linked third-party library that you obtained through one of the \
625 contrib/get-xxx scripts. The binary uses the rpath mechanism to find these \
626 locally, hence executing such a contrib script removing the \
627 \\\"deps/install\\\" folder most probably breaks the installed binary! \
628 Consider installing the dynamically linked dependencies on your system \
629 manually or link cvc4 statically.\")")
630 # Print the libraries in question
631 foreach(lib ${LIBS_SHARED_FROM_DEPS})
632 install(CODE "message(WARNING \"The following library is used by the cvc4 binary: ${lib}\")")
633 endforeach()
634 # Check if we use a custom installation prefix
635 if(CMAKE_INSTALL_PREFIX STREQUAL "/usr/local")
636 install(CODE "message(FATAL_ERROR \"To avoid installing a \
637 soon-to-be-broken binary, system-wide installation is disabled if the \
638 binary depends on locally-built shared libraries.\")")
639 else()
640 install(CODE "message(WARNING \"You have selected a custom install \
641 directory ${CMAKE_INSTALL_PREFIX}, so we expect you understood the \
642 previous warning and know what you are doing.\")")
643 endif()
644 endif()
645 endif()
646
647 install(EXPORT cvc4-targets
648 FILE CVC4Targets.cmake
649 NAMESPACE CVC4::
650 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CVC4)
651
652 configure_package_config_file(
653 ${CMAKE_SOURCE_DIR}/cmake/CVC4Config.cmake.in
654 ${CMAKE_BINARY_DIR}/cmake/CVC4Config.cmake
655 INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CVC4
656 PATH_VARS CMAKE_INSTALL_LIBDIR
657 )
658
659 write_basic_package_version_file(
660 ${CMAKE_CURRENT_BINARY_DIR}/CVC4ConfigVersion.cmake
661 VERSION ${CVC4_RELEASE_STRING}
662 COMPATIBILITY ExactVersion
663 )
664
665 install(FILES
666 ${CMAKE_BINARY_DIR}/cmake/CVC4Config.cmake
667 ${CMAKE_BINARY_DIR}/CVC4ConfigVersion.cmake
668 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CVC4
669 )
670
671
672 #-----------------------------------------------------------------------------#
673 # Print build configuration
674
675 # Convert build type to lower case.
676 string(TOLOWER ${CMAKE_BUILD_TYPE} CVC4_BUILD_PROFILE_STRING)
677
678 # Get all definitions added via add_definitions.
679 get_directory_property(CVC4_DEFINITIONS COMPILE_DEFINITIONS)
680 string(REPLACE ";" " " CVC4_DEFINITIONS "${CVC4_DEFINITIONS}")
681
682 message("CVC4 ${CVC4_RELEASE_STRING}")
683 message("")
684 if(ENABLE_COMP_INC_TRACK)
685 message("Build profile : ${CVC4_BUILD_PROFILE_STRING} (incremental)")
686 else()
687 message("Build profile : ${CVC4_BUILD_PROFILE_STRING}")
688 endif()
689 message("")
690 print_config("GPL :" ENABLE_GPL)
691 print_config("Best configuration :" ENABLE_BEST)
692 print_config("Optimization level :" OPTIMIZATION_LEVEL)
693 message("")
694 print_config("Assertions :" ENABLE_ASSERTIONS)
695 print_config("Debug symbols :" ENABLE_DEBUG_SYMBOLS)
696 print_config("Debug context mem mgr :" ENABLE_DEBUG_CONTEXT_MM)
697 message("")
698 print_config("Dumping :" ENABLE_DUMPING)
699 print_config("Muzzle :" ENABLE_MUZZLE)
700 print_config("Proofs :" ENABLE_PROOFS)
701 print_config("Statistics :" ENABLE_STATISTICS)
702 print_config("Tracing :" ENABLE_TRACING)
703 message("")
704 print_config("ASan :" ENABLE_ASAN)
705 print_config("UBSan :" ENABLE_UBSAN)
706 print_config("TSan :" ENABLE_TSAN)
707 print_config("Coverage (gcov) :" ENABLE_COVERAGE)
708 print_config("Profiling (gprof) :" ENABLE_PROFILING)
709 print_config("Unit tests :" ENABLE_UNIT_TESTING)
710 print_config("Valgrind :" ENABLE_VALGRIND)
711 message("")
712 print_config("Shared libs :" ENABLE_SHARED)
713 print_config("Static binary :" ENABLE_STATIC_BINARY)
714 print_config("Python bindings :" BUILD_BINDINGS_PYTHON)
715 print_config("Java bindings :" BUILD_BINDINGS_JAVA)
716 print_config("Python2 :" USE_PYTHON2)
717 message("")
718 print_config("ABC :" USE_ABC)
719 print_config("CaDiCaL :" USE_CADICAL)
720 print_config("CryptoMiniSat :" USE_CRYPTOMINISAT)
721 print_config("drat2er :" USE_DRAT2ER)
722 print_config("GLPK :" USE_GLPK)
723 print_config("Kissat :" USE_KISSAT)
724 print_config("LFSC :" USE_LFSC)
725 print_config("LibPoly :" USE_POLY)
726 message("")
727 print_config("BUILD_LIB_ONLY :" BUILD_LIB_ONLY)
728
729 if(CVC4_USE_CLN_IMP)
730 message("MP library : cln")
731 else()
732 message("MP library : gmp")
733 endif()
734 print_config("Editline :" ${USE_EDITLINE})
735 print_config("SymFPU :" ${USE_SYMFPU})
736 message("")
737 if(ABC_DIR)
738 message("ABC dir : ${ABC_DIR}")
739 endif()
740 if(ANTLR_DIR)
741 message("ANTLR dir : ${ANTLR_DIR}")
742 endif()
743 if(CADICAL_DIR)
744 message("CADICAL dir : ${CADICAL_DIR}")
745 endif()
746 if(CRYPTOMINISAT_DIR)
747 message("CRYPTOMINISAT dir : ${CRYPTOMINISAT_DIR}")
748 endif()
749 if(DRAT2ER_DIR)
750 message("DRAT2ER dir : ${DRAT2ER_DIR}")
751 endif()
752 if(GLPK_DIR)
753 message("GLPK dir : ${GLPK_DIR}")
754 endif()
755 if(GMP_DIR)
756 message("GMP dir : ${GMP_DIR}")
757 endif()
758 if(KISSAT_DIR)
759 message("KISSAT dir : ${KISSAT_DIR}")
760 endif()
761 if(LFSC_DIR)
762 message("LFSC dir : ${LFSC_DIR}")
763 endif()
764 if(POLY_DIR)
765 message("LibPoly dir : ${POLY_DIR}")
766 endif()
767 if(SYMFPU_DIR)
768 message("SYMFPU dir : ${SYMFPU_DIR}")
769 endif()
770 message("")
771 message("CPPLAGS (-D...) : ${CVC4_DEFINITIONS}")
772 message("CXXFLAGS : ${CMAKE_CXX_FLAGS}")
773 message("CFLAGS : ${CMAKE_C_FLAGS}")
774 message("Linker flags : ${CMAKE_EXE_LINKER_FLAGS}")
775 message("")
776 message("Install prefix : ${CMAKE_INSTALL_PREFIX}")
777 message("")
778
779 if(GPL_LIBS)
780 message(
781 "CVC4 license : ${Yellow}GPLv3 (due to optional libraries; see below)${ResetColor}"
782 "\n"
783 "\n"
784 "Please note that CVC4 will be built against the following GPLed libraries:"
785 "\n"
786 "${GPL_LIBS}"
787 "\n"
788 "As these libraries are covered under the GPLv3, so is this build of CVC4."
789 "\n"
790 "CVC4 is also available to you under the terms of the (modified) BSD license."
791 "\n"
792 "If you prefer to license CVC4 under those terms, please configure CVC4 to"
793 "\n"
794 "disable all optional GPLed library dependencies (-DENABLE_BSD_ONLY=ON)."
795 )
796 else()
797 message(
798 "CVC4 license : modified BSD"
799 "\n"
800 "\n"
801 "Note that this configuration is NOT built against any GPL'ed libraries, so"
802 "\n"
803 "it is covered by the (modified) BSD license. This is, however, not the best"
804 "\n"
805 "performing configuration of CVC4. To build against GPL'ed libraries which"
806 "\n"
807 "improve CVC4's performance, re-configure with '-DENABLE_GPL -DENABLE_BEST'."
808 )
809 endif()
810
811 if("${CMAKE_GENERATOR}" STREQUAL "Ninja")
812 set(BUILD_COMMAND_NAME "ninja")
813 else()
814 set(BUILD_COMMAND_NAME "make")
815 endif()
816
817 message("")
818 message("Now just type '${BUILD_COMMAND_NAME}', "
819 "followed by '${BUILD_COMMAND_NAME} check' "
820 "or '${BUILD_COMMAND_NAME} install'.")
821 message("")