diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ include(KDECompilerSettings NO_POLICY_SCOPE) include(FeatureSummary) -# check for PkgConfig, Qt and GMP +# check for PkgConfig, Qt and MPIR/GMP find_package(PkgConfig) if(BUILD_QT4) find_package(Qt4 REQUIRED COMPONENTS QtCore QtDBus QtTest) @@ -31,7 +31,24 @@ set(PC_TARGET_QTPREFIX Qt5) set(PC_TARGET_SUFFIX 5) endif() -find_package(GMP REQUIRED) + +# figure out which multi-precision library to use +# MPIR is preferred over GMP +find_package(MPIR) +if(MPIR_FOUND) + set(MP_INCLUDE_DIR ${MPIR_INCLUDE_DIR}) + set(MP_LIBRARIES ${MPIR_LIBRARIES}) + set(MP_HEADER mpirxx.h) + set(MP_CMAKE_MODULE "MPIR") + set(PC_LIB mpir) +else() + find_package(GMP REQUIRED) + set(MP_INCLUDE_DIR ${GMP_INCLUDE_DIR}) + set(MP_LIBRARIES ${GMP_LIBRARIES}) + set(MP_HEADER gmpxx.h) + set(MP_CMAKE_MODULE "GMP") + set(PC_LIB gmp) +endif() # check for Doxygen (for API documentation) find_package(Doxygen) diff --git a/cmake/modules/FindMPIR.cmake b/cmake/modules/FindMPIR.cmake new file mode 100644 --- /dev/null +++ b/cmake/modules/FindMPIR.cmake @@ -0,0 +1,24 @@ +# Try to find the MPIR librairies +# MPIR_FOUND - system has MPIR lib +# MPIR_INCLUDE_DIR - the MPIR include directory +# MPIR_LIBRARIES - Libraries needed to use MPIR + +# Copyright (c) 2006, Laurent Montel, +# Copyright (c) 2018, Thomas Baumgart +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + + +if (MPIR_INCLUDE_DIR AND MPIR_LIBRARIES) + # Already in cache, be silent + set(MPIR_FIND_QUIETLY TRUE) +endif (MPIR_INCLUDE_DIR AND MPIR_LIBRARIES) + +find_path(MPIR_INCLUDE_DIR NAMES mpir.h ) +find_library(MPIR_LIBRARIES NAMES mpir libmpir) + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(MPIR DEFAULT_MSG MPIR_INCLUDE_DIR MPIR_LIBRARIES) + +mark_as_advanced(MPIR_INCLUDE_DIR MPIR_LIBRARIES) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,7 +2,7 @@ # The current version of libalkimia (used for packages and config.h) set(VERSION_MAJOR "7") set(VERSION_MINOR "0") -set(VERSION_PATCH "0") +set(VERSION_PATCH "1") include(GenerateExportHeader) include(ECMGenerateHeaders) @@ -20,7 +20,7 @@ ) set(alkimia_HEADERS - alkvalue.h + ${CMAKE_CURRENT_BINARY_DIR}/alkvalue.h alkquoteitem.h alkcompany.h ${CMAKE_CURRENT_BINARY_DIR}/alk_export.h @@ -30,8 +30,8 @@ kde_target_enable_exceptions(alkimia PUBLIC) -target_include_directories(alkimia PUBLIC ${GMP_INCLUDE_DIR}) -target_link_libraries(alkimia PUBLIC ${QT_USE_LIBSPREFIX}Core ${QT_USE_LIBSPREFIX}DBus ${GMP_LIBRARIES}) +target_include_directories(alkimia PUBLIC ${MP_INCLUDE_DIR}) +target_link_libraries(alkimia PUBLIC ${QT_USE_LIBSPREFIX}Core ${QT_USE_LIBSPREFIX}DBus ${MP_LIBRARIES}) generate_export_header(alkimia BASE_NAME alk) if(WIN32) @@ -45,6 +45,7 @@ if (NOT WIN32) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libalkimia.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libalkimia${ALKIMIA_PATH_SUFFIX}.pc IMMEDIATE @ONLY) endif(NOT WIN32) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/alkvalue.h.in ${CMAKE_CURRENT_BINARY_DIR}/alkvalue.h IMMEDIATE) ########### create package configuration file ########### @@ -88,7 +89,7 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/LibAlkimia${ALKIMIA_PATH_SUFFIX}Config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/LibAlkimia${ALKIMIA_PATH_SUFFIX}ConfigVersion.cmake" - "../cmake/modules/FindGMP.cmake" + "../cmake/modules/Find${MP_CMAKE_MODULE}.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel) diff --git a/src/LibAlkimiaConfig.cmake.in b/src/LibAlkimiaConfig.cmake.in --- a/src/LibAlkimiaConfig.cmake.in +++ b/src/LibAlkimiaConfig.cmake.in @@ -8,7 +8,7 @@ find_dependency(Qt5Core) find_dependency(Qt5DBus) endif() -find_dependency(GMP) +find_dependency(@MP_CMAKE_MODULE@) include("${CMAKE_CURRENT_LIST_DIR}/LibAlkimia@ALKIMIA_PATH_SUFFIX@Targets.cmake") diff --git a/src/alkvalue.h b/src/alkvalue.h.in rename from src/alkvalue.h rename to src/alkvalue.h.in --- a/src/alkvalue.h +++ b/src/alkvalue.h.in @@ -1,5 +1,6 @@ /*************************************************************************** - * Copyright 2010 Thomas Baumgart ipwizard@users.sourceforge.net * + * Copyright 2010 Thomas Baumgart tbaumgart@kde.org * + * Copyright 2018 Thomas Baumgart tbaumgart@kde.org * * * * This file is part of libalkimia. * * * @@ -23,7 +24,7 @@ // Workaround: include before gmpxx.h to fix build with gcc-4.9 /** @todo When gmp version is higer than 5.1.3, remove cstddef include */ #include -#include // krazy:exclude=camelcase +#include <@MP_HEADER@> // krazy:exclude=camelcase #include #include diff --git a/src/alkvalue.cpp b/src/alkvalue.cpp --- a/src/alkvalue.cpp +++ b/src/alkvalue.cpp @@ -1,5 +1,6 @@ /*************************************************************************** - * Copyright 2010 Thomas Baumgart ipwizard@users.sourceforge.net * + * Copyright 2010 Thomas Baumgart tbaumgart@kde.org * + * Copyright 2018 Thomas Baumgart tbaumgart@kde.org * * * * This file is part of libalkimia. * * * @@ -46,7 +47,7 @@ QString result = QString::fromLatin1(p); // and free up the resources allocated by gmp_asprintf - __gmp_freefunc_t freefunc; + void (*freefunc) (void *, size_t); mp_get_memory_functions(NULL, NULL, &freefunc); (*freefunc)(p, std::strlen(p) + 1); diff --git a/src/libalkimia.pc.in b/src/libalkimia.pc.in --- a/src/libalkimia.pc.in +++ b/src/libalkimia.pc.in @@ -14,6 +14,6 @@ Version: @ALKIMIA_LIB_VERSION@ Libs: -lalkimia@PC_TARGET_SUFFIX@ -Libs.private: -lgmp -l@PC_TARGET_QTPREFIX@Core -l@PC_TARGET_QTPREFIX@DBus -lstdc++ -Cflags: -I${includedir} +Libs.private: -l@PC_LIB@ -l@PC_TARGET_QTPREFIX@Core -l@PC_TARGET_QTPREFIX@DBus -lstdc++ +Cflags: -I${includedir} -I@MP_INCLUDE_DIR@