1
0

Findqrcodegencpp.cmake 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #[=======================================================================[.rst
  2. Findqrcodegencpp
  3. ----------------
  4. FindModule for qrcodegencpp and associated libraries
  5. Imported Targets
  6. ^^^^^^^^^^^^^^^^
  7. .. versionadded:: 3.0
  8. This module defines the :prop_tgt:`IMPORTED` target ``qrcodegencpp::qrcodegencpp``.
  9. Result Variables
  10. ^^^^^^^^^^^^^^^^
  11. This module sets the following variables:
  12. ``qrcodegencpp_FOUND``
  13. True, if all required components and the core library were found.
  14. ``qrcodegencpp_VERSION``
  15. Detected version of found qrcodegencpp libraries.
  16. Cache variables
  17. ^^^^^^^^^^^^^^^
  18. The following cache variables may also be set:
  19. ``qrcodegencpp_LIBRARY``
  20. Path to the library component of qrcodegencpp.
  21. ``qrcodegencpp_INCLUDE_DIR``
  22. Directory containing ``qrcodegen.hpp``.
  23. #]=======================================================================]
  24. # cmake-format: off
  25. # cmake-lint: disable=C0103
  26. # cmake-lint: disable=C0301
  27. # cmake-format: on
  28. include(FindPackageHandleStandardArgs)
  29. find_package(PkgConfig QUIET)
  30. if(PKG_CONFIG_FOUND)
  31. pkg_search_module(PC_qrcodegencpp QUIET qrcodegencpp)
  32. endif()
  33. # qrcodegencpp_set_soname: Set SONAME on imported library target
  34. macro(qrcodegencpp_set_soname)
  35. if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
  36. execute_process(
  37. COMMAND sh -c "otool -D '${qrcodegencpp_LIBRARY}' | grep -v '${qrcodegencpp_LIBRARY}'"
  38. OUTPUT_VARIABLE _output
  39. RESULT_VARIABLE _result)
  40. if(_result EQUAL 0 AND _output MATCHES "^@rpath/")
  41. set_property(TARGET qrcodegencpp::qrcodegencpp PROPERTY IMPORTED_SONAME "${_output}")
  42. endif()
  43. elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD")
  44. execute_process(
  45. COMMAND sh -c "${CMAKE_OBJDUMP} -p '${qrcodegencpp_LIBRARY}' | grep SONAME"
  46. OUTPUT_VARIABLE _output
  47. RESULT_VARIABLE _result)
  48. if(_result EQUAL 0)
  49. string(REGEX REPLACE "[ \t]+SONAME[ \t]+([^ \t]+)" "\\1" _soname "${_output}")
  50. set_property(TARGET qrcodegencpp::qrcodegencpp PROPERTY IMPORTED_SONAME "${_soname}")
  51. unset(_soname)
  52. endif()
  53. endif()
  54. unset(_output)
  55. unset(_result)
  56. endmacro()
  57. # qrcodegencpp_find_dll: Find DLL for corresponding import library
  58. macro(qrcodegencpp_find_dll)
  59. cmake_path(GET qrcodegencpp_IMPLIB PARENT_PATH _implib_path)
  60. cmake_path(SET _bin_path NORMALIZE "${_implib_path}/../bin")
  61. string(REGEX REPLACE "[0-9]+\\.([0-9]+)\\.[0-9]+" "\\1" _dll_version "${qrcodegencpp_VERSION}")
  62. find_program(
  63. qrcodegencpp_LIBRARY
  64. NAMES qrcodegencpp.dll
  65. HINTS ${_implib_path} ${_bin_path}
  66. DOC "qrcodegencpp DLL location")
  67. if(NOT qrcodegencpp_LIBRARY)
  68. set(qrcodegencpp_LIBRARY "${qrcodegencpp_IMPLIB}")
  69. endif()
  70. unset(_implib_path)
  71. unset(_bin_path)
  72. unset(_dll_version)
  73. endmacro()
  74. find_path(
  75. qrcodegencpp_INCLUDE_DIR
  76. NAMES qrcodegen.hpp
  77. HINTS ${PC_qrcodegencpp_INCLUDE_DIRS}
  78. PATHS /usr/include /usr/local/include
  79. PATH_SUFFIXES qrcodegencpp qrcodegen
  80. DOC "qrcodegencpp include directory")
  81. if(PC_qrcodegencpp_VERSION VERSION_GREATER 0)
  82. set(qrcodegencpp_VERSION ${PC_qrcodegencpp_VERSION})
  83. else()
  84. if(NOT qrcodegencpp_FIND_QUIETLY)
  85. message(AUTHOR_WARNING "Failed to find qrcodegencpp version.")
  86. endif()
  87. set(qrcodegencpp_VERSION 0.0.0)
  88. endif()
  89. if(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
  90. find_library(
  91. qrcodegencpp_IMPLIB
  92. NAMES qrcodegencpp qrcodegencpp
  93. DOC "qrcodegencpp import library location")
  94. qrcodegencpp_find_dll()
  95. else()
  96. find_library(
  97. qrcodegencpp_LIBRARY
  98. NAMES qrcodegencpp qrcodegencpp
  99. HINTS ${PC_qrcodegencpp_LIBRARY_DIRS}
  100. PATHS /usr/lib /usr/local/lib
  101. DOC "qrcodegencpp location")
  102. endif()
  103. if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows")
  104. set(qrcodegencpp_ERROR_REASON "Ensure that a qrcodegencpp distribution is provided as part of CMAKE_PREFIX_PATH.")
  105. elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD")
  106. set(qrcodegencpp_ERROR_REASON "Ensure that qrcodegencpp is installed on the system.")
  107. endif()
  108. find_package_handle_standard_args(
  109. qrcodegencpp
  110. REQUIRED_VARS qrcodegencpp_LIBRARY qrcodegencpp_INCLUDE_DIR
  111. VERSION_VAR qrcodegencpp_VERSION REASON_FAILURE_MESSAGE "${qrcodegencpp_ERROR_REASON}")
  112. mark_as_advanced(qrcodegencpp_INCLUDE_DIR qrcodegencpp_LIBRARY qrcodegencpp_IMPLIB)
  113. unset(qrcodegencpp_ERROR_REASON)
  114. if(qrcodegencpp_FOUND)
  115. if(NOT TARGET qrcodegencpp::qrcodegencpp)
  116. if(IS_ABSOLUTE "${qrcodegencpp_LIBRARY}")
  117. if(DEFINED qrcodegencpp_IMPLIB)
  118. if(qrcodegencpp_IMPLIB STREQUAL qrcodegencpp_LIBRARY)
  119. add_library(qrcodegencpp::qrcodegencpp STATIC IMPORTED)
  120. else()
  121. add_library(qrcodegencpp::qrcodegencpp SHARED IMPORTED)
  122. set_property(TARGET qrcodegencpp::qrcodegencpp PROPERTY IMPORTED_IMPLIB "${qrcodegencpp_IMPLIB}")
  123. endif()
  124. else()
  125. add_library(qrcodegencpp::qrcodegencpp UNKNOWN IMPORTED)
  126. endif()
  127. set_property(TARGET qrcodegencpp::qrcodegencpp PROPERTY IMPORTED_LOCATION "${qrcodegencpp_LIBRARY}")
  128. else()
  129. add_library(qrcodegencpp::qrcodegencpp INTERFACE IMPORTED)
  130. set_property(TARGET qrcodegencpp::qrcodegencpp PROPERTY IMPORTED_LIBNAME "${qrcodegencpp_LIBRARY}")
  131. endif()
  132. qrcodegencpp_set_soname()
  133. set_target_properties(
  134. qrcodegencpp::qrcodegencpp
  135. PROPERTIES INTERFACE_COMPILE_OPTIONS "${PC_qrcodegencpp_CFLAGS_OTHER}"
  136. INTERFACE_INCLUDE_DIRECTORIES "${qrcodegencpp_INCLUDE_DIR}"
  137. VERSION ${qrcodegencpp_VERSION})
  138. endif()
  139. endif()
  140. include(FeatureSummary)
  141. set_package_properties(
  142. qrcodegencpp PROPERTIES
  143. URL "https://www.nayuki.io/page/qr-code-generator-library"
  144. DESCRIPTION "This project aims to be the best, clearest library for generating QR Codes in C++.")