gmp.cmake 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. if(TARGET gmp::gmp)
  2. return()
  3. endif()
  4. # Download precompiled .dll on Windows
  5. if(WIN32)
  6. include(gmp_mpfr)
  7. # Find_package will look for our downloaded lib on Windows, and system-wide on Linux/macOS
  8. find_package(GMP REQUIRED)
  9. else()
  10. message(STATUS "Third-party: creating target 'gmp::gmp'")
  11. include(FetchContent)
  12. include(ProcessorCount)
  13. ProcessorCount(Ncpu)
  14. include(ExternalProject)
  15. set(prefix ${FETCHCONTENT_BASE_DIR}/gmp)
  16. set(gmp_INSTALL ${prefix}/install)
  17. set(gmp_LIB_DIR ${gmp_INSTALL}/lib)
  18. set(gmp_LIBRARY ${gmp_LIB_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gmp${CMAKE_STATIC_LIBRARY_SUFFIX})
  19. set(gmp_INCLUDE_DIR ${gmp_INSTALL}/include)
  20. ExternalProject_Add(gmp
  21. PREFIX ${prefix}
  22. URL https://gmplib.org/download/gmp/gmp-6.2.1.tar.xz
  23. URL_MD5 0b82665c4a92fd2ade7440c13fcaa42b
  24. UPDATE_DISCONNECTED true # need this to avoid constant rebuild
  25. PATCH_COMMAND
  26. curl "https://gmplib.org/repo/gmp/raw-rev/5f32dbc41afc" "|" git apply -v
  27. CONFIGURE_HANDLED_BY_BUILD ON # avoid constant reconfigure
  28. CONFIGURE_COMMAND
  29. ${prefix}/src/gmp/configure
  30. --disable-debug --disable-dependency-tracking --enable-cxx --with-pic
  31. --prefix=${gmp_INSTALL}
  32. --disable-shared
  33. BUILD_COMMAND make -j${Ncpu}
  34. INSTALL_COMMAND make -j${Ncpu} install
  35. INSTALL_DIR ${gmp_INSTALL}
  36. TEST_COMMAND ""
  37. BUILD_BYPRODUCTS ${gmp_LIBRARY}
  38. )
  39. ExternalProject_Get_Property(gmp SOURCE_DIR)
  40. set(gmp_LIBRARIES ${gmp_LIBRARY})
  41. add_library(gmp::gmp INTERFACE IMPORTED GLOBAL)
  42. file(MAKE_DIRECTORY ${gmp_INCLUDE_DIR}) # avoid race condition
  43. target_include_directories(gmp::gmp INTERFACE ${gmp_INCLUDE_DIR})
  44. target_link_libraries(gmp::gmp INTERFACE "${gmp_LIBRARIES}") # need the quotes to expand list
  45. add_dependencies(gmp::gmp gmp)
  46. endif()
  47. if(NOT TARGET gmp::gmp)
  48. message(FATAL_ERROR "Creation of target 'gmp::gmp' failed")
  49. endif()