Update instructions in containers.rst
[gromacs.git] / cmake / FindLmfit.cmake
blob4f9b3ecee87013040fe45298070b18fbbcfa1ab6
2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2016,2018, 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 # This package tries to find an external lmfit library, version
36 # 7. Note that pkg-config support was removed before version 7, so is
37 # no longer supported here. Upon exit, the following variables may be
38 # set:
40 # LMFIT_FOUND       - lmfit was found
41 # LMFIT_INCLUDE_DIR - lmfit include directory
42 # LMFIT_LIBRARY     - lmfit library
43 # LMFIT_LINKS_OK    - lmfit libraries link correctly
44 # LMFIT_VERSION     - lmfit version string as "major.minor"
46 # CMake will search the CMAKE_PREFIX_PATH in the usual way, but if you
47 # need more control then setting LMFIT_INCLUDE_DIR and LMFIT_LIBRARY
48 # on the cmake command line to suitable values will work.
50 include(CMakePushCheckState)
51 cmake_push_check_state()
53 find_package(PkgConfig QUIET)
54 if(PKG_CONFIG_FOUND)
55     if(LMFIT_FIND_VERSION)
56         # lmfit doesn't support CMake-based find_package version
57         # checking in 6.1, so this code does nothing.
58         if(LMFIT_FIND_VERSION_EXACT)
59             pkg_check_modules(PC_LMFIT QUIET lmfit=${LMFIT_FIND_VERSION})
60         else()
61             pkg_check_modules(PC_LMFIT QUIET lmfit>=${LMFIT_FIND_VERSION})
62         endif()
63     else()
64         pkg_check_modules(PC_LMFIT QUIET lmfit)
65         if (PC_LMFIT_VERSION)
66             string(REGEX REPLACE "^([0-9]+):([0-9]+)" "\\1.\\2" LMFIT_VERSION "${PC_LMFIT_VERSION}")
67         endif()
68     endif()
69 endif()
71 # Try to find lmfit, perhaps with help from pkg-config
72 find_path(LMFIT_INCLUDE_DIR lmcurve.h HINTS "${PC_LMFIT_INCLUDE_DIRS}" PATH_SUFFIXES include)
73 find_library(LMFIT_LIBRARY NAMES lmfit HINTS "${PC_LMFIT_LIBRARY_DIRS}" PATH_SUFFIXES lib64 lib)
75 # Make sure we can also link, so that cross-compilation is properly supported
76 if (LMFIT_INCLUDE_DIR AND LMFIT_LIBRARY)
77     include(CheckCXXSourceCompiles)
78     set(CMAKE_REQUIRED_INCLUDES ${LMFIT_INCLUDE_DIR})
79     set(CMAKE_REQUIRED_LIBRARIES ${LMFIT_LIBRARY})
80     check_cxx_source_compiles("#include <lmcurve.h>\nint main(){lmcurve(0,0,0,0,0,0,0,0);}" LMFIT_LINKS_OK)
81 endif()
83 include(FindPackageHandleStandardArgs)
84 find_package_handle_standard_args(lmfit
85     FOUND_VAR
86     LMFIT_FOUND
87     REQUIRED_VARS
88     LMFIT_INCLUDE_DIR
89     LMFIT_LIBRARY
90     LMFIT_LINKS_OK
91     VERSION_VAR
92     LMFIT_VERSION)
94 mark_as_advanced(LMFIT_INCLUDE_DIR LMFIT_LIBRARY)
96 # Make a target that other targets can depend on just like this was a
97 # library built in the main project.
98 if (LMFIT_FOUND)
99     add_library(lmfit INTERFACE IMPORTED)
100     set_target_properties(lmfit PROPERTIES
101         INTERFACE_INCLUDE_DIRECTORIES "${LMFIT_INCLUDE_DIR}"
102         INTERFACE_LINK_LIBRARIES "${LMFIT_LIBRARY}"
103         )
104 endif()
106 cmake_pop_check_state()