Fixing copyright issues and code contributors
[alexxy/gromacs.git] / src / contrib / FindOpenMM.cmake
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2012,2013, by the GROMACS development team, led by
5 # David van der Spoel, Berk Hess, Erik Lindahl, and including many
6 # others, as listed in the AUTHORS file in the top-level source
7 # 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 # Find OpenMM library.
36 #
37 # Looks for the OpenMM libraries at the default (/usr/local) location 
38 # or custom location found in the OPENMM_ROOT_DIR environment variable. 
39 #
40 # The script defines defines: 
41 #  OpenMM_FOUND     
42 #  OpenMM_ROOT_DIR
43 #  OpenMM_INCLUDE_DIR
44 #  OpenMM_LIBRARY_DIR
45 #  OpenMM_LIBRARIES      
46 #  OpenMM_LIBRARIES_D   - debug version of libraries 
47 #  OpenMM_PLUGIN_DIR
48 #
49
50 # Author: Szilard Pall (pszilard@cbr.su.se)
51
52 if(OpenMM_INCLUDE_DIR AND OpenMM_LIBRARY_DIR AND OpenMM_PLUGIN_DIR)
53     set(OpenMM_FIND_QUIETLY)
54 endif()
55
56 file(TO_CMAKE_PATH "$ENV{OPENMM_ROOT_DIR}" _env_OPENMM_ROOT_DIR)
57
58 if(IS_DIRECTORY ${_env_OPENMM_ROOT_DIR})
59     set(OpenMM_ROOT_DIR "${_env_OPENMM_ROOT_DIR}" CACHE PATH "OpenMM installation directory" FORCE)
60 else()
61     if(IS_DIRECTORY "/usr/local/openmm")
62         set(OpenMM_ROOT_DIR "/usr/local/openmm" CACHE PATH "OpenMM installation directory" FORCE)
63     endif()
64 endif()
65
66 find_library(OpenMM_LIBRARIES
67     NAMES OpenMM
68     PATHS "${OpenMM_ROOT_DIR}/lib"
69     CACHE STRING "OpenMM libraries")
70
71 find_library(OpenMM_LIBRARIES_D
72     NAMES OpenMM_d
73     PATHS "${OpenMM_ROOT_DIR}/lib"
74     CACHE STRING "OpenMM debug libraries")
75
76 if(OpenMM_LIBRARIES_D AND NOT OpenMM_LIBRARIES)
77     set(OpenMM_LIBRARIES ${OpenMM_LIBRARIES_D}
78         CACHE STRING "OpenMM libraries" FORCE)
79     message(WARNING " Only found debug versions of the OpenMM libraries!")
80 endif()
81
82 get_filename_component(OpenMM_LIBRARY_DIR 
83     ${OpenMM_LIBRARIES} 
84     PATH
85     CACHE STRING "OpenMM library path")
86
87 find_path(OpenMM_INCLUDE_DIR 
88     NAMES OpenMM.h 
89     PATHS "${OpenMM_ROOT_DIR}/include" "${OpenMM_LIBRARY_DIR}/../include"
90     CACHE STRING "OpenMM include directory")    
91
92 # if we did not manage to set the root dir at the beginning but found the 
93 # libs then set the ${OpenMM_LIBRARY_DIR}/.. as root
94 if(NOT IS_DIRECTORY ${OpenMM_ROOT_DIR})
95     if (IS_DIRECTORY "${OpenMM_LIBRARY_DIR}/..") # just double-checking
96         get_filename_component(OpenMM_ROOT_DIR 
97             "${OpenMM_LIBRARY_DIR}/.." 
98             ABSOLUTE)
99     endif()   
100 endif()
101
102 if(NOT IS_DIRECTORY ${OpenMM_ROOT_DIR})
103     message(FATAL_ERROR "Could not find OpenMM! Set the OPENMM_ROOT_DIR environment "
104     "variable to contain the path of the OpenMM installation.")
105 endif()
106
107 if(NOT IS_DIRECTORY ${OpenMM_LIBRARY_DIR})
108     message(FATAL_ERROR "Can't find OpenMM libraries. Check your OpenMM installation!")
109 endif()
110
111 # now we can be sure that we have the library dir
112 if(IS_DIRECTORY "${OpenMM_LIBRARY_DIR}/plugins")
113     get_filename_component(OpenMM_PLUGIN_DIR
114         "${OpenMM_LIBRARY_DIR}/plugins"
115         ABSOLUTE)
116     set(OpenMM_PLUGIN_DIR ${OpenMM_PLUGIN_DIR} CACHE PATH "OpenMM plugins directory")
117 else()
118     message(WARNING "Could not detect the OpenMM plugin directory at the default location (${OpenMM_LIBRARY_DIR}/plugins)."
119             "Check your OpenMM installation or set the OPENMM_PLUGIN_DIR environment variable!")
120 endif()
121
122 if(NOT OpenMM_INCLUDE_DIR)
123     message(FATAL_ERROR "Can't find OpenMM includes. Check your OpenMM installation!")
124 endif()
125
126 set(OpenMM_ROOT_DIR ${OpenMM_ROOT_DIR} CACHE PATH "OpenMM installation directory")
127
128 include(FindPackageHandleStandardArgs)
129 find_package_handle_standard_args(OpenMM DEFAULT_MSG 
130                                     OpenMM_ROOT_DIR
131                                     OpenMM_LIBRARIES 
132                                     OpenMM_LIBRARY_DIR 
133                                     OpenMM_INCLUDE_DIR)
134
135 mark_as_advanced(OpenMM_INCLUDE_DIR
136     OpenMM_LIBRARIES
137     OpenMM_LIBRARIES_D
138     OpenMM_LIBRARY_DIR)