Remove cycle suppression
[gromacs.git] / cmake / FindTinyXML-2.cmake
blob37e324518d8374bddf8d2311ea7f97e5a4c5f50a
2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2016, 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 the TinyXML-2 library. It will consider
36 # the directory ${TinyXML2_DIR} in its search. Upon exit, the
37 # following variables may be set:
39 # TinyXML2_FOUND       - TinyXML-2 was found
40 # TinyXML2_INCLUDE_DIR - TinyXML-2 include directory
41 # TinyXML2_LIBRARIES   - TinyXML-2 libraries
42 # TinyXML2_LINKS_OK    - TinyXML-2 libraries link correctly
43 # TinyXML2_VERSION     - TinyXML-2 version string as "major.minor"
45 include(CMakePushCheckState)
46 cmake_push_check_state()
48 find_package(PkgConfig QUIET)
49 if(PKG_CONFIG_FOUND)
50     if(TinyXML2_FIND_VERSION)
51         if(TinyXML2_FIND_VERSION_EXACT)
52             pkg_check_modules(PC_TINYXML2 QUIET tinyxml2=${TinyXML2_FIND_VERSION})
53         else()
54             pkg_check_modules(PC_TINYXML2 QUIET tinyxml2>=${TinyXML2_FIND_VERSION})
55         endif()
56     else()
57         pkg_check_modules(PC_TINYXML2 QUIET tinyxml2)
58     endif()
59 endif()
61 # Try to find tinyxml2, perhaps with help from pkg-config
62 find_path(TinyXML2_INCLUDE_DIR tinyxml2.h HINTS "${TinyXML2_DIR}" "${PC_TINYXML2_INCLUDE_DIRS}" PATH_SUFFIXES include)
63 find_library(TinyXML2_LIBRARIES NAMES tinyxml2 HINTS "${TinyXML2_DIR}" "${PC_TINYXML2_LIBRARIES}" PATH_SUFFIXES lib64 lib)
65 if(TinyXML2_INCLUDE_DIR AND EXISTS "${TinyXML2_INCLUDE_DIR}/tinyxml2.h" AND TinyXML2_LIBRARIES)
66     file(STRINGS "${TinyXML2_INCLUDE_DIR}/tinyxml2.h" _TinyXML2_H_MAJOR REGEX "TIXML2_MAJOR_VERSION = [0-9]+;")
67     file(STRINGS "${TinyXML2_INCLUDE_DIR}/tinyxml2.h" _TinyXML2_H_MINOR REGEX "TIXML2_MINOR_VERSION = [0-9]+;")
68     string(REGEX REPLACE "TIXML2_MAJOR_VERSION = ([0-9]+);" "\\1" _TinyXML2_MAJOR_VERSION "${_TinyXML2_H_MAJOR}")
69     string(REGEX REPLACE "TIXML2_MINOR_VERSION = ([0-9]+);" "\\1" _TinyXML2_MINOR_VERSION "${_TinyXML2_H_MINOR}")
70     set(TinyXML2_VERSION "${_TinyXML2_MAJOR_VERSION}.${_TinyXML2_MINOR_VERSION}")
71 endif()
73 # Make sure we can also link, so that cross-compilation is properly supported
74 if (TinyXML2_INCLUDE_DIR AND TinyXML2_LIBRARIES)
75     include(CheckCXXSourceCompiles)
76     set(CMAKE_REQUIRED_INCLUDES ${TinyXML2_INCLUDE_DIR})
77     set(CMAKE_REQUIRED_LIBRARIES ${TinyXML2_LIBRARIES})
78     check_cxx_source_compiles("#include <tinyxml2.h>\nint main(){tinyxml2::XMLDocument doc;}" TinyXML2_LINKS_OK)
79 endif()
81 include(FindPackageHandleStandardArgs)
82 find_package_handle_standard_args(TinyXML2
83     FOUND_VAR
84     TinyXML2_FOUND
85     REQUIRED_VARS
86     TinyXML2_INCLUDE_DIR
87     TinyXML2_LIBRARIES
88     TinyXML2_LINKS_OK
89     VERSION_VAR
90     TinyXML2_VERSION)
92 mark_as_advanced(TinyXML2_INCLUDE_DIR TinyXML2_LIBRARIES)
94 cmake_pop_check_state()