]> www.ginac.de Git - cln.git/blob - cmake/modules/GMPLimbSize.cmake
CLN can be built with CMake
[cln.git] / cmake / modules / GMPLimbSize.cmake
1
2 include(CheckCXXSourceCompiles)
3
4 set(_save_required_libraries ${CMAKE_REQUIRED_LIBRARIES})
5 set(_save_required_includes ${CMAKE_REQUIRED_INCLUDES})
6 set(CMAKE_REQUIRED_LIBRARIES "${GMP_LIBRARIES} ${CMAKE_REQUIRED_LIBRARIES}")
7 set(CMAKE_REQUIRED_INCLUDES "${GMP_INCLUDE_DIR} ${CMAKE_REQUIRED_INCLUDES}")
8
9 CHECK_CXX_SOURCE_COMPILES("
10         #include <gmp.h>
11         template<bool COND> struct Static_Assert;
12         template<> struct Static_Assert<true> { };
13         #if defined(__GMP_BITS_PER_MP_LIB)
14         Static_Assert<8*sizeof(mp_limb_t) == __GMP_BITS_PER_MP_LIB> check;
15         int main() { return 0; }
16         #endif
17         "
18         cl_gmp_has_nails
19 )
20 if (${cl_gmp_has_nails})
21     message(SEND_ERROR "nails in MP limbs are not supported.")
22 endif()
23
24 CHECK_CXX_SOURCE_COMPILES("
25         #include <gmp.h>
26         template<bool COND> struct Static_Assert;
27         template<> struct Static_Assert<true> { };
28         Static_Assert<sizeof(mp_limb_t) == sizeof(long)> check;
29         int main() { return 0; }
30         "
31         mp_limb_t_is_long
32 )
33
34 CHECK_CXX_SOURCE_COMPILES("
35         #include <gmp.h>
36         template<bool COND> struct Static_Assert;
37         template<> struct Static_Assert<true> { };
38         Static_Assert<sizeof(mp_limb_t) == sizeof(long long)> check;
39         int main() { return 0; }
40         "
41         mp_limb_t_is_long_long
42 )
43 set(CMAKE_REQUIRED_INCLUDES ${_save_required_includes})
44 set(CMAKE_REQUIRED_LIBRARIES ${_save_required_libraries})
45
46 if (mp_limb_t_is_long)
47     message(STATUS "sizeof(mp_limb_t) == sizeof(long)")
48     set(GMP_DEMANDS_UINTD_LONG 1 CACHE INTERNAL "sizeof(mp_limb_t) == sizeof(long)")
49 else (mp_limb_t_is_long)
50     if (mp_limb_t_is_long_long)
51         message(STATUS "sizeof(mp_limb_t) == sizeof(long long)")
52         set(GMP_DEMANDS_UINTD_LONG_LONG 1 CACHE INTERNAL "sizeof(mp_limb_t) == sizeof(long long)")
53     else()
54         message(SEND_ERROR "Don't know which C integer type has sizeof(mp_limb_t)")
55     endif()
56 endif (mp_limb_t_is_long)