From: Jean-Paul Pelteret Date: Thu, 14 Mar 2019 08:54:01 +0000 (+0100) Subject: Add CMake module and configuration files for SymEngine X-Git-Tag: v9.1.0-rc1~285^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=95f6e6068ff5675aba5f814942550fcaff23fdec;p=dealii.git Add CMake module and configuration files for SymEngine --- diff --git a/cmake/configure/configure_symengine.cmake b/cmake/configure/configure_symengine.cmake new file mode 100644 index 0000000000..4867772178 --- /dev/null +++ b/cmake/configure/configure_symengine.cmake @@ -0,0 +1,41 @@ +## --------------------------------------------------------------------- +## +## Copyright (C) 2019 by the deal.II authors +## +## This file is part of the deal.II library. +## +## The deal.II library is free software; you can use it, redistribute +## it, and/or modify it under the terms of the GNU Lesser General +## Public License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## The full text of the license can be found in the file LICENSE at +## the top level of the deal.II distribution. +## +## --------------------------------------------------------------------- + +# +# Configuration for the SymEngine library: +# + +# +# We require at least version 0.3 of the symengine library: +# +SET(SYMENGINE_MINIMUM_REQUIRED_VERSION "0.3") + + +MACRO(FEATURE_SYMENGINE_CONFIGURE_EXTERNAL) + SET(DEAL_II_SYMENGINE_WITH_LLVM ${SYMENGINE_WITH_LLVM}) + + IF(DEAL_II_SYMENGINE_WITH_LLVM) + MESSAGE(STATUS "Configured with SymEngine LLVM capabilities.") + ENDIF() + + # + # Overwrite the compiler flags imported from SymEngine + # + SET(SYMENGINE_CXX_FLAGS_DEBUG) + SET(SYMENGINE_CXX_FLAGS_RELEASE) +ENDMACRO() + + +CONFIGURE_FEATURE(SYMENGINE) diff --git a/cmake/modules/FindSYMENGINE.cmake b/cmake/modules/FindSYMENGINE.cmake new file mode 100644 index 0000000000..4b7468f9ec --- /dev/null +++ b/cmake/modules/FindSYMENGINE.cmake @@ -0,0 +1,129 @@ +## --------------------------------------------------------------------- +## +## Copyright (C) 2019 by the deal.II authors +## +## This file is part of the deal.II library. +## +## The deal.II library is free software; you can use it, redistribute +## it, and/or modify it under the terms of the GNU Lesser General +## Public License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## The full text of the license can be found in the file LICENSE at +## the top level of the deal.II distribution. +## +## --------------------------------------------------------------------- + +# +# - Try to find SymEngine +# +# This module exports +# +# SYMENGINE_INCLUDE_DIR +# SYMENGINE_LIBRARY +# SYMENGINE_WITH_LLVM +# + +SET(SYMENGINE_DIR "" CACHE PATH "An optional hint to a SymEngine installation") +SET_IF_EMPTY(SYMENGINE_DIR "$ENV{SYMENGINE_DIR}") + +# +# SymEngine overwrites the CMake module path, so we save +# and restore it after this library is found and configured. +# +SET (DEAL_II_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}) + +# +# Include the SymEngine: +# +FIND_PACKAGE(SymEngine ${SYMENGINE_MINIMUM_REQUIRED_VERSION} + CONFIG QUIET + HINTS ${SYMENGINE_DIR} + PATH_SUFFIXES lib/cmake/symengine + NO_SYSTEM_ENVIRONMENT_PATH + ) + +# +# Reset the CMake module path +# +SET (CMAKE_MODULE_PATH ${DEAL_II_CMAKE_MODULE_PATH}) + + +# +# Look for symengine_config.h - we'll query it to determine supported features: +# +IF(SymEngine_FOUND) + DEAL_II_FIND_FILE(SYMENGINE_SETTINGS_H symengine_config.h + HINTS ${SYMENGINE_INCLUDE_DIRS} + PATH_SUFFIXES symengine + NO_DEFAULT_PATH + NO_CMAKE_ENVIRONMENT_PATH + NO_CMAKE_PATH + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH + NO_CMAKE_FIND_ROOT_PATH + ) +ENDIF() + +# +# Version check +# +IF(EXISTS ${SYMENGINE_SETTINGS_H}) + + FILE(STRINGS "${SYMENGINE_SETTINGS_H}" SYMENGINE_VERSION_MAJOR_STRING + REGEX "#define.*SYMENGINE_MAJOR_VERSION") + STRING(REGEX REPLACE "^.*SYMENGINE_MAJOR_VERSION.*([0-9]+).*" "\\1" + SYMENGINE_VERSION_MAJOR "${SYMENGINE_VERSION_MAJOR_STRING}" + ) + FILE(STRINGS "${SYMENGINE_SETTINGS_H}" SYMENGINE_VERSION_MINOR_STRING + REGEX "#define.*SYMENGINE_MINOR_VERSION") + STRING(REGEX REPLACE "^.*SYMENGINE_MINOR_VERSION.*([0-9]+).*" "\\1" + SYMENGINE_VERSION_MINOR "${SYMENGINE_VERSION_MINOR_STRING}" + ) + FILE(STRINGS "${SYMENGINE_SETTINGS_H}" SYMENGINE_VERSION_PATCH_STRING + REGEX "#define.*SYMENGINE_PATCH_VERSION") + STRING(REGEX REPLACE "^.*SYMENGINE_PATCH_VERSION.*([0-9]+).*" "\\1" + SYMENGINE_VERSION_PATCH "${SYMENGINE_VERSION_PATCH_STRING}" + ) + SET(SYMENGINE_VERSION + "${SYMENGINE_VERSION_MAJOR}.${SYMENGINE_VERSION_MINOR}.${SYMENGINE_VERSION_PATCH}" + ) +ENDIF() + +# +# Feature checks +# + +MACRO(_symengine_feature_check _var _regex) + IF(EXISTS ${SYMENGINE_SETTINGS_H}) + FILE(STRINGS "${SYMENGINE_SETTINGS_H}" SYMENGINE_${_var}_STRING + REGEX "${_regex}") + IF("${SYMENGINE_${_var}_STRING}" STREQUAL "") + SET(SYMENGINE_WITH_${_var} FALSE) + ELSE() + SET(SYMENGINE_WITH_${_var} TRUE) + ENDIF() + ENDIF() +ENDMACRO() + +# Other possible features of interest: BOOST, GMP +_symengine_feature_check(LLVM "#define.*HAVE_SYMENGINE_LLVM") + +# +# Sanitize include dirs: +# + +STRING(REGEX REPLACE + "(lib64|lib)\\/cmake\\/symengine\\/\\.\\.\\/\\.\\.\\/\\.\\.\\/" "" + _symengine_include_dirs "${SYMENGINE_INCLUDE_DIRS}" + ) +REMOVE_DUPLICATES(_symengine_include_dirs) + +SET(_symengine_libraries ${SYMENGINE_LIBRARIES}) + + +DEAL_II_PACKAGE_HANDLE(SYMENGINE + LIBRARIES REQUIRED _symengine_libraries + INCLUDE_DIRS REQUIRED _symengine_include_dirs + USER_INCLUDE_DIRS REQUIRED _symengine_include_dirs + CLEAR SYMENGINE_SETTINGS_H SYMENGINE_SKIP_DEPENDENCIES SymEngine_DIR +)