minor updates to FindGit and FindOpenMM
[gromacs/rigid-bodies.git] / cmake / FindOpenMM.cmake
blob5094d1bd942e86ad6f346b19caaccc89ff5e5383
1 # Find OpenMM library.
3 # Looks for the OpenMM libraries at the default (/usr/local) location 
4 # or custom location found in the OPENMM_ROOT_DIR environment variable. 
6 # The script defines defines: 
7 #  OpenMM_FOUND     
8 #  OpenMM_ROOT_DIR
9 #  OpenMM_INCLUDE_DIR
10 #  OpenMM_LIBRARY_DIR
11 #  OpenMM_LIBRARIES      
12 #  OpenMM_LIBRARIES_D   - debug version of libraries 
13 #  OpenMM_PLUGIN_DIR
16 # Author: Szilard Pall (pszilard@cbr.su.se)
18 if(OpenMM_INCLUDE_DIR AND OpenMM_LIBRARY_DIR AND OpenMM_PLUGIN_DIR)
19     set(OpenMM_FIND_QUIETLY)
20 endif()
22 file(TO_CMAKE_PATH "$ENV{OPENMM_ROOT_DIR}" _env_OPENMM_ROOT_DIR)
24 if(IS_DIRECTORY ${_env_OPENMM_ROOT_DIR})
25     set(OpenMM_ROOT_DIR "${_env_OPENMM_ROOT_DIR}" CACHE PATH "OpenMM installation directory" FORCE)
26 else()
27     if(IS_DIRECTORY "/usr/local/openmm")
28         set(OpenMM_ROOT_DIR "/usr/local/openmm" CACHE PATH "OpenMM installation directory" FORCE)
29     endif()
30 endif()
32 find_library(OpenMM_LIBRARIES
33     NAMES OpenMM
34     PATHS "${OpenMM_ROOT_DIR}/lib"
35     CACHE STRING "OpenMM libraries")
37 find_library(OpenMM_LIBRARIES_D
38     NAMES OpenMM_d
39     PATHS "${OpenMM_ROOT_DIR}/lib"
40     CACHE STRING "OpenMM debug libraries")
42 if(OpenMM_LIBRARIES_D AND NOT OpenMM_LIBRARIES)
43     set(OpenMM_LIBRARIES ${OpenMM_LIBRARIES_D}
44         CACHE STRING "OpenMM libraries" FORCE)
45     message(WARNING " Only found debug versions of the OpenMM libraries!")
46 endif()
48 get_filename_component(OpenMM_LIBRARY_DIR 
49     ${OpenMM_LIBRARIES} 
50     PATH
51     CACHE STRING "OpenMM library path")
53 find_path(OpenMM_INCLUDE_DIR 
54     NAMES OpenMM.h 
55     PATHS "${OpenMM_ROOT_DIR}/include" "${OpenMM_LIBRARY_DIR}/../include"
56     CACHE STRING "OpenMM include directory")    
58 # if we did not manage to set the root dir at the beginning but found the 
59 # libs then set the ${OpenMM_LIBRARY_DIR}/.. as root
60 if(NOT IS_DIRECTORY ${OpenMM_ROOT_DIR})
61     if (IS_DIRECTORY "${OpenMM_LIBRARY_DIR}/..") # just double-checking
62         get_filename_component(OpenMM_ROOT_DIR 
63             "${OpenMM_LIBRARY_DIR}/.." 
64             ABSOLUTE)
65     endif()   
66 endif()
68 if(NOT IS_DIRECTORY ${OpenMM_ROOT_DIR})
69     message(FATAL_ERROR "Can't find OpenMM! Either set the OPENMM_ROOT_DIR environment " 
70     "variable to the path where your OpenMM installation is located or install it to the default location (/usr/local/openmm)!")
71 endif()
73 if(NOT IS_DIRECTORY ${OpenMM_LIBRARY_DIR})
74     message(FATAL_ERROR "Can't find OpenMM libraries. Check your OpenMM installation!")
75 endif()
77 # now we can be sure that we have the library dir
78 if(IS_DIRECTORY "${OpenMM_LIBRARY_DIR}/plugins")
79     get_filename_component(OpenMM_PLUGIN_DIR
80         "${OpenMM_LIBRARY_DIR}/plugins"
81         ABSOLUTE)
82     set(OpenMM_PLUGIN_DIR ${OpenMM_PLUGIN_DIR} CACHE PATH "OpenMM plugins directory")
83 else()
84     message(WARNING "Could not detect the OpenMM plugin directory at the default location (${OpenMM_LIBRARY_DIR}/plugins)."
85             "Check you OpenMM installation or manually set the OPENMM_PLUGIN_DIR environment variable!")
86 endif()
88 if(NOT OpenMM_INCLUDE_DIR)
89     message(FATAL_ERROR "Can't find OpenMM includes. Check your OpenMM installation!")
90 endif()
92 set(OpenMM_ROOT_DIR ${OpenMM_ROOT_DIR} CACHE PATH "OpenMM installation directory")
94 include(FindPackageHandleStandardArgs)
95 find_package_handle_standard_args(OpenMM DEFAULT_MSG 
96                                     OpenMM_ROOT_DIR
97                                     OpenMM_LIBRARIES 
98                                     OpenMM_LIBRARY_DIR 
99                                     OpenMM_INCLUDE_DIR)
101 mark_as_advanced(OpenMM_INCLUDE_DIR
102     OpenMM_LIBRARIES
103     OpenMM_LIBRARIES_D
104     OpenMM_LIBRARY_DIR)