Merge branch 'release-2020' into master
[alexxy/gromacs.git] / src / gromacs / gromacs-config.cmake.cmakein
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2014,2016,2019,2020, 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_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)
39
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
42 # import them.
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})
48     endif()
49     unset(_gmx_import_file_static)
50 endif()
51 if (NOT EXISTS ${_gmx_import_file})
52     message(FATAL_ERROR
53         "The GROMACS installation at ${_gmx_root_dir} does not contain "
54         "libgromacs.cmake or libgromacs_static.cmake to define the imported "
55         "targets.")
56 endif()
57 include(${_gmx_import_file})
58 unset(_gmx_import_file)
59
60 get_target_property(_libs Gromacs::libgromacs INTERFACE_LINK_LIBRARIES)
61 if (_libs MATCHES "tng_io::tng_io")
62     include(CMakeFindDependencyMacro)
63     find_dependency(TNG_IO REQUIRED)
64 endif()
65 if (_libs MATCHES "OpenMP::OpenMP_CXX")
66     include(CMakeFindDependencyMacro)
67     find_dependency(OpenMP REQUIRED)
68 endif()
69 if (_libs MATCHES "OpenMP::OpenMP_CXX")
70     include(CMakeFindDependencyMacro)
71     find_dependency(OpenMP REQUIRED)
72 endif()
73 unset(_libs)
74
75 set(GROMACS_INCLUDE_DIRS)
76 set(_include_dirs "@INSTALLED_HEADER_INCLUDE_DIRS@")
77 foreach (_dir ${_include_dirs})
78     if (IS_ABSOLUTE ${_dir})
79         list(APPEND GROMACS_INCLUDE_DIRS ${_dir})
80     else()
81         list(APPEND GROMACS_INCLUDE_DIRS ${_gmx_root_dir}/${_dir})
82     endif()
83 endforeach()
84 set(GROMACS_LIBRARIES Gromacs::libgromacs)
85 set(GROMACS_DEFINITIONS @INSTALLED_HEADER_DEFINITIONS@)
86 set(GROMACS_IS_DOUBLE @GMX_DOUBLE@)
87 if (DEFINED GROMACS_SUFFIX AND NOT "${GROMACS_SUFFIX}" STREQUAL "@GMX_LIBS_SUFFIX@")
88     message(FATAL_ERROR "GROMACS_SUFFIX is set inconsistently, expected '@GMX_LIBS_SUFFIX@'")
89 endif()
90 set(GROMACS_SUFFIX "@GMX_LIBS_SUFFIX@")
91 set(GROMACS_CXX_COMPILER "@GROMACS_CXX_COMPILER@")
92 set(GROMACS_CXX_COMPILER_ID "@CMAKE_CXX_COMPILER_ID@")
93 set(GROMACS_CXX_COMPILER_VERSION "@CMAKE_CXX_COMPILER_VERSION@")
94 set(GROMACS_CXX_FLAGS "")
95
96 # Produce a message, since find_package() prints nothing on success.
97 include(FindPackageMessage)
98 # The version info is set by CMake when it determines whether this file
99 # is suitable (by calling the version file, which sets PACKAGE_VERSION).
100 # TODO: Make also the full version string available from somewhere.
101 set(_gmx_info "${GROMACS_VERSION}")
102 if (GROMACS_SUFFIX)
103     set(_gmx_info "${_gmx_info} (suffix: ${GROMACS_SUFFIX})")
104 endif()
105 find_package_message(GROMACS "Found GROMACS: ${_gmx_info}" "${CMAKE_CURRENT_LIST_FILE}")
106
107 unset(_gmx_cmake_dir)
108 unset(_gmx_root_dir)
109 unset(_gmx_info)
110
111 #####################################################################
112 # Macros for use in calling code
113
114 # This does not work as a function if called as gromacs_check_double(GMX_DOUBLE)
115 # (i.e., with the parameter value equal to the formal parameter name) because
116 # of scoping rules.
117 macro (gromacs_check_double GMX_DOUBLE)
118     if (${GMX_DOUBLE} AND NOT GROMACS_IS_DOUBLE)
119         message(FATAL_ERROR
120             "The found GROMACS installation is compiled in mixed precision, "
121             "but double-precision compilation was requested with ${GMX_DOUBLE}=${${GMX_DOUBLE}}")
122     elseif (NOT ${GMX_DOUBLE} AND GROMACS_IS_DOUBLE)
123         message(FATAL_ERROR
124             "The found GROMACS installation is compiled in double precision, "
125             "but mixed-precision compilation was requested with ${GMX_DOUBLE}=${${GMX_DOUBLE}}")
126     endif()
127 endmacro()
128
129 function (gromacs_check_compiler LANG)
130     if (NOT LANG STREQUAL CXX)
131         message(FATAL_ERROR
132             "gromacs_check_compiler(CXX) is currently the only supported call")
133     endif()
134     # Deal with possible symlinks (it is fine if one of the used compilers was
135     # a symlink to another one).
136     get_filename_component(_cmake_compiler_realpath ${CMAKE_${LANG}_COMPILER} REALPATH)
137     if (NOT "${_cmake_compiler_realpath}" STREQUAL "${GROMACS_${LANG}_COMPILER}" OR
138         NOT "${CMAKE_${LANG}_COMPILER_ID}" STREQUAL "${GROMACS_${LANG}_COMPILER_ID}" OR
139         NOT "${CMAKE_${LANG}_COMPILER_VERSION}" STREQUAL "${GROMACS_${LANG}_COMPILER_VERSION}")
140         message(WARNING
141             "You are compiling with a different C++ compiler from the one that was "
142             "used to compile GROMACS. This may lead to linking or runtime problems. "
143             "GROMACS was compiled with "
144             "${GROMACS_${LANG}_COMPILER_ID} ${GROMACS_${LANG}_COMPILER_VERSION} "
145             "(${GROMACS_${LANG}_COMPILER}).")
146     endif()
147 endfunction()