Skip to content

Commit

Permalink
Add muparser and CMake handling
Browse files Browse the repository at this point in the history
Adds handling both for linking external muparser library and building
from source if it is not found.

Refs #3515

Change-Id: I09f725ea634d21e3a7d217cf99d28adb71d54473
  • Loading branch information
acmnpv authored and zhmurov committed Oct 5, 2020
1 parent ef43c94 commit b06ac54
Show file tree
Hide file tree
Showing 30 changed files with 10,338 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,8 @@ include(gmxManageTNG)

include(gmxManageLmfit)

include(gmxManageMuparser)

if(GMX_GPU)

string(TOUPPER "${GMX_GPU}" _gmx_gpu_uppercase)
Expand Down
35 changes: 35 additions & 0 deletions COPYING
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ This file contains the licenses for the following bodies of code:
19. Reference implementation of std::string_view
20. Reference implementation of std::optional
21. stl_interfaces
22. muparser

Our chosen method for packaging distributions (CPack) only permits a
package to have a single license file, so we are unfortunately forced
Expand Down Expand Up @@ -1496,3 +1497,37 @@ SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

22. muparser
============

Used version 2.3.2 from https://github.com/beltoforion/muparser/releases/tag/v2.3.2,
which is licensed as below.

/*

_____ __ _____________ _______ ______ ___________
/ \| | \____ \__ \\_ __ \/ ___// __ \_ __ \
| Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/
|__|_| /____/| __(____ /__| /____ >\___ >__|
\/ |__| \/ \/ \/
Copyright (C) 2004 - 2020 Ingo Berg

Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or other materials provided
with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
102 changes: 102 additions & 0 deletions cmake/FindMuparser.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#
# This file is part of the GROMACS molecular simulation package.
#
# Copyright (c) 2020, by the GROMACS development team, led by
# Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
# and including many others, as listed in the AUTHORS file in the
# top-level source directory and at http://www.gromacs.org.
#
# GROMACS is free software; you can 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.
#
# GROMACS 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with GROMACS; if not, see
# http://www.gnu.org/licenses, or write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# If you want to redistribute modifications to GROMACS, please
# consider that scientific software is very special. Version
# control is crucial - bugs must be traceable. We will be happy to
# consider code for inclusion in the official distribution, but
# derived work must not be called official GROMACS. Details are found
# in the README & COPYING files - if they are missing, get the
# official version at http://www.gromacs.org.
#
# To help us fund GROMACS development, we humbly ask that you cite
# the research papers on the package. Check out http://www.gromacs.org.

# This package tries to find an external muparser library, version
# 2.3.
#
# MUPARSER_FOUND - muparser was found
# MUPARSER_INCLUDE_DIR - muparser include directory
# MUPARSER_LIBRARY - muparser library
# MUPARSER_LINKS_OK - muparser libraries link correctly
# MUPARSER_VERSION - muparser version string as "major.minor"
#
# CMake will search the CMAKE_PREFIX_PATH in the usual way, but if you
# need more control then setting MUPARSER_INCLUDE_DIR and MUPARSER_LIBRARY
# on the cmake command line to suitable values will work.

include(CMakePushCheckState)
cmake_push_check_state()

find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
if(MUPARSER_FIND_VERSION)
if(MUPARSER_FIND_VERSION_EXACT)
pkg_check_modules(PC_MUPARSER QUIET muparser=${MUPARSER_FIND_VERSION})
else()
pkg_check_modules(PC_MUPARSER QUIET muparser>=${MUPARSER_FIND_VERSION})
endif()
else()
pkg_check_modules(PC_MUPARSER QUIET muparser)
if (PC_MUPARSER_VERSION)
string(REGEX REPLACE "^([0-9]+):([0-9]+)" "\\1.\\2" MUPARSER_VERSION "${PC_MUPARSER_VERSION}")
endif()
endif()
endif()

# Try to find muparser, perhaps with help from pkg-config
find_path(MUPARSER_INCLUDE_DIR muParser.h HINTS "${PC_MUPARSER_INCLUDE_DIRS}" PATH_SUFFIXES include)
find_library(MUPARSER_LIBRARY NAMES muparser HINTS "${PC_MUPARSER_LIBRARY_DIRS}" PATH_SUFFIXES lib64 lib)

# Make sure we can also link, so that cross-compilation is properly supported
if (MUPARSER_INCLUDE_DIR AND MUPARSER_LIBRARY)
include(CheckCXXSourceCompiles)
set(CMAKE_REQUIRED_INCLUDES ${MUPARSER_INCLUDE_DIR})
set(CMAKE_REQUIRED_LIBRARIES ${MUPARSER_LIBRARY})
check_cxx_source_compiles("#include <muParser.h>\nint main(){mu::Parser parser;}" MUPARSER_LINKS_OK)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(muparser
FOUND_VAR
MUPARSER_FOUND
REQUIRED_VARS
MUPARSER_INCLUDE_DIR
MUPARSER_LIBRARY
MUPARSER_LINKS_OK
VERSION_VAR
MUPARSER_VERSION)

mark_as_advanced(MUPARSER_INCLUDE_DIR MUPARSER_LIBRARY)

# Make a target that other targets can depend on just like this was a
# library built in the main project.
if (MUPARSER_FOUND)
add_library(muparser INTERFACE IMPORTED)
set_target_properties(muparser PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${MUPARSER_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${MUPARSER_LIBRARY}"
)
endif()

cmake_pop_check_state()
92 changes: 92 additions & 0 deletions cmake/gmxManageMuparser.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#
# This file is part of the GROMACS molecular simulation package.
#
# Copyright (c) 2020, by the GROMACS development team, led by
# Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
# and including many others, as listed in the AUTHORS file in the
# top-level source directory and at http://www.gromacs.org.
#
# GROMACS is free software; you can 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.
#
# GROMACS 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with GROMACS; if not, see
# http://www.gnu.org/licenses, or write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# If you want to redistribute modifications to GROMACS, please
# consider that scientific software is very special. Version
# control is crucial - bugs must be traceable. We will be happy to
# consider code for inclusion in the official distribution, but
# derived work must not be called official GROMACS. Details are found
# in the README & COPYING files - if they are missing, get the
# official version at http://www.gromacs.org.
#
# To help us fund GROMACS development, we humbly ask that you cite
# the research papers on the package. Check out http://www.gromacs.org.

set(GMX_MUPARSER_REQUIRED_VERSION "2.3")

include(gmxOptionUtilities)

# Make a three-state enumeration, defaulting to
gmx_option_multichoice(GMX_USE_MUPARSER
"How to handle the muparser dependency of GROMACS"
INTERNAL
INTERNAL EXTERNAL NONE)
mark_as_advanced(GMX_USE_MUPARSER)

# Make a fully functional muparser library target that libgromacs can
# depend on regardless of how the user directed muparser support and/or
# linking to work.
function(gmx_manage_muparser)
if(GMX_USE_MUPARSER STREQUAL "INTERNAL")
# Create an object library for the muparser sources
set(BUNDLED_MUPARSER_DIR "${CMAKE_SOURCE_DIR}/src/external/muparser")
file(GLOB MUPARSER_SOURCES ${BUNDLED_MUPARSER_DIR}/*.cpp)
add_library(muparser_objlib OBJECT ${MUPARSER_SOURCES})
# Ensure that the objects can be used in both STATIC and SHARED
# libraries.
set_target_properties(muparser_objlib PROPERTIES POSITION_INDEPENDENT_CODE ON)

# Create an INTERFACE (ie. fake) library for muparser, that
# libgromacs can depend on. The generator expression for the
# target_sources expands to nothing when cmake builds the
# export for libgromacs, so that it understands that we don't
# install anything for this library - using plain source files
# would not convey the right information.
add_library(muparser INTERFACE)
target_sources(muparser INTERFACE $<TARGET_OBJECTS:muparser_objlib>)
target_include_directories(muparser SYSTEM INTERFACE $<BUILD_INTERFACE:${BUNDLED_MUPARSER_DIR}>)
# Add the muparser interface library to the libgromacs Export name, even though
# we will not be installing any content.
install(TARGETS muparser EXPORT libgromacs)

set(HAVE_MUPARSER 1 CACHE INTERNAL "Is muparser found?")
elseif(GMX_USE_MUPARSER STREQUAL "EXTERNAL")
# Find an external muparser library.
find_package(muparser ${GMX_MUPARSER_REQUIRED_VERSION})
if(NOT MUPARSER_FOUND OR MUPARSER_VERSION VERSION_LESS GMX_MUPARSER_REQUIRED_VERSION)
message(FATAL_ERROR "External muparser >= ${GMX_MUPARSER_REQUIRED_VERSION} could not be found, please adjust your pkg-config path to include the muparser.pc file")
endif()

set(HAVE_MUPARSER 1 CACHE INTERNAL "Is muparser found?")
else()
# Create a dummy link target so the calling code doesn't need to know
# whether muparser support is being compiled.
add_library(muparser INTERFACE)
# Add the muparser interface library to the libgromacs Export name, even though
# we will not be installing any content.
install(TARGETS muparser EXPORT libgromacs)

set(HAVE_MUPARSER 0 CACHE INTERNAL "Is muparser found?")
endif()
mark_as_advanced(HAVE_MUPARSER)
endfunction()
6 changes: 6 additions & 0 deletions docs/release-notes/2021/major/portability.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ configure with ``GMX_USE_RDTSCP=off``. Non-x86 platforms are
unaffected, except that they will no longer report that RDTSCP is
disabled (because that is self-evident).

Bundle muparser
"""""""""""""""

|Gromacs| now bundles MuParser version 2.3. It is also possible
to link to an external provided library.

armv8+sve support (ARM_SVE)
"""""""""""""""""""""""""""
Support for ARM Scalable Vector Extensions (SVE) has been added.
Expand Down
3 changes: 3 additions & 0 deletions src/config.h.cmakein
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,9 @@
/* Define if we have lmfit support */
#cmakedefine01 HAVE_LMFIT

/* Define if we have muparser support */
#cmakedefine01 HAVE_MUPARSER

/* Build using clang analyzer */
#cmakedefine01 GMX_CLANG_ANALYZER

Expand Down
3 changes: 3 additions & 0 deletions src/external/muparser/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
muparser files
==============
Used from https://github.com/beltoforion/muparser/releases/tag/v2.3.2.
Loading

0 comments on commit b06ac54

Please sign in to comment.