Unify coordinate copy handling across GPU platforms
[alexxy/gromacs.git] / cmake / gmxManageMuparser.cmake
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2021, by the GROMACS development team, led by
5 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 # and including many others, as listed in the AUTHORS file in the
7 # top-level source directory and at http://www.gromacs.org.
8 #
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
13 #
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # Lesser General Public License for more details.
18 #
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23 #
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
31 #
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
34
35 set(GMX_MUPARSER_REQUIRED_VERSION "2.3")
36
37 include(gmxOptionUtilities)
38
39 # Make a three-state enumeration, defaulting to 
40 gmx_option_multichoice(GMX_USE_MUPARSER
41     "How to handle the muparser dependency of GROMACS"
42     INTERNAL
43     INTERNAL EXTERNAL NONE)
44 mark_as_advanced(GMX_USE_MUPARSER)
45
46 # Make a fully functional muparser library target that libgromacs can
47 # depend on regardless of how the user directed muparser support and/or
48 # linking to work.
49 function(gmx_manage_muparser)
50     if(GMX_USE_MUPARSER STREQUAL "INTERNAL")
51         # Use cmake's FetchContent to organize the build, even though
52         # the content is already present in src/external. In
53         # particular, it sets up an easy call to add_subdirectory().
54         include(FetchContent)
55         FetchContent_Declare(muparser SOURCE_DIR ${CMAKE_SOURCE_DIR}/src/external/muparser)
56         if (NOT ${muparser}_POPULATED)
57             if (OpenMP_CXX_FLAGS)
58                 set(OpenMP_FIND_QUIETLY ON)
59             endif()
60             FetchContent_Populate(muparser)
61         endif()
62         add_subdirectory(${muparser_SOURCE_DIR} ${muparser_BINARY_DIR})
63         if (BUILD_SHARED_LIBS)
64             # Ensure muparser is in the export set called libgromacs,
65             # so that it gets installed along with libgromacs.
66             install(TARGETS muparser EXPORT libgromacs)
67         endif()
68         if (WIN32)
69             gmx_target_warning_suppression(muparser /wd4310 HAS_NO_MSVC_CAST_TRUNCATES_CONSTANT_VALUE)
70         endif()
71
72         set(HAVE_MUPARSER 1 CACHE INTERNAL "Is muparser found?")
73     elseif(GMX_USE_MUPARSER STREQUAL "EXTERNAL")
74         # Find an external muparser library.
75         find_package(muparser ${GMX_MUPARSER_REQUIRED_VERSION})
76         if(NOT MUPARSER_FOUND OR MUPARSER_VERSION VERSION_LESS GMX_MUPARSER_REQUIRED_VERSION)
77             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")
78         endif()
79
80         set(HAVE_MUPARSER 1 CACHE INTERNAL "Is muparser found?")
81     else()
82         # Create a dummy link target so the calling code doesn't need to know
83         # whether muparser support is being compiled.
84         add_library(muparser INTERFACE)
85         # Add the muparser interface library to the libgromacs Export name, even though
86         # we will not be installing any content.
87         install(TARGETS muparser EXPORT libgromacs)
88
89         set(HAVE_MUPARSER 0 CACHE INTERNAL "Is muparser found?")
90     endif()
91     mark_as_advanced(HAVE_MUPARSER)
92 endfunction()