2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2009-2011, by the VOTCA Development Team (http://www.votca.org).
5 # Copyright (c) 2012,2013,2014, by the GROMACS development team, led by
6 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
7 # and including many others, as listed in the AUTHORS file in the
8 # top-level source directory and at http://www.gromacs.org.
10 # GROMACS is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU Lesser General Public License
12 # as published by the Free Software Foundation; either version 2.1
13 # of the License, or (at your option) any later version.
15 # GROMACS is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 # Lesser General Public License for more details.
20 # You should have received a copy of the GNU Lesser General Public
21 # License along with GROMACS; if not, see
22 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
23 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 # If you want to redistribute modifications to GROMACS, please
26 # consider that scientific software is very special. Version
27 # control is crucial - bugs must be traceable. We will be happy to
28 # consider code for inclusion in the official distribution, but
29 # derived work must not be called official GROMACS. Details are found
30 # in the README & COPYING files - if they are missing, get the
31 # official version at http://www.gromacs.org.
33 # To help us fund GROMACS development, we humbly ask that you cite
34 # the research papers on the package. Check out http://www.gromacs.org.
36 # - Finds parts of GROMACS
37 # Find the native GROMACS components headers and libraries.
39 # GROMACS_INCLUDE_DIRS - where to find GROMACS headers.
40 # GROMACS_LIBRARIES - List of libraries when used by GROMACS.
41 # GROMACS_FOUND - True if all GROMACS components were found.
42 # GROMACS_DEFINITIONS - Extra definies needed by GROMACS
43 # GROMACS_PKG - The name of the pkg-config package needed
44 # GROMACS_VERSION - GROMACS lib interface version
45 # GROMACS_MAJOR_VERSION - GROMACS lib interface major version
46 # GROMACS_MINOR_VERSION - GROMACS lib interface minor version
47 # GROMACS_PATCH_LEVEL - GROMACS lib interface patch level
48 # GROMACS_VERSION_STRING - GROMACS lib interface version string (e.g. "4.5.3")
51 find_package(PkgConfig)
52 list(LENGTH GROMACS_FIND_COMPONENTS GROMACS_NUM_COMPONENTS_WANTED)
53 if(${GROMACS_NUM_COMPONENTS_WANTED} LESS 1)
54 message(FATAL_ERROR "find_package(GROMACS) needs to be supplied with the name of a GROMACS component for which it can search")
55 elseif(${GROMACS_NUM_COMPONENTS_WANTED} GREATER 1)
56 message(FATAL_ERROR "We only support finding one GROMACS component at this point, go and implement it ;-)")
57 elseif(${GROMACS_FIND_COMPONENTS} MATCHES "^lib(gmx|gromacs)(_d)?$")
58 set(GROMACS_PKG "${GROMACS_FIND_COMPONENTS}")
59 string(REGEX REPLACE "^lib(.*)" "\\1" GROMACS_LIBRARY_NAME "${GROMACS_PKG}")
61 message(FATAL_ERROR "We do not support finding ${GROMACS_FIND_COMPONENTS}, go and implement it ;-)")
64 if(GMX_DOUBLE AND NOT "${GROMACS_PKG}" MATCHES "_d$")
65 message(FATAL_ERROR "GMX_DOUBLE was true, but I was asked to find ${GROMACS_PKG} (without _d at the end) - illogical!")
66 endif(GMX_DOUBLE AND NOT "${GROMACS_PKG}" MATCHES "_d$")
67 if(NOT GMX_DOUBLE AND "${GROMACS_PKG}" MATCHES "_d$")
68 message(FATAL_ERROR "GMX_DOUBLE was false, but I was asked to find ${GROMACS_PKG} (with _d at the end) - illogical!")
69 endif(NOT GMX_DOUBLE AND "${GROMACS_PKG}" MATCHES "_d$")
71 pkg_check_modules(PC_GROMACS ${GROMACS_PKG})
73 list(APPEND GMX_DEFS "-DGMX_DOUBLE")
75 if (PC_GROMACS_CFLAGS_OTHER)
76 foreach(DEF ${PC_GROMACS_CFLAGS_OTHER})
77 if (${DEF} MATCHES "^-D")
78 list(APPEND GMX_DEFS ${DEF})
79 endif (${DEF} MATCHES "^-D")
81 list(REMOVE_DUPLICATES GMX_DEFS)
82 endif (PC_GROMACS_CFLAGS_OTHER)
83 set(GROMACS_DEFINITIONS "${GMX_DEFS}" CACHE STRING "extra GROMACS definitions")
85 find_library(GROMACS_LIBRARY NAMES ${GROMACS_LIBRARY_NAME}
86 HINTS ${PC_GROMACS_LIBRARY_DIRS} @CMAKE_INSTALL_PREFIX@/@LIB_INSTALL_DIR@)
88 if("${GROMACS_LIBRARY}" MATCHES "lib(gmx|gromacs)[^;]*\\.a")
89 if(PC_GROMACS_LIBRARIES)
90 list(REMOVE_ITEM PC_GROMACS_LIBRARIES ${GROMACS_LIBRARY_NAME})
91 foreach (LIB ${PC_GROMACS_LIBRARIES})
92 find_library(GROMACS_${LIB} NAMES ${LIB}
93 HINTS ${PC_GROMACS_LIBRARY_DIRS} @CMAKE_INSTALL_PREFIX@/@LIB_INSTALL_DIR@)
94 list(APPEND GMX_DEP_LIBRARIES ${GROMACS_${LIB}})
95 unset(GROMACS_${LIB} CACHE)
97 endif(PC_GROMACS_LIBRARIES)
98 if(PC_GROMACS_CFLAGS_OTHER)
99 foreach(LIB ${PC_GROMACS_CFLAGS_OTHER})
100 if (${LIB} MATCHES "thread")
101 find_package(Threads REQUIRED)
102 list(APPEND GMX_DEP_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
103 endif (${LIB} MATCHES "thread")
105 endif(PC_GROMACS_CFLAGS_OTHER)
106 set(GROMACS_DEP_LIBRARIES "${GMX_DEP_LIBRARIES}" CACHE FILEPATH "GROMACS depency libs (only needed for static (.a) ${GROMACS_LIBRARY}")
107 endif("${GROMACS_LIBRARY}" MATCHES "lib(gmx|gromacs)[^;]*\\.a")
108 include(CheckLibraryExists)
109 check_library_exists("${GROMACS_LIBRARY};${GROMACS_DEP_LIBRARIES}" GromacsVersion "" FOUND_GROMACS_VERSION)
110 if(NOT FOUND_GROMACS_VERSION)
111 message(FATAL_ERROR "Could not find GromacsVersion in ${GROMACS_LIBRARY};${GROMACS_DEP_LIBRARIES}, take look at the error message in ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log to find out what was going wrong. If you don't have pkg-config installed you will most likely have to set GROMACS_LIBRARY and GROMACS_DEP_LIBRARY by hand which sets the GROMACS lib and its depencies (e.g. -DGROMACS_LIBRARY='/path/to/libgmx.so' -DGROMACS_DEP_LIBRARIES='/path/to/libblas.so;/path/to/libm.so') !")
112 endif(NOT FOUND_GROMACS_VERSION)
113 check_library_exists("${GROMACS_LIBRARY};${GROMACS_DEP_LIBRARIES}" init_mtop "" FOUND_GROMACS_INIT_MTOP)
114 if(NOT FOUND_GROMACS_INIT_MTOP)
115 message(FATAL_ERROR "Could not find init_mtop in the GROMACS library, take look at the error message in ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log to find out what was going wrong. This most likely means that your GROMACS version is too old, we need at least GROMACS 4.0.7.")
116 endif(NOT FOUND_GROMACS_INIT_MTOP)
117 set(GROMACS_VERSION 40000)
118 check_library_exists("${GROMACS_LIBRARY};${GROMACS_DEP_LIBRARIES}" output_env_done "" FOUND_GROMACS_OUTPUT_ENV_DONE)
119 if(FOUND_GROMACS_OUTPUT_ENV_DONE)
120 set(GROMACS_VERSION 40500)
121 endif(FOUND_GROMACS_OUTPUT_ENV_DONE)
122 check_library_exists("${GROMACS_LIBRARY};${GROMACS_DEP_LIBRARIES}" gmx_nonbonded_setup "" FOUND_GROMACS_GMX_NONBONDED_SETUP)
123 if(FOUND_GROMACS_GMX_NONBONDED_SETUP)
124 set(GROMACS_VERSION 40600)
125 endif(FOUND_GROMACS_GMX_NONBONDED_SETUP)
126 check_library_exists("${GROMACS_LIBRARY};${GROMACS_DEP_LIBRARIES}" init_domdec_vsites "" FOUND_GROMACS_INIT_DOMDEC_VSITES)
127 if(FOUND_GROMACS_INIT_DOMDEC_VSITES)
128 set(GROMACS_VERSION 50000)
129 endif(FOUND_GROMACS_INIT_DOMDEC_VSITES)
130 set(GROMACS_VERSION ${GROMACS_VERSION} CACHE STRING "GROMACS lib interface version")
131 else(GROMACS_LIBRARY)
132 set(GROMACS_VERSION 40500)
133 endif (GROMACS_LIBRARY)
135 math(EXPR GROMACS_MAJOR_VERSION "${GROMACS_VERSION} / 10000")
136 math(EXPR GROMACS_MINOR_VERSION "${GROMACS_VERSION} / 100 % 100")
137 math(EXPR GROMACS_PATCH_LEVEL "${GROMACS_VERSION} % 100")
138 set(GROMACS_VERSION_STRING "${GROMACS_MAJOR_VERSION}.${GROMACS_MINOR_VERSION}.${GROMACS_PATCH_LEVEL}")
140 if ("${GROMACS_PKG}" MATCHES "libgmx")
141 if (${GROMACS_VERSION} EQUAL 40000)
142 find_path(GROMACS_INCLUDE_DIR tpxio.h HINTS ${PC_GROMACS_INCLUDE_DIRS} @CMAKE_INSTALL_PREFIX@/@INCL_INSTALL_DIR@)
143 else(${GROMACS_VERSION} EQUAL 40000)
144 find_path(GROMACS_INCLUDE_DIR gromacs/tpxio.h HINTS ${PC_GROMACS_INCLUDE_DIRS} @CMAKE_INSTALL_PREFIX@/@INCL_INSTALL_DIR@)
145 endif(${GROMACS_VERSION} EQUAL 40000)
146 elseif("${GROMACS_PKG}" MATCHES "libgromacs")
147 find_path(GROMACS_INCLUDE_DIR gromacs/version.h HINTS ${PC_GROMACS_INCLUDE_DIRS} @CMAKE_INSTALL_PREFIX@/@INCL_INSTALL_DIR@)
148 endif("${GROMACS_PKG}" MATCHES "libgmx")
150 set(GROMACS_LIBRARIES "${GROMACS_LIBRARY};${GROMACS_DEP_LIBRARIES}" )
151 set(GROMACS_INCLUDE_DIRS ${GROMACS_INCLUDE_DIR} )
152 if (PC_GROMACS_INCLUDE_DIRS)
153 list(APPEND GROMACS_INCLUDE_DIRS ${PC_GROMACS_INCLUDE_DIRS})
154 endif(PC_GROMACS_INCLUDE_DIRS)
156 if(NOT ${GROMACS_MAJOR_VERSION} LESS 5)
157 include(CheckIncludeFile)
158 # Let find_package find the subset of Boost installed with GROMACS
159 set(BOOST_INCLUDEDIR ${GROMACS_INCLUDE_DIRS}/gromacs/external/boost)
160 find_package(Boost 1.44.0 REQUIRED)
162 list(APPEND GROMACS_INCLUDE_DIRS ${Boost_INCLUDE_DIRS})
164 message(FATAL_ERROR "Boost not found, compiling the GROMACS template will not work")
168 include(FindPackageHandleStandardArgs)
169 # handle the QUIETLY and REQUIRED arguments and set GROMACS_FOUND to TRUE
170 # if all listed variables are TRUE
171 find_package_handle_standard_args(GROMACS DEFAULT_MSG GROMACS_LIBRARY GROMACS_INCLUDE_DIR)
173 mark_as_advanced(GROMACS_INCLUDE_DIR GROMACS_LIBRARY GROMACS_DEFINITIONS GROMACS_PKG GROMACS_VERSION GROMACS_DEP_LIBRARIES)