2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2014,2016, 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.
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.
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.
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.
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.
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.
35 set(_gmx_cmake_dir ${CMAKE_CURRENT_LIST_DIR})
36 get_filename_component(_gmx_root_dir "${_gmx_cmake_dir}" PATH)
37 get_filename_component(_gmx_root_dir "${_gmx_root_dir}" PATH)
38 get_filename_component(_gmx_root_dir "${_gmx_root_dir}" PATH)
40 # Find the exported targets (file name depends on whether shared or static
41 # libraries were built to allow both to coexist in the same prefix), and
43 set(_gmx_import_file ${_gmx_cmake_dir}/libgromacs.cmake)
44 if (GROMACS_PREFER_STATIC OR NOT EXISTS ${_gmx_import_file})
45 set(_gmx_import_file_static ${_gmx_cmake_dir}/libgromacs_static.cmake)
46 if (EXISTS ${_gmx_import_file_static})
47 set(_gmx_import_file ${_gmx_import_file_static})
49 unset(_gmx_import_file_static)
51 if (NOT EXISTS ${_gmx_import_file})
53 "The GROMACS installation at ${_gmx_root_dir} does not contain "
54 "libgromacs.cmake or libgromacs_static.cmake to define the imported "
57 include(${_gmx_import_file})
58 unset(_gmx_import_file)
60 get_target_property(_libs libgromacs INTERFACE_LINK_LIBRARIES)
61 if (_libs MATCHES "tng_io::tng_io")
62 include(CMakeFindDependencyMacro)
63 find_dependency(TNG_IO)
67 set(GROMACS_INCLUDE_DIRS)
68 set(_include_dirs "@INSTALLED_HEADER_INCLUDE_DIRS@")
69 foreach (_dir ${_include_dirs})
70 if (IS_ABSOLUTE ${_dir})
71 list(APPEND GROMACS_INCLUDE_DIRS ${_dir})
73 list(APPEND GROMACS_INCLUDE_DIRS ${_gmx_root_dir}/${_dir})
76 set(GROMACS_LIBRARIES libgromacs @GMX_STDLIB_LIBRARIES@)
77 set(GROMACS_DEFINITIONS @INSTALLED_HEADER_DEFINITIONS@)
78 set(GROMACS_IS_DOUBLE @GMX_DOUBLE@)
79 if (DEFINED GROMACS_SUFFIX AND NOT "${GROMACS_SUFFIX}" STREQUAL "@GMX_LIBS_SUFFIX@")
80 message(FATAL_ERROR "GROMACS_SUFFIX is set inconsistently, expected '@GMX_LIBS_SUFFIX@'")
82 set(GROMACS_SUFFIX "@GMX_LIBS_SUFFIX@")
83 set(GROMACS_CXX_COMPILER "@GROMACS_CXX_COMPILER@")
84 set(GROMACS_CXX_COMPILER_ID "@CMAKE_CXX_COMPILER_ID@")
85 set(GROMACS_CXX_COMPILER_VERSION "@CMAKE_CXX_COMPILER_VERSION@")
86 set(GROMACS_CXX_FLAGS "@GMX_CXX11_FLAGS@ @GMX_STDLIB_CXX_FLAGS@")
88 # Produce a message, since find_package() prints nothing on success.
89 include(FindPackageMessage)
90 # The version info is set by CMake when it determines whether this file
91 # is suitable (by calling the version file, which sets PACKAGE_VERSION).
92 # TODO: Make also the full version string available from somewhere.
93 set(_gmx_info "${GROMACS_VERSION}")
95 set(_gmx_info "${_gmx_info} (suffix: ${GROMACS_SUFFIX})")
97 find_package_message(GROMACS "Found GROMACS: ${_gmx_info}" "${CMAKE_CURRENT_LIST_FILE}")
103 #####################################################################
104 # Macros for use in calling code
106 # This does not work as a function if called as gromacs_check_double(GMX_DOUBLE)
107 # (i.e., with the parameter value equal to the formal parameter name) because
109 macro (gromacs_check_double GMX_DOUBLE)
110 if (${GMX_DOUBLE} AND NOT GROMACS_IS_DOUBLE)
112 "The found GROMACS installation is compiled in mixed precision, "
113 "but double-precision compilation was requested with ${GMX_DOUBLE}=${${GMX_DOUBLE}}")
114 elseif (NOT ${GMX_DOUBLE} AND GROMACS_IS_DOUBLE)
116 "The found GROMACS installation is compiled in double precision, "
117 "but mixed-precision compilation was requested with ${GMX_DOUBLE}=${${GMX_DOUBLE}}")
121 function (gromacs_check_compiler LANG)
122 if (NOT LANG STREQUAL CXX)
124 "gromacs_check_compiler(CXX) is currently the only supported call")
126 # Deal with possible symlinks (it is fine if one of the used compilers was
127 # a symlink to another one).
128 get_filename_component(_cmake_compiler_realpath ${CMAKE_${LANG}_COMPILER} REALPATH)
129 if (NOT "${_cmake_compiler_realpath}" STREQUAL "${GROMACS_${LANG}_COMPILER}" OR
130 NOT "${CMAKE_${LANG}_COMPILER_ID}" STREQUAL "${GROMACS_${LANG}_COMPILER_ID}" OR
131 NOT "${CMAKE_${LANG}_COMPILER_VERSION}" STREQUAL "${GROMACS_${LANG}_COMPILER_VERSION}")
133 "You are compiling with a different C++ compiler from the one that was "
134 "used to compile GROMACS. This may lead to linking or runtime problems. "
135 "GROMACS was compiled with "
136 "${GROMACS_${LANG}_COMPILER_ID} ${GROMACS_${LANG}_COMPILER_VERSION} "
137 "(${GROMACS_${LANG}_COMPILER}).")