mpfr.cmake 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Expects
  2. # gmp_INCLUDE_DIR
  3. # gmp_LIB_DIR
  4. # gmp_LIBRARIES
  5. if(TARGET mpfr::mpfr)
  6. return()
  7. endif()
  8. # Download precompiled .dll on Windows
  9. if(WIN32)
  10. include(gmp_mpfr)
  11. # Find_package will look for our downloaded lib on Windows, and system-wide on Linux/macOS
  12. find_package(MPFR REQUIRED)
  13. else()
  14. message(STATUS "Third-party: creating target 'mpfr::mpfr'")
  15. include(FetchContent)
  16. include(ProcessorCount)
  17. ProcessorCount(Ncpu)
  18. include(ExternalProject)
  19. set(prefix ${FETCHCONTENT_BASE_DIR}/mpfr)
  20. set(mpfr_INSTALL ${prefix}/install)
  21. set(mpfr_LIBRARY ${mpfr_INSTALL}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}mpfr${CMAKE_STATIC_LIBRARY_SUFFIX})
  22. set(mpfr_INCLUDE_DIR ${mpfr_INSTALL}/include)
  23. ExternalProject_Add(mpfr
  24. PREFIX ${prefix}
  25. DEPENDS gmp
  26. URL https://ftp.gnu.org/gnu/mpfr/mpfr-4.1.0.tar.xz
  27. URL_MD5 bdd3d5efba9c17da8d83a35ec552baef
  28. UPDATE_DISCONNECTED true # need this to avoid constant rebuild
  29. CONFIGURE_HANDLED_BY_BUILD ON # avoid constant reconfigure
  30. CONFIGURE_COMMAND
  31. ${prefix}/src/mpfr/configure
  32. --disable-debug --disable-dependency-tracking --disable-silent-rules --enable-cxx --with-pic
  33. --with-gmp-include=${gmp_INCLUDE_DIR} --with-gmp-lib=${gmp_LIB_DIR}
  34. --disable-shared
  35. --prefix=${mpfr_INSTALL}
  36. --disable-shared
  37. BUILD_COMMAND make -j${Ncpu}
  38. INSTALL_COMMAND make -j${Ncpu} install
  39. INSTALL_DIR ${mpfr_INSTALL}
  40. TEST_COMMAND ""
  41. BUILD_BYPRODUCTS ${mpfr_LIBRARY}
  42. )
  43. #PATCH_COMMAND curl "https://raw.githubusercontent.com/Homebrew/formula-patches/03cf8088210822aa2c1ab544ed58ea04c897d9c4/libtool/configure-big_sur.diff" "|" sed -e "s/configure.orig/configure/g" "|" git apply -v
  44. ExternalProject_Get_Property(mpfr SOURCE_DIR)
  45. set(mpfr_LIBRARIES ${mpfr_LIBRARY})
  46. add_library(mpfr::mpfr INTERFACE IMPORTED GLOBAL)
  47. file(MAKE_DIRECTORY ${mpfr_INCLUDE_DIR}) # avoid race condition
  48. target_include_directories(mpfr::mpfr INTERFACE ${mpfr_INCLUDE_DIR})
  49. target_link_libraries(mpfr::mpfr INTERFACE "${mpfr_LIBRARIES}") # need the quotes to expand list
  50. # This is necessary to ensure that mpfr appears before gmp in link order.
  51. # Otherwise undefined reference errors occur at link time on Linux with gcc
  52. target_link_libraries(mpfr::mpfr INTERFACE "${gmp_LIBRARIES}")
  53. add_dependencies(mpfr::mpfr mpfr)
  54. endif()
  55. if(NOT TARGET mpfr::mpfr)
  56. message(FATAL_ERROR "Creation of target 'mpfr::mpfr' failed")
  57. endif()