-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GMP support via custom FindGMP module
Introduce a custom FindGMP.cmake module to locate and configure GMP library dependencies. This change streamlines GMP integration by handling both pkg-config and direct library searches, ensuring compatibility across different platforms and setups. The CMakeLists.txt is updated to use this new module for improved maintainability.
- Loading branch information
1 parent
078901c
commit 3afe673
Showing
2 changed files
with
119 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
|
||
if (GMP_FOUND) | ||
return() | ||
endif() | ||
|
||
include(FindPackageHandleStandardArgs) | ||
include(SelectLibraryConfigurations) | ||
|
||
find_package(PkgConfig QUIET) | ||
|
||
if (PkgConfig_FOUND) | ||
pkg_check_modules(PC_GMP QUIET gmp) | ||
endif () | ||
|
||
if (GMP_PKG_FOUND) | ||
set(GMP_INCLUDE_DIR "${PC_GMP_INCLUDE_DIRS}") | ||
set(GMP_LIBRARY_DIRS "${PC_GMP_LIBRARY_DIRS}") | ||
set(GMP_LIBRARIES "${PC_GMP_LIBRARIES}") | ||
set(GMP_COMPILE_OPTIONS ${PC_GMP_CFLAGS} ${PC_GMP_CFLAGS_OTHER}) | ||
set(GMP_LINK_OPTIONS ${PC_GMP_LDFLAGS} ${PC_GMP_LDFLAGS_OTHER}) | ||
else() | ||
|
||
set(_gmp_lib_names gmp libgmp mpir libmpir) | ||
|
||
find_library(GMP_LIBRARY_RELEASE | ||
NAMES ${_gmp_lib_names} | ||
HINTS "${VCPKG_INSTALLED_DIR}" | ||
) | ||
|
||
if (WIN32) | ||
# VCPKG installs debug libraries in ${VCPKG_INSTALLED_DIR}/debug on Windows | ||
find_library(GMP_LIBRARY_DEBUG | ||
NAMES ${_gmp_lib_names} | ||
HINTS "${VCPKG_INSTALLED_DIR}/debug" | ||
) | ||
else() | ||
foreach(_name IN ITEMS ${_gmp_lib_names}) | ||
list(APPEND _gmp_lib_names_debug "${_name}d") | ||
endforeach() | ||
|
||
# Almost surely, sensible platforms will have pkgconfig find the libraries | ||
find_library(GMP_LIBRARY_DEBUG | ||
NAMES ${_gmp_lib_names_debug} | ||
HINTS "${VCPKG_INSTALLED_DIR}" | ||
) | ||
endif() | ||
|
||
set(GMP_COMPILE_OPTIONS "") | ||
set(GMP_LINK_OPTIONS "") | ||
|
||
find_path(GMP_INCLUDE_DIR NAMES gmp.h HINTS "${VCPKG_INSTALLED_DIR}") | ||
|
||
|
||
select_library_configurations(GMP) | ||
|
||
endif () | ||
|
||
|
||
|
||
|
||
find_package_handle_standard_args(GMP | ||
FOUND_VAR GMP_FOUND | ||
REQUIRED_VARS | ||
GMP_LIBRARY GMP_INCLUDE_DIR) | ||
|
||
mark_as_advanced( | ||
GMP_INCLUDE_DIR | ||
GMP_LIBRARIES | ||
GMP_LIBRARY_DIRS | ||
GMP_COMPILE_OPTIONS | ||
GMP_LINK_OPTIONS | ||
) | ||
|
||
|
||
if (GMP_FOUND AND NOT TARGET GMP::GMP) | ||
add_library(GMP::GMP UNKNOWN IMPORTED GLOBAL) | ||
set_target_properties(GMP::GMP PROPERTIES | ||
IMPORTED_LOCATION "${GMP_LIBRARY}" | ||
INTERFACE_INCLUDE_DIRECTORIES "${GMP_INCLUDE_DIR}" | ||
IMPORTED_IMPLIB "${GMP_LIBRARY_DIRS}" | ||
) | ||
if (GMP_COMPILE_OPTIONS) | ||
set_target_properties(GMP::GMP PROPERTIES | ||
INTERFACE_COMPILE_OPTIONS "${GMP_COMPILE_OPTIONS}" | ||
) | ||
endif() | ||
if(GMP_LINK_OPTIONS) | ||
set_target_properties(GMP::GMP PROPERTIES | ||
INTERFACE_LINK_OPTIONS "${GMP_LINK_OPTIONS}" | ||
) | ||
endif() | ||
|
||
if (GMP_LIBRARY_RELEASE) | ||
set_property(TARGET GMP::GMP APPEND PROPERTY | ||
IMPORTED_CONFIGURATIONS RELEASE | ||
) | ||
set_target_properties(GMP::GMP PROPERTIES | ||
IMPORTED_LOCATION_RELEASE "${GMP_LIBRARY_RELEASE}" | ||
) | ||
endif() | ||
if (GMP_LIBRARY_RELEASE) | ||
set_property(TARGET GMP::GMP APPEND PROPERTY | ||
IMPORTED_CONFIGURATIONS DEBUG | ||
) | ||
set_target_properties(GMP::GMP PROPERTIES | ||
IMPORTED_LOCATION_DEBUG "${GMP_LIBRARY_DEBUG}" | ||
) | ||
endif() | ||
|
||
|
||
endif() |