Merge release-5-0 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, 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 set(GROMACS_INCLUDE_DIRS)
61 set(_include_dirs "@INSTALLED_HEADER_INCLUDE_DIRS@")
62 foreach (_dir ${_include_dirs})
63     if (IS_ABSOLUTE ${_dir})
64         list(APPEND GROMACS_INCLUDE_DIRS ${_dir})
65     else()
66         list(APPEND GROMACS_INCLUDE_DIRS ${_gmx_root_dir}/${_dir})
67     endif()
68 endforeach()
69 set(GROMACS_LIBRARIES libgromacs)
70 set(GROMACS_DEFINITIONS @INSTALLED_HEADER_DEFINITIONS@)
71 set(GROMACS_IS_DOUBLE @GMX_DOUBLE@)
72 if (DEFINED GROMACS_SUFFIX AND NOT "${GROMACS_SUFFIX}" STREQUAL "@GMX_LIBS_SUFFIX@")
73     message(FATAL_ERROR "GROMACS_SUFFIX is set inconsistently, expected '@GMX_LIBS_SUFFIX@'")
74 endif()
75 set(GROMACS_SUFFIX "@GMX_LIBS_SUFFIX@")
76 set(GROMACS_CXX_COMPILER "@GROMACS_CXX_COMPILER@")
77 set(GROMACS_CXX_COMPILER_ID "@CMAKE_CXX_COMPILER_ID@")
78 set(GROMACS_CXX_COMPILER_VERSION "@CMAKE_CXX_COMPILER_VERSION@")
79
80 # Produce a message, since find_package() prints nothing on success.
81 include(FindPackageMessage)
82 # The version info is set by CMake when it determines whether this file
83 # is suitable (by calling the version file, which sets PACKAGE_VERSION).
84 # TODO: Make also the full version string available from somewhere.
85 set(_gmx_info "${GROMACS_VERSION}")
86 if (GROMACS_SUFFIX)
87     set(_gmx_info "${_gmx_info} (suffix: ${GROMACS_SUFFIX})")
88 endif()
89 find_package_message(GROMACS "Found GROMACS: ${_gmx_info}" "${CMAKE_CURRENT_LIST_FILE}")
90
91 unset(_gmx_cmake_dir)
92 unset(_gmx_root_dir)
93 unset(_gmx_info)
94
95 #####################################################################
96 # Macros for use in calling code
97
98 # This does not work as a function if called as gromacs_check_double(GMX_DOUBLE)
99 # (i.e., with the parameter value equal to the formal parameter name) because
100 # of scoping rules.
101 macro (gromacs_check_double GMX_DOUBLE)
102     if (${GMX_DOUBLE} AND NOT GROMACS_IS_DOUBLE)
103         message(FATAL_ERROR
104             "The found GROMACS installation is compiled in mixed precision, "
105             "but double-precision compilation was requested with ${GMX_DOUBLE}=${${GMX_DOUBLE}}")
106     elseif (NOT ${GMX_DOUBLE} AND GROMACS_IS_DOUBLE)
107         message(FATAL_ERROR
108             "The found GROMACS installation is compiled in double precision, "
109             "but mixed-precision compilation was requested with ${GMX_DOUBLE}=${${GMX_DOUBLE}}")
110     endif()
111 endmacro()
112
113 function (gromacs_check_compiler LANG)
114     if (NOT LANG STREQUAL CXX)
115         message(FATAL_ERROR
116             "gromacs_check_compiler(CXX) is currently the only supported call")
117     endif()
118     # Deal with possible symlinks (it is fine if one of the used compilers was
119     # a symlink to another one).
120     get_filename_component(_cmake_compiler_realpath ${CMAKE_${LANG}_COMPILER} REALPATH)
121     if (NOT "${_cmake_compiler_realpath}" STREQUAL "${GROMACS_${LANG}_COMPILER}" OR
122         NOT "${CMAKE_${LANG}_COMPILER_ID}" STREQUAL "${GROMACS_${LANG}_COMPILER_ID}" OR
123         NOT "${CMAKE_${LANG}_COMPILER_VERSION}" STREQUAL "${GROMACS_${LANG}_COMPILER_VERSION}")
124         message(WARNING
125             "You are compiling with a different C++ compiler than what was used "
126             "to compile GROMACS. This may lead to linking or runtime problems. "
127             "GROMACS was compiled with "
128             "${GROMACS_${LANG}_COMPILER_ID} ${GROMACS_${LANG}_COMPILER_VERSION} "
129             "(${GROMACS_${LANG}_COMPILER}).")
130     endif()
131 endfunction()