Skip to content
Snippets Groups Projects
Commit f0e02418 authored by Christoph Grüninger's avatar Christoph Grüninger
Browse files

[FindGMP.cmake]

Complete overwork of GMP test.
Changed variable GMP_PATH to GMP_PREFIX.

Tested without GMP and with GMP 5.0.5, both installed in /usr and using a
user-specified prefix path.

[[Imported from SVN: r7059]]
parent e090b61c
No related branches found
No related tags found
No related merge requests found
......@@ -2,63 +2,100 @@
# dirs and
#
# Variables used by this module which you may want to set:
# GMP_PATH Path list to search for GMP
# GMP_PREFIX Path list to search for GMP
#
# Sets the following variables:
# GMP_FOUND True if the GMP library was found.
#
include(CheckIncludeFileCXX)
include(CheckCXXSymbolExists)
# adds GMP flags to the targets
function(dune_add_gmp_flags _targets)
if(GMP_FOUND)
foreach(_target ${_targets})
target_link_libraries(${_target} ${GMP_LIBRARIES})
set_property(TARGET ${_target}
APPEND_STRING
PROPERTY COMPILE_FLAGS "-DENABLE_GMP=1 ")
foreach(_path ${GMP_INCLUDE_DIRS})
set_property(TARGET ${_target}
APPEND_STRING
PROPERTY COMPILE_FLAGS "-I${_path}")
endforeach(_path ${GMP_INCLUDE_DIRS})
endforeach(_target ${_targets})
endif(GMP_FOUND)
endfunction(dune_add_gmp_flags)
set(GMP_SEARCH_PATH CACHE FILEPATH "User defined list of directories to search for the GNU GMP library")
# search for location of header gmpxx.h", only at positions given by the user
find_path(GMP_INCLUDE_DIR
NAMES "gmpxx.h"
PATHS ${GMP_PREFIX}
PATH_SUFFIXES include
NO_DEFAULT_PATH)
# try default paths now
find_path(GMP_INCLUDE_DIR
NAMES "gmpxx.h")
# save old variables
set(CMAKE_REQUIRED_INCLUDES_SAVE ${CMAKE_REQUIRED_INCLUDES})
set(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_LIBRARIES_SAVE ${CMAKE_REQUIRED_LIBRARIES})
# check if header is accepted
include(CMakePushCheckState)
cmake_push_check_state()
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${GMP_INCLUDE_DIR})
include(CheckIncludeFileCXX)
check_include_file_cxx("gmpxx.h" GMP_FOUND)
# look for library gmp, only at positions given by the user
find_library(GMP_LIB gmp
PATHS ${GMP_PREFIX}
PATH_SUFFIXES lib lib64
NO_DEFAULT_PATH
DOC "GNU GMP library")
# try default paths now
find_library(GMP_LIB gmp)
# Search for location of header gmpxx.h"
find_path(GMP_INCLUDE_DIRS "gmpxx.h" PATHS ${GMP_SEARCH_PATH} PATH_SUFFIXES include NO_DEFAULT_PATH)
#If not found fall back to default locations
find_path(GMP_INCLUDE_DIRS "gmpxx.h")
# look for library gmpxx, only at positions given by the user
find_library(GMPXX_LIB gmpxx
PATHS ${GMP_PREFIX}
PATH_SUFFIXES lib lib64
NO_DEFAULT_PATH
DOC "GNU GMPXX library")
# try default paths now
find_library(GMPXX_LIB gmpxx)
if(GMP_INCLUDE_DIRS)
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_SAVE} ${GMP_INCLUDE_DIRS})
check_include_files("gmpxx.h" GMP_FOUND)
find_library(GMP_LIB gmp PATHS ${GMP_SEARCH_PATH} PATH_SUFFIXES lib NODEFAULT_PATH DOC "GNU GMP library")
find_library(GMP_LIB gmp)
find_library(GMPXX_LIB gmpxx PATHS ${GMP_SEARCH_PATH} NODEFAULT_PATH DOC DOC "GNU GMPXX library")
find_library(GMPXX_LIB gmpxx)
# check if library works
set(GMP_FOUND "GMP_FOUND-NOTFOUND")
if(GMP_LIB AND GMPXX_LIB)
include(CheckSymbolExists)
check_symbol_exists(__gmpz_abs ${GMP_LIB} GMP_FOUND)
endif(GMP_LIB AND GMPXX_LIB)
cmake_pop_check_state()
if(GMP_LIB AND GMPXX_LIB)
set(GMP_FOUND "GMP_FOUND-NOTFOUND")
check_symbol_exists(__gmpz_abs ${GMP_LIB} GMP_FOUND)
if(GMP_FOUND)
set(GMP_LIBRARIES ${GMP_LIB} ${GMPXX_LIB} CACHE INTERNAL)
set(GMP_COMPILE_FLAGS "-DENABLE_GMP")
endif(GMP_FOUND)
else()
set(GMP_FOUND "GMP_FOUND-NOTFOUND")
endif()
set(HAVE_GMP GMP_FOUND)
endif(GMP_INCLUDE_DIRS)
# behave like a CMake module is supposed to behave
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
"GMP"
DEFAULT_MSG
GMP_INCLUDE_DIR GMP_LIB GMPXX_LIB GMP_FOUND
)
# restore values
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES_SAVE})
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_SAVE})
mark_as_advanced(GMP_LIB GMP_LIBXX)
mark_as_advanced(GMP_LIB GMPXX_LIB GMP_INCLUDE_DIR)
function(dune_add_gmp_flags _targets)
if(GMP_FOUND)
foreach(_target ${_targets})
target_link_libraries(${_target} ${GMP_LIBRARIES})
set_property(TARGET ${_target} APPEND_STRING COMPILE_FLAGS "-DENABLE_GMP=1")
foreach(_path ${GMP_INCLUDE_DIRS})
set_property(TARGET ${_target} APPEND_STRING COMPILE_FLAGS "-I${_path}")
endforeach(_path ${GMP_INCLUDE_DIRS})
endif(GMP_FOUND)
endfunction(dune_add_gmp_flags)
# if both headers and library are found, store results
if(GMP_FOUND)
set(GMP_INCLUDE_DIRS ${GMP_INCLUDE_DIR})
set(GMP_LIBRARIES ${GMP_LIB} ${GMPXX_LIB})
set(GMP_COMPILE_FLAGS "-DENABLE_GMP=1")
# log result
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"Determing location of GMP succeded:\n"
"Include directory: ${GMP_INCLUDE_DIRS}\n"
"Library directory: ${GMP_LIBRARIES}\n\n")
else(GMP_FOUND)
# log errornous result
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Determing location of GMP failed:\n"
"Include directory: ${GMP_INCLUDE_DIR}\n"
"gmp library directory: ${GMP_LIB}\n"
"gmpx library directory: ${GMPXX_LIB}\n\n")
endif(GMP_FOUND)
# set HAVE_GMP for config.h
set(HAVE_GMP GMP_FOUND)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment