FindTinyXML.cmake 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. # Get package location hint from environment variable (if any)
  44. if(NOT TinyXML_ROOT_DIR AND DEFINED ENV{TinyXML_ROOT_DIR})
  45. set(TinyXML_ROOT_DIR "$ENV{TinyXML_ROOT_DIR}" CACHE PATH
  46. "TinyXML base directory location (optional, used for nonstandard installation paths)")
  47. endif()
  48. # Search path for nonstandard package locations
  49. if(TinyXML_ROOT_DIR)
  50. set(TinyXML_INCLUDE_PATH PATHS "${TinyXML_ROOT_DIR}/include" NO_DEFAULT_PATH)
  51. set(TinyXML_LIBRARY_PATH PATHS "${TinyXML_ROOT_DIR}/lib" NO_DEFAULT_PATH)
  52. endif()
  53. # Find headers and libraries
  54. find_path(TinyXML_INCLUDE_DIR NAMES tinyxml.h PATH_SUFFIXES "tinyxml" ${TinyXML_INCLUDE_PATH})
  55. find_library(TinyXML_LIBRARY NAMES tinyxml PATH_SUFFIXES "tinyxml" ${TinyXML_LIBRARY_PATH})
  56. mark_as_advanced(TinyXML_INCLUDE_DIR
  57. TinyXML_LIBRARY)
  58. # Output variables generation
  59. include(FindPackageHandleStandardArgs)
  60. find_package_handle_standard_args(TinyXML DEFAULT_MSG TinyXML_LIBRARY
  61. TinyXML_INCLUDE_DIR)
  62. set(TinyXML_FOUND ${TINYXML_FOUND}) # Enforce case-correctness: Set appropriately cased variable...
  63. unset(TINYXML_FOUND) # ...and unset uppercase variable generated by find_package_handle_standard_args
  64. if(TinyXML_FOUND)
  65. set(TinyXML_INCLUDE_DIRS ${TinyXML_INCLUDE_DIR})
  66. set(TinyXML_LIBRARIES ${TinyXML_LIBRARY})
  67. endif()