Updated cool quotes
[gromacs.git] / cmake / FindVMD.cmake
blobe390bcd7fefc633668141815630a657f1297ea6d
2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2013, 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.
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.
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.
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.
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.
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.
35 # The module defines the following variables:
36 #   VMD_EXECUTABLE - path to vmd command
37 #   GMX_VMD_PLUGIN_PATH - path to vmd plugins
39 message(STATUS "Checking for suitable VMD version")
40 find_program(VMD_EXECUTABLE NAMES vmd PATH_SUFFIXES bin
41     DOC "VMD command")
43 #set search path in increasing priority:
44 # default path, vmd binary path, enviroment variable
45 set(VMD_PATHS "/usr/local/lib/vmd/plugins/*/molfile/")
46 if(VMD_EXECUTABLE)
47     file(STRINGS "${VMD_EXECUTABLE}" VMDDIR REGEX "^defaultvmddir=.*$")
48     string(REGEX REPLACE "(^.*=\"?|\"$)" "" VMDDIR "${VMDDIR}")
49     list(INSERT VMD_PATHS 0 "${VMDDIR}/plugins/*/molfile/")
50 endif()
51 if(NOT "$ENV{VMDDIR}" STREQUAL "")
52     list(INSERT VMD_PATHS 0 "$ENV{VMDDIR}/plugins/*/molfile/")
53 endif()
55 #xyz is just an example. Any other molfile plugin could be used.
56 #But some require extra link flags. VMD uses ".so" even on Windows.
57 find_library(VMDXYZPLUGIN NAME "xyzplugin.so"
58     PATHS ${VMD_PATHS})
60 if (VMDXYZPLUGIN)
61     try_run(TESTVMD TESTVMD_COMPILED ${CMAKE_BINARY_DIR}
62         "${CMAKE_SOURCE_DIR}/cmake/TestVMD.c"
63         CMAKE_FLAGS "-DLINK_LIBRARIES=${CMAKE_DL_LIBS}"
64             "-DINCLUDE_DIRECTORIES=${CMAKE_SOURCE_DIR}/src/gmxlib"
65         COMPILE_DEFINITIONS "-DGMX_USE_PLUGINS"
66         RUN_OUTPUT_VARIABLE TESTVMD_OUTPUT ARGS ${VMDXYZPLUGIN})
67 endif()
69 if(NOT TESTVMD EQUAL 0)
70     if (NOT VMDXYZPLUGIN)
71         message(STATUS "VMD plugins not found. Path to VMD can be set with VMDDIR.")
72     elseif(NOT TESTVMD_COMPILED)
73         message(STATUS "Could not compile VMD version check")
74     elseif(TESTVMD EQUAL 1)
75         message(STATUS "Could not load VMD plugin ${VMDXYZPLUGIN}: ${TESTVMD_OUTPUT}")
76     elseif(TESTVMD EQUAL 5)
77         message(STATUS "VMD plugin ${VMDXYZPLUGIN} too old. VMD 1.8.6 required.")
78     else()
79         message(STATUS "Could not identify VMD version of ${VMDXYZPLUGIN}. Error: ${TESTVMD}")
80     endif()
81     # This permits GROMACS to avoid hard-coding a fall-back path.
82     # Fall-back is useful in case VMD is installed later.
83     set(GMX_VMD_PLUGIN_PATH "/usr/local/lib/vmd/plugins/*/molfile"
84         CACHE PATH "Path to VMD plugins for molfile I/O" FORCE)
85 else()
86     get_filename_component(VMD_PLUGIN_PATH ${VMDXYZPLUGIN} PATH)
87     message(STATUS "VMD version of ${VMD_PLUGIN_PATH} is suitable")
88     set(GMX_VMD_PLUGIN_PATH ${VMD_PLUGIN_PATH}
89         CACHE PATH "Path to VMD plugins for molfile I/O" FORCE)
90 endif()
91 mark_as_advanced(GMX_VMD_PLUGIN_PATH)
92 #Nothing is rerun unless GMX_VMD_PLUGIN_PATH is set to NO. Clean-up all.
93 unset(VMDXYZPLUGIN CACHE)
94 unset(VMD_EXECUTABLE CACHE)
95 unset(TESTVMD CACHE)
96 unset(TESTVMD_COMPILED CACHE)
97 unset(VMD_PATHS)
98 unset(VMD_PLUGIN_PATH)
99 unset(VMDDIR)