FindGMP.cmake 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # Try to find the GNU Multiple Precision Arithmetic Library (GMP)
  2. # See http://gmplib.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(GMP_INCLUDES
  15. NAMES
  16. gmp.h
  17. PATHS
  18. ENV GMP_DIR
  19. ${INCLUDE_INSTALL_DIR}
  20. PATH_SUFFIXES
  21. include
  22. ${REQUIRED_FLAG}
  23. ${NO_DEFAULT_FLAG}
  24. )
  25. find_library(GMP_LIBRARIES
  26. NAMES
  27. gmp
  28. libgmp-10
  29. PATHS
  30. ENV GMP_DIR
  31. ${LIB_INSTALL_DIR}
  32. PATH_SUFFIXES
  33. lib
  34. ${REQUIRED_FLAG}
  35. ${NO_DEFAULT_FLAG}
  36. )
  37. set(GMP_EXTRA_VARS "")
  38. if(WIN32)
  39. # Find dll file and set IMPORTED_LOCATION to the .dll file
  40. find_file(GMP_RUNTIME_LIB
  41. NAMES
  42. gmp.dll
  43. libgmp-10.dll
  44. PATHS
  45. ENV GMP_DIR
  46. ${LIB_INSTALL_DIR}
  47. PATH_SUFFIXES
  48. lib
  49. ${REQUIRED_FLAG}
  50. ${NO_DEFAULT_FLAG}
  51. )
  52. list(APPEND GMP_EXTRA_VARS GMP_RUNTIME_LIB)
  53. endif()
  54. include(FindPackageHandleStandardArgs)
  55. find_package_handle_standard_args(GMP
  56. REQUIRED_VARS
  57. GMP_INCLUDES
  58. GMP_LIBRARIES
  59. ${GMP_EXTRA_VARS}
  60. REASON_FAILURE_MESSAGE
  61. "GMP is not installed on your system. Either install GMP using your preferred package manager, or disable libigl modules that depend on GMP, 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(GMP_INCLUDES GMP_LIBRARIES)
  64. if(GMP_INCLUDES AND GMP_LIBRARIES AND NOT TARGET gmp::gmp)
  65. if(GMP_RUNTIME_LIB)
  66. add_library(gmp::gmp SHARED IMPORTED)
  67. else()
  68. add_library(gmp::gmp UNKNOWN IMPORTED)
  69. endif()
  70. # Set public header location and link language
  71. set_target_properties(gmp::gmp PROPERTIES
  72. IMPORTED_LINK_INTERFACE_LANGUAGES "C"
  73. INTERFACE_INCLUDE_DIRECTORIES "${GMP_INCLUDES}"
  74. )
  75. # Set lib location. On Windows we specify both the .lib and the .dll paths
  76. if(GMP_RUNTIME_LIB)
  77. set_target_properties(gmp::gmp PROPERTIES
  78. IMPORTED_IMPLIB "${GMP_LIBRARIES}"
  79. IMPORTED_LOCATION "${GMP_RUNTIME_LIB}"
  80. )
  81. else()
  82. set_target_properties(gmp::gmp PROPERTIES
  83. IMPORTED_LOCATION "${GMP_LIBRARIES}"
  84. )
  85. endif()
  86. endif()