]> git.cworth.org Git - vogl/blob - src/cmake/Modules/FindTinyXML.cmake
Added a simple find_package module for TinyXML.cmake;
[vogl] / src / cmake / Modules / FindTinyXML.cmake
1 ##################################################################################################
2 #
3 # CMake script for finding TinyXML.
4 #
5 # Input variables:
6 #
7 # - TinyXML_ROOT_DIR (optional): When specified, header files and libraries will be searched for in
8 #     ${TinyXML_ROOT_DIR}/include
9 #     ${TinyXML_ROOT_DIR}/libs
10 #   respectively, and the default CMake search order will be ignored. When unspecified, the default
11 #   CMake search order is used.
12 #   This variable can be specified either as a CMake or environment variable. If both are set,
13 #   preference is given to the CMake variable.
14 #   Use this variable for finding packages installed in a nonstandard location, or for enforcing
15 #   that one of multiple package installations is picked up.
16 #
17 #
18 # Cache variables (not intended to be used in CMakeLists.txt files)
19 #
20 # - TinyXML_INCLUDE_DIR: Absolute path to package headers.
21 # - TinyXML_LIBRARY: Absolute path to library.
22 #
23 #
24 # Output variables:
25 #
26 # - TinyXML_FOUND: Boolean that indicates if the package was found
27 # - TinyXML_INCLUDE_DIRS: Paths to the necessary header files
28 # - TinyXML_LIBRARIES: Package libraries
29 #
30 #
31 # Example usage:
32 #
33 #  find_package(TinyXML)
34 #  if(NOT TinyXML_FOUND)
35 #    # Error handling
36 #  endif()
37 #  ...
38 #  include_directories(${TinyXML_INCLUDE_DIRS} ...)
39 #  ...
40 #  target_link_libraries(my_target ${TinyXML_LIBRARIES})
41 #
42 ##################################################################################################
43 #from: https://github.com/ros/cmake_modules/blob/0.3-devel/cmake/Modules/FindTinyXML.cmake
44
45 # Get package location hint from environment variable (if any)
46 if(NOT TinyXML_ROOT_DIR AND DEFINED ENV{TinyXML_ROOT_DIR})
47   set(TinyXML_ROOT_DIR "$ENV{TinyXML_ROOT_DIR}" CACHE PATH
48       "TinyXML base directory location (optional, used for nonstandard installation paths)")
49 endif()
50
51 # Search path for nonstandard package locations
52 if(TinyXML_ROOT_DIR)
53   set(TinyXML_INCLUDE_PATH PATHS "${TinyXML_ROOT_DIR}/include" NO_DEFAULT_PATH)
54   set(TinyXML_LIBRARY_PATH PATHS "${TinyXML_ROOT_DIR}/lib"     NO_DEFAULT_PATH)
55 endif()
56
57 # Find headers and libraries
58 find_path(TinyXML_INCLUDE_DIR NAMES tinyxml.h PATH_SUFFIXES "tinyxml" ${TinyXML_INCLUDE_PATH})
59 find_library(TinyXML_LIBRARY  NAMES tinyxml   PATH_SUFFIXES "tinyxml" ${TinyXML_LIBRARY_PATH})
60
61 mark_as_advanced(TinyXML_INCLUDE_DIR
62                  TinyXML_LIBRARY)
63
64 # Output variables generation
65 include(FindPackageHandleStandardArgs)
66 find_package_handle_standard_args(TinyXML DEFAULT_MSG TinyXML_LIBRARY
67                                                       TinyXML_INCLUDE_DIR)
68
69 set(TinyXML_FOUND ${TINYXML_FOUND}) # Enforce case-correctness: Set appropriately cased variable...
70 unset(TINYXML_FOUND) # ...and unset uppercase variable generated by find_package_handle_standard_args
71
72 if(TinyXML_FOUND)
73   set(TinyXML_INCLUDE_DIRS ${TinyXML_INCLUDE_DIR})
74   set(TinyXML_LIBRARIES ${TinyXML_LIBRARY})
75 endif()