cmake: Move PACKAGE_NAME to ConfigureCVC4, more cleanup.
[cvc5.git] / cmake / ConfigureCVC4.cmake
1 include(CheckCXXSourceCompiles)
2 include(CheckIncludeFile)
3 include(CheckIncludeFileCXX)
4 include(CheckSymbolExists)
5
6 # Check whether "long" and "int64_t" are distinct types w.r.t. overloading.
7 # Even if they have the same size, they can be distinct, and some platforms
8 # can have problems with ambiguous function calls when auto-converting
9 # int64_t to long, and others will complain if you overload a function
10 # that takes an int64_t with one that takes a long (giving a redefinition
11 # error). So we have to keep both happy. Probably the same underlying
12 # issue as the hash specialization below, but let's check separately
13 # for flexibility.
14 check_cxx_source_compiles(
15 "
16 #include <stdint.h>
17 void foo(long) {}
18 void foo(int64_t) {}
19 int main() { return 0; }
20 "
21 CVC4_NEED_INT64_T_OVERLOADS
22 )
23 if(NOT CVC4_NEED_INT64_T_OVERLOADS)
24 set(CVC4_NEED_INT64_T_OVERLOADS 0)
25 endif()
26
27 # Check to see if this version/architecture of GNU C++ explicitly
28 # instantiates std::hash<uint64_t> or not. Some do, some don't.
29 # See src/util/hash.h.
30 check_cxx_source_compiles(
31 "
32 #include <cstdint>
33 #include <functional>
34 namespace std { template<> struct hash<uint64_t> {}; }
35 int main() { return 0; }
36 "
37 CVC4_NEED_HASH_UINT64_T_OVERLOAD
38 )
39 if(CVC4_NEED_HASH_UINT64_T_OVERLOAD)
40 add_definitions(-DCVC4_NEED_HASH_UINT64_T)
41 endif()
42
43 check_include_file(unistd.h HAVE_UNISTD_H)
44 check_include_file_cxx(ext/stdio_filebuf.h HAVE_EXT_STDIO_FILEBUF_H)
45
46 # For Windows builds check if clock_gettime is available via -lpthread
47 # (pthread_time.h).
48 if(CVC4_WINDOWS_BUILD)
49 set(CMAKE_REQUIRED_FLAGS -pthread)
50 check_symbol_exists(clock_gettime "time.h" HAVE_CLOCK_GETTIME)
51 unset(CMAKE_REQUIRED_FLAGS)
52 if(HAVE_CLOCK_GETTIME)
53 add_c_cxx_flag(-pthread)
54 endif()
55 else()
56 check_symbol_exists(clock_gettime "time.h" HAVE_CLOCK_GETTIME)
57 endif()
58 check_symbol_exists(ffs "strings.h" HAVE_FFS)
59 check_symbol_exists(optreset "getopt.h" HAVE_DECL_OPTRESET)
60 check_symbol_exists(sigaltstack "signal.h" HAVE_SIGALTSTACK)
61 check_symbol_exists(strerror_r "string.h" HAVE_STRERROR_R)
62 check_symbol_exists(strtok_r "string.h" HAVE_STRTOK_R)
63
64 # Determine if we have the POSIX (int) or GNU (char *) variant of strerror_r.
65 check_c_source_compiles(
66 "
67 #include <string.h>
68 int main(void)
69 {
70 char buf[1];
71 char c = *strerror_r(0, buf, 0);
72 return 0;
73 }
74 "
75 STRERROR_R_CHAR_P
76 )
77
78 # Defined if using the CLN multi-precision arithmetic library.
79 set(CVC4_CLN_IMP ${CVC4_USE_CLN_IMP})
80 # Defined if using the GMP multi-precision arithmetic library.
81 set(CVC4_GMP_IMP ${CVC4_USE_GMP_IMP})
82 # Define the full name of this package.
83 set(PACKAGE_NAME "${PROJECT_NAME}")