zxing.cmake 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. macro(zxing_add_package_stb)
  2. unset (STB_FOUND CACHE)
  3. if (ZXING_DEPENDENCIES STREQUAL "AUTO")
  4. find_package(PkgConfig)
  5. pkg_check_modules (STB IMPORTED_TARGET stb)
  6. elseif (ZXING_DEPENDENCIES STREQUAL "LOCAL")
  7. find_package(PkgConfig REQUIRED)
  8. pkg_check_modules (STB REQUIRED IMPORTED_TARGET stb)
  9. endif()
  10. if (NOT STB_FOUND)
  11. include(FetchContent)
  12. FetchContent_Declare (stb
  13. GIT_REPOSITORY https://github.com/nothings/stb.git)
  14. FetchContent_MakeAvailable (stb)
  15. add_library(stb::stb INTERFACE IMPORTED)
  16. target_include_directories(stb::stb INTERFACE ${stb_SOURCE_DIR})
  17. else()
  18. add_library(stb::stb ALIAS PkgConfig::STB)
  19. endif()
  20. endmacro()
  21. macro(zxing_add_package name depname git_repo git_rev)
  22. unset(${name}_FOUND CACHE) # see https://github.com/zxing-cpp/zxing-cpp/commit/8db14eeead45e0f1961532f55061d5e4dd0f78be#commitcomment-66464026
  23. if (ZXING_DEPENDENCIES STREQUAL "AUTO")
  24. find_package (${name} CONFIG)
  25. elseif (ZXING_DEPENDENCIES STREQUAL "LOCAL")
  26. find_package (${name} REQUIRED CONFIG)
  27. endif()
  28. if (NOT ${name}_FOUND)
  29. include(FetchContent)
  30. FetchContent_Declare (${depname}
  31. GIT_REPOSITORY ${git_repo}
  32. GIT_TAG ${git_rev})
  33. if (${depname} STREQUAL "googletest")
  34. # Prevent overriding the parent project's compiler/linker settings on Windows
  35. set (gtest_force_shared_crt ON CACHE BOOL "" FORCE)
  36. endif()
  37. #FetchContent_MakeAvailable (${depname})
  38. # TODO: reqire cmake 3.28 and pass EXCLUDE_FROM_ALL to FetchContent_Declare instead of calling FetchContent_Populate below.
  39. # This would fix a warning but cmake 3.28 is not in Debian bookworm but at least in Ubuntu 24.04 (LTS)
  40. FetchContent_GetProperties(${depname})
  41. if(NOT ${depname}_POPULATED)
  42. FetchContent_Populate(${depname})
  43. add_subdirectory(${${depname}_SOURCE_DIR} ${${depname}_BINARY_DIR} EXCLUDE_FROM_ALL) # prevent installing of dependencies
  44. endif()
  45. set (${name}_POPULATED TRUE) # this is supposed to be done in MakeAvailable but it seems not to?!?
  46. endif()
  47. endmacro()