Findexpat.cmake 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. # the following is like an include guard:
  9. if (TARGET 3rdParty::expat)
  10. return()
  11. endif()
  12. # Even though expat itself exports it as lowercase expat, older cmake (and cmake's built-in targets)
  13. # expect uppercase. So we define both, for backwards compat:
  14. # See https://cmake.org/cmake/help/latest/module/FindEXPAT.html for how CMake exports it.
  15. # in order to support old and new packages, we'll export it as CMake exports it but also
  16. # alias that to older legacy ones.
  17. if (WIN32)
  18. # on windows, expat adds the nonstandard 'lib' prefix and MD, dMD suffixes for
  19. # Multithreaded Dynamic CRT and debug Multithreaded Dynamic CRT
  20. # We don't use the debug version since its a pure C library with no C++ and thus will
  21. # not have an ITERATOR_DEBUG_LEVEL conflict
  22. set(PREFIX_TO_USE "lib")
  23. set(SUFFIX_TO_USE "MD.lib")
  24. else()
  25. # on other platforms its just standard prefixes and suffix
  26. set(PREFIX_TO_USE ${CMAKE_STATIC_LIBRARY_PREFIX})
  27. set(SUFFIX_TO_USE ${CMAKE_STATIC_LIBRARY_SUFFIX})
  28. endif()
  29. set(EXPAT_VERSION_STRING "2.4.2")
  30. set(EXPAT_VERSION "2.4.2") # backward compat
  31. set(expat_VERSION "2.4.2") # backward compat
  32. set(EXPAT_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/expat/lib/${PREFIX_TO_USE}expat${SUFFIX_TO_USE})
  33. set(expat_LIBRARY ${EXPAT_LIBRARY})
  34. set(EXPAT_LIBRARIES ${EXPAT_LIBRARY}) # compatibility with CMake's FindEXPAT.cmake
  35. set(EXPAT_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/expat/include)
  36. set(expat_INCLUDE_DIR ${EXPAT_INCLUDE_DIR})
  37. set(EXPAT_INCLUDE_DIRS ${EXPAT_INCLUDE_DIR}) #compatibility with CMake's FindEXPAT file.
  38. set(EXPAT_FOUND TRUE) #compatibility with CMake's FindEXPAT file.
  39. set(expat_FOUND TRUE)
  40. add_library(expat::expat STATIC IMPORTED GLOBAL)
  41. set_target_properties(expat::expat PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C")
  42. set_target_properties(expat::expat PROPERTIES IMPORTED_LOCATION ${EXPAT_LIBRARY})
  43. target_compile_definitions(expat::expat INTERFACE XML_STATIC)
  44. if (COMMAND ly_target_include_system_directories)
  45. # inside the O3DE ecosystem, this macro makes sure it works even in cmake < 3.19
  46. ly_target_include_system_directories(TARGET expat::expat INTERFACE ${EXPAT_INCLUDE_DIR})
  47. else()
  48. # outside the O3DE ecosystem, we do our best...
  49. target_include_directories(expat::expat SYSTEM INTERFACE ${EXPAT_INCLUDE_DIR})
  50. endif()
  51. # create O3DE aliases:
  52. add_library(3rdParty::expat ALIAS expat::expat)
  53. # upppercase for compat:
  54. add_library(EXPAT::EXPAT ALIAS expat::expat) #compatibility with CMake's FindEXPAT file.
  55. # if we're not in O3DE, it's also extremely helpful to show a message to logs that indicate that this
  56. # library was successfully picked up, as opposed to the system one.
  57. # A good way to know if you're in O3DE or not is that O3DE sets various cache variables before
  58. # calling find_package, specifically, LY_VERSION_ENGINE_NAME is always set very early:
  59. if (NOT LY_VERSION_ENGINE_NAME)
  60. message(STATUS "Using O3DE expat ${expat_VERSION} from ${CMAKE_CURRENT_LIST_DIR}")
  61. endif()