Findnlohmann_json.cmake 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # SPDX-FileCopyrightText: 2020 yuzu Emulator Project
  2. # SPDX-License-Identifier: GPL-2.0-or-later
  3. find_package(PkgConfig QUIET)
  4. pkg_check_modules(PC_nlohmann_json QUIET nlohmann_json)
  5. find_path(nlohmann_json_INCLUDE_DIR
  6. NAMES json.hpp
  7. PATHS ${PC_nlohmann_json_INCLUDE_DIRS}
  8. PATH_SUFFIXES nlohmann
  9. )
  10. if(nlohmann_json_INCLUDE_DIR)
  11. file(STRINGS "${nlohmann_json_INCLUDE_DIR}/json.hpp" _nlohmann_json_version_lines
  12. REGEX "#define[ \t]+NLOHMANN_JSON_VERSION_(MAJOR|MINOR|PATCH)")
  13. string(REGEX REPLACE ".*NLOHMANN_JSON_VERSION_MAJOR +\([0-9]+\).*" "\\1" _nlohmann_json_version_major "${_nlohmann_json_version_lines}")
  14. string(REGEX REPLACE ".*NLOHMANN_JSON_VERSION_MINOR +\([0-9]+\).*" "\\1" _nlohmann_json_version_minor "${_nlohmann_json_version_lines}")
  15. string(REGEX REPLACE ".*NLOHMANN_JSON_VERSION_PATCH +\([0-9]+\).*" "\\1" _nlohmann_json_version_patch "${_nlohmann_json_version_lines}")
  16. set(nlohmann_json_VERSION "${_nlohmann_json_version_major}.${_nlohmann_json_version_minor}.${_nlohmann_json_version_patch}")
  17. unset(_nlohmann_json_version_major)
  18. unset(_nlohmann_json_version_minor)
  19. unset(_nlohmann_json_version_patch)
  20. unset(_nlohmann_json_version_lines)
  21. endif()
  22. include(FindPackageHandleStandardArgs)
  23. find_package_handle_standard_args(nlohmann_json
  24. FOUND_VAR nlohmann_json_FOUND
  25. REQUIRED_VARS
  26. nlohmann_json_INCLUDE_DIR
  27. nlohmann_json_VERSION
  28. VERSION_VAR nlohmann_json_VERSION
  29. )
  30. if(nlohmann_json_FOUND)
  31. set(nlohmann_json_INCLUDE_DIRS ${nlohmann_json_INCLUDE_DIR})
  32. set(nlohmann_json_DEFINITIONS ${PC_nlohmann_json_CFLAGS_OTHER})
  33. endif()
  34. if(nlohmann_json_FOUND AND NOT TARGET nlohmann_json::nlohmann_json)
  35. add_library(nlohmann_json::nlohmann_json UNKNOWN IMPORTED)
  36. set_target_properties(nlohmann_json::nlohmann_json PROPERTIES
  37. IMPORTED_LOCATION "${nlohmann_json_LIBRARY}"
  38. INTERFACE_COMPILE_OPTIONS "${PC_nlohmann_json_CFLAGS_OTHER}"
  39. INTERFACE_INCLUDE_DIRECTORIES "${nlohmann_json_INCLUDE_DIR}"
  40. )
  41. endif()
  42. mark_as_advanced(
  43. nlohmann_json_INCLUDE_DIR
  44. )