FindMPFR.cmake 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # Try to find the MPFR library
  2. # See http://www.mpfr.org/
  3. if(${CMAKE_VERSION} VERSION_LESS "3.18.0")
  4. set(REQUIRED_FLAG "")
  5. else()
  6. set(REQUIRED_FLAG REQUIRED)
  7. endif()
  8. # On Windows, we must use the pre-compiled versions downloaded with libigl
  9. if(WIN32)
  10. set(NO_DEFAULT_FLAG NO_DEFAULT_PATH)
  11. else()
  12. set(NO_DEFAULT_FLAG "")
  13. endif()
  14. find_path(MPFR_INCLUDES
  15. NAMES
  16. mpfr.h
  17. PATHS
  18. ENV MPFR_DIR
  19. ${INCLUDE_INSTALL_DIR}
  20. PATH_SUFFIXES
  21. include
  22. ${REQUIRED_FLAG}
  23. ${NO_DEFAULT_FLAG}
  24. )
  25. find_library(MPFR_LIBRARIES
  26. NAMES
  27. mpfr
  28. libmpfr-4
  29. PATHS
  30. ENV MPFR_DIR
  31. ${LIB_INSTALL_DIR}
  32. PATH_SUFFIXES
  33. lib
  34. ${REQUIRED_FLAG}
  35. ${NO_DEFAULT_FLAG}
  36. )
  37. set(MPFR_EXTRA_VARS "")
  38. if(WIN32)
  39. # Find dll file and set IMPORTED_LOCATION to the .dll file
  40. find_file(MPFR_RUNTIME_LIB
  41. NAMES
  42. mpfr.dll
  43. libmpfr-4.dll
  44. PATHS
  45. ENV MPFR_DIR
  46. ${LIB_INSTALL_DIR}
  47. PATH_SUFFIXES
  48. lib
  49. ${REQUIRED_FLAG}
  50. ${NO_DEFAULT_FLAG}
  51. )
  52. list(APPEND MPFR_EXTRA_VARS MPFR_RUNTIME_LIB)
  53. endif()
  54. include(FindPackageHandleStandardArgs)
  55. find_package_handle_standard_args(MPFR
  56. REQUIRED_VARS
  57. MPFR_INCLUDES
  58. MPFR_LIBRARIES
  59. ${MPFR_EXTRA_VARS}
  60. REASON_FAILURE_MESSAGE
  61. "MPFR is not installed on your system. Either install MPFR using your preferred package manager, or disable libigl modules that depend on MPFR, such as CGAL. See LibiglOptions.cmake.sample for configuration options. Do not forget to delete your <build>/CMakeCache.txt for the changes to take effect."
  62. )
  63. mark_as_advanced(MPFR_INCLUDES MPFR_LIBRARIES)
  64. if(MPFR_INCLUDES AND MPFR_LIBRARIES AND NOT TARGET mpfr::mpfr)
  65. if(MPFR_RUNTIME_LIB)
  66. add_library(mpfr::mpfr SHARED IMPORTED)
  67. else()
  68. add_library(mpfr::mpfr UNKNOWN IMPORTED)
  69. endif()
  70. # Set public header location and link language
  71. set_target_properties(mpfr::mpfr PROPERTIES
  72. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  73. INTERFACE_INCLUDE_DIRECTORIES "${MPFR_INCLUDES}"
  74. )
  75. # Set lib location. On Windows we specify both the .lib and the .dll paths
  76. if(MPFR_RUNTIME_LIB)
  77. set_target_properties(mpfr::mpfr PROPERTIES
  78. IMPORTED_IMPLIB "${MPFR_LIBRARIES}"
  79. IMPORTED_LOCATION "${MPFR_RUNTIME_LIB}"
  80. )
  81. else()
  82. set_target_properties(mpfr::mpfr PROPERTIES
  83. IMPORTED_LOCATION "${MPFR_LIBRARIES}"
  84. )
  85. endif()
  86. endif()