Skip to content

Commit

Permalink
Be prepared for mpfr
Browse files Browse the repository at this point in the history
  • Loading branch information
msoos committed Apr 12, 2024
1 parent 7402409 commit 571c7d2
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ else()
MESSAGE(STATUS "Not on Linux, not creating manpage")
endif()

find_package(MPFR REQUIRED)

# -----------------------------------------------------------------------------
# Look for ZLIB (For reading zipped CNFs)
# -----------------------------------------------------------------------------
Expand Down
108 changes: 108 additions & 0 deletions cmake/FindMPFR.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# ----------------------------------------------------------------------------
# XC program; finite element analysis code
# for structural analysis and design.
#
# Copyright (C) Luis C. Pérez Tato
#
# Except for the restrictions that may arise from the copyright
# of the original program (see copyright below if any)
# XC is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This software is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program.
# If not, see <http:// www.gnu.org/licenses/>.
# ----------------------------------------------------------------------------

# Try to find the MPFR library
# See http://www.mpfr.org/
#
# This module supports requiring a minimum version, e.g. you can do
# find_package(MPFR 2.3.0)
# to require version 2.3.0 to newer of MPFR.
#
# Once done this will define
#
# MPFR_FOUND - system has MPFR lib with correct version
# MPFR_INCLUDES - the MPFR include directory
# MPFR_LIBRARIES - the MPFR library
# MPFR_VERSION - MPFR version

# Copyright (c) 2006, 2007 Montel Laurent, <[email protected]>
# Copyright (c) 2008, 2009 Gael Guennebaud, <[email protected]>
# Copyright (c) 2010 Jitse Niesen, <[email protected]>
# Redistribution and use is allowed according to the terms of the BSD license.

# Set MPFR_INCLUDES

find_path(MPFR_INCLUDES
NAMES
mpfr.h
PATHS
$ENV{GMPDIR}
${INCLUDE_INSTALL_DIR}
)

# Set MPFR_FIND_VERSION to 1.0.0 if no minimum version is specified

if(NOT MPFR_FIND_VERSION)
if(NOT MPFR_FIND_VERSION_MAJOR)
set(MPFR_FIND_VERSION_MAJOR 1)
endif(NOT MPFR_FIND_VERSION_MAJOR)
if(NOT MPFR_FIND_VERSION_MINOR)
set(MPFR_FIND_VERSION_MINOR 0)
endif(NOT MPFR_FIND_VERSION_MINOR)
if(NOT MPFR_FIND_VERSION_PATCH)
set(MPFR_FIND_VERSION_PATCH 0)
endif(NOT MPFR_FIND_VERSION_PATCH)

set(MPFR_FIND_VERSION "${MPFR_FIND_VERSION_MAJOR}.${MPFR_FIND_VERSION_MINOR}.${MPFR_FIND_VERSION_PATCH}")
endif(NOT MPFR_FIND_VERSION)


if(MPFR_INCLUDES)

# Set MPFR_VERSION

file(READ "${MPFR_INCLUDES}/mpfr.h" _mpfr_version_header)

string(REGEX MATCH "define[ \t]+MPFR_VERSION_MAJOR[ \t]+([0-9]+)" _mpfr_major_version_match "${_mpfr_version_header}")
set(MPFR_MAJOR_VERSION "${CMAKE_MATCH_1}")
string(REGEX MATCH "define[ \t]+MPFR_VERSION_MINOR[ \t]+([0-9]+)" _mpfr_minor_version_match "${_mpfr_version_header}")
set(MPFR_MINOR_VERSION "${CMAKE_MATCH_1}")
string(REGEX MATCH "define[ \t]+MPFR_VERSION_PATCHLEVEL[ \t]+([0-9]+)" _mpfr_patchlevel_version_match "${_mpfr_version_header}")
set(MPFR_PATCHLEVEL_VERSION "${CMAKE_MATCH_1}")

set(MPFR_VERSION ${MPFR_MAJOR_VERSION}.${MPFR_MINOR_VERSION}.${MPFR_PATCHLEVEL_VERSION})

# Check whether found version exceeds minimum version

#if(${MPFR_VERSION} VERSION_LESS ${MPFR_FIND_VERSION})
# set(MPFR_VERSION_OK FALSE)
# message(STATUS "MPFR version ${MPFR_VERSION} found in ${MPFR_INCLUDES}, "
# "but at least version ${MPFR_FIND_VERSION} is required")
#else(${MPFR_VERSION} VERSION_LESS ${MPFR_FIND_VERSION})
# set(MPFR_VERSION_OK TRUE)
#endif(${MPFR_VERSION} VERSION_LESS ${MPFR_FIND_VERSION})
set(MPFR_VERSION_OK TRUE)

endif(MPFR_INCLUDES)

# Set MPFR_LIBRARIES

find_library(MPFR_LIBRARIES mpfr PATHS $ENV{GMPDIR} ${LIB_INSTALL_DIR})

# Epilogue

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(MPFR DEFAULT_MSG
MPFR_INCLUDES MPFR_LIBRARIES MPFR_VERSION_OK)
mark_as_advanced(MPFR_INCLUDES MPFR_LIBRARIES)
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ include_directories(${PROJECT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CRYPTOMINISAT5_INCLUDE_DIRS})
include_directories(${SBVA_INCLUDE_DIRS})
include_directories(${MPFR_INCLUDES})

if (NOT WIN32)
add_cxx_flag_if_supported("-Wno-bitfield-constant-conversion")
Expand Down Expand Up @@ -54,6 +55,7 @@ add_library(arjun
target_link_libraries(arjun
LINK_PUBLIC ${CRYPTOMINISAT5_LIBRARIES}
LINK_PUBLIC ${SBVA_LIBRARIES}
LINK_PUBLIC ${MPFR_LIBRARIES}
)

add_executable(arjun-bin main.cpp)
Expand Down

0 comments on commit 571c7d2

Please sign in to comment.