include(deps-helper)
-find_path(GMP_INCLUDE_DIR NAMES gmp.h gmpxx.h)
+find_path(GMP_INCLUDE_DIR NAMES gmp.h)
+find_path(GMPXX_INCLUDE_DIR NAMES gmpxx.h)
find_library(GMP_LIBRARIES NAMES gmp)
+find_library(GMPXX_LIBRARIES NAMES gmpxx)
set(GMP_FOUND_SYSTEM FALSE)
-if(GMP_INCLUDE_DIR AND GMP_LIBRARIES)
+if(GMP_INCLUDE_DIR AND GMPXX_INCLUDE_DIR AND GMP_LIBRARIES AND GMPXX_LIBRARIES)
set(GMP_FOUND_SYSTEM TRUE)
+ # Attempt to retrieve the version from gmp.h
function(getversionpart OUTPUT FILENAME DESC)
file(STRINGS ${FILENAME} RES REGEX "^#define __GNU_MP_${DESC}[ \\t]+.*")
string(REGEX MATCH "[0-9]+" RES "${RES}")
getversionpart(MAJOR "${GMP_INCLUDE_DIR}/gmp.h" "VERSION")
getversionpart(MINOR "${GMP_INCLUDE_DIR}/gmp.h" "VERSION_MINOR")
getversionpart(PATCH "${GMP_INCLUDE_DIR}/gmp.h" "VERSION_PATCHLEVEL")
- set(GMP_VERSION
- "${MAJOR}.${MINOR}.${PATCH}"
- )
- check_system_version("GMP")
+ if(MAJOR AND MINOR AND PATCH)
+ set(GMP_VERSION
+ "${MAJOR}.${MINOR}.${PATCH}"
+ )
+ else()
+ set(GMP_VERSION "(unknown version)")
+ endif()
- TRY_COMPILE(DOES_WORK "${DEPS_BASE}/try_compile/GMP-EP"
+ # This test checks whether GMP is usable and whether the version is new
+ # enough
+ try_compile(GMP_USABLE "${DEPS_BASE}/try_compile/GMP-EP"
"${CMAKE_CURRENT_LIST_DIR}/deps-utils/gmp-test.cpp"
- CMAKE_FLAGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
- LINK_LIBRARIES gmpxx gmp
+ CMAKE_FLAGS
+ "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}"
+ "-DINCLUDE_DIRECTORIES=${GMP_INCLUDE_DIR}"
+ LINK_LIBRARIES ${GMP_LIBRARIES} ${GMPXX_LIBRARIES}
)
- if(NOT ${DOES_WORK})
- message(VERBOSE "System version for ${name} does not work in the selected configuration. Maybe we are cross-compiling?")
+ if(NOT GMP_USABLE)
+ message(VERBOSE "System version for GMP does not work in the selected configuration. Maybe we are cross-compiling?")
set(GMP_FOUND_SYSTEM FALSE)
endif()
endif()