Remove linking against RT (#7257)
[cvc5.git] / cmake / ConfigureCvc5.cmake
1 ###############################################################################
2 # Top contributors (to current version):
3 # Mathias Preiner, Gereon Kremer, Makai Mann
4 #
5 # This file is part of the cvc5 project.
6 #
7 # Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
8 # in the top-level source directory and their institutional affiliations.
9 # All rights reserved. See the file COPYING in the top-level source
10 # directory for licensing information.
11 # #############################################################################
12 ##
13
14 include(CheckCXXSourceCompiles)
15 include(CheckIncludeFile)
16 include(CheckIncludeFileCXX)
17 include(CheckSymbolExists)
18 include(CheckLibraryExists)
19
20 # Check whether "long" and "int64_t" are distinct types w.r.t. overloading.
21 # Even if they have the same size, they can be distinct, and some platforms
22 # can have problems with ambiguous function calls when auto-converting
23 # int64_t to long, and others will complain if you overload a function
24 # that takes an int64_t with one that takes a long (giving a redefinition
25 # error). So we have to keep both happy. Probably the same underlying
26 # issue as the hash specialization below, but let's check separately
27 # for flexibility.
28 check_cxx_source_compiles(
29 "
30 #include <stdint.h>
31 void foo(long) {}
32 void foo(int64_t) {}
33 int main() { return 0; }
34 "
35 CVC5_NEED_INT64_T_OVERLOADS
36 )
37 if(NOT CVC5_NEED_INT64_T_OVERLOADS)
38 set(CVC5_NEED_INT64_T_OVERLOADS 0)
39 endif()
40
41 # Check to see if this version/architecture of GNU C++ explicitly
42 # instantiates std::hash<uint64_t> or not. Some do, some don't.
43 # See src/util/hash.h.
44 check_cxx_source_compiles(
45 "
46 #include <cstdint>
47 #include <functional>
48 namespace std { template<> struct hash<uint64_t> {}; }
49 int main() { return 0; }
50 "
51 CVC5_NEED_HASH_UINT64_T_OVERLOAD
52 )
53 if(CVC5_NEED_HASH_UINT64_T_OVERLOAD)
54 add_definitions(-DCVC5_NEED_HASH_UINT64_T)
55 endif()
56
57 check_include_file(unistd.h HAVE_UNISTD_H)
58 check_include_file_cxx(ext/stdio_filebuf.h HAVE_EXT_STDIO_FILEBUF_H)
59
60 # For Windows builds check if clock_gettime is available via -lpthread
61 # (pthread_time.h).
62 if(CVC5_WINDOWS_BUILD)
63 set(CMAKE_REQUIRED_FLAGS -pthread)
64 check_symbol_exists(clock_gettime "time.h" HAVE_CLOCK_GETTIME)
65 unset(CMAKE_REQUIRED_FLAGS)
66 if(HAVE_CLOCK_GETTIME)
67 add_c_cxx_flag(-pthread)
68 endif()
69 else()
70 check_symbol_exists(clock_gettime "time.h" HAVE_CLOCK_GETTIME)
71 endif()
72 check_symbol_exists(ffs "strings.h" HAVE_FFS)
73 check_symbol_exists(optreset "getopt.h" HAVE_DECL_OPTRESET)
74 check_symbol_exists(sigaltstack "signal.h" HAVE_SIGALTSTACK)
75 check_symbol_exists(strerror_r "string.h" HAVE_STRERROR_R)
76 check_symbol_exists(strtok_r "string.h" HAVE_STRTOK_R)
77 check_symbol_exists(setitimer "sys/time.h" HAVE_SETITIMER)
78
79 # on non-POSIX systems, time limit is implemented with threads
80 if(NOT HAVE_SETITIMER)
81 find_package(Threads REQUIRED)
82 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
83 endif()
84
85 # Determine if we have the POSIX (int) or GNU (char *) variant of strerror_r.
86 check_c_source_compiles(
87 "
88 #include <string.h>
89 int main(void)
90 {
91 char buf[1];
92 char c = *strerror_r(0, buf, 0);
93 return 0;
94 }
95 "
96 STRERROR_R_CHAR_P
97 )
98
99 # Defined if using the CLN multi-precision arithmetic library.
100 set(CVC5_CLN_IMP ${CVC5_USE_CLN_IMP})
101 # Defined if using the GMP multi-precision arithmetic library.
102 set(CVC5_GMP_IMP ${CVC5_USE_GMP_IMP})
103 # Defined if using the libpoly polynomial library.
104 set(CVC5_POLY_IMP ${CVC5_USE_POLY_IMP})
105 # Define the full name of this package.
106 set(CVC5_PACKAGE_NAME "${PROJECT_NAME}")