Findqrcodegencpp.cmake 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. include(FindPackageHandleStandardArgs)
  25. find_package(PkgConfig QUIET)
  26. if(PKG_CONFIG_FOUND)
  27. pkg_search_module(PC_qrcodegencpp QUIET qrcodegencpp)
  28. endif()
  29. # qrcodegencpp_set_soname: Set SONAME on imported library target
  30. macro(qrcodegencpp_set_soname)
  31. if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
  32. execute_process(
  33. COMMAND sh -c "otool -D '${qrcodegencpp_LIBRARY}' | grep -v '${qrcodegencpp_LIBRARY}'"
  34. OUTPUT_VARIABLE _output
  35. RESULT_VARIABLE _result
  36. )
  37. if(_result EQUAL 0 AND _output MATCHES "^@rpath/")
  38. set_property(TARGET qrcodegencpp::qrcodegencpp PROPERTY IMPORTED_SONAME "${_output}")
  39. endif()
  40. elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD")
  41. execute_process(
  42. COMMAND sh -c "${CMAKE_OBJDUMP} -p '${qrcodegencpp_LIBRARY}' | grep SONAME"
  43. OUTPUT_VARIABLE _output
  44. RESULT_VARIABLE _result
  45. )
  46. if(_result EQUAL 0)
  47. string(REGEX REPLACE "[ \t]+SONAME[ \t]+([^ \t]+)" "\\1" _soname "${_output}")
  48. set_property(TARGET qrcodegencpp::qrcodegencpp PROPERTY IMPORTED_SONAME "${_soname}")
  49. unset(_soname)
  50. endif()
  51. endif()
  52. unset(_output)
  53. unset(_result)
  54. endmacro()
  55. # qrcodegencpp_find_dll: Find DLL for corresponding import library
  56. macro(qrcodegencpp_find_dll)
  57. cmake_path(GET qrcodegencpp_IMPLIB PARENT_PATH _implib_path)
  58. cmake_path(SET _bin_path NORMALIZE "${_implib_path}/../bin")
  59. string(REGEX REPLACE "[0-9]+\\.([0-9]+)\\.[0-9]+" "\\1" _dll_version "${qrcodegencpp_VERSION}")
  60. find_program(
  61. qrcodegencpp_LIBRARY
  62. NAMES qrcodegencpp.dll
  63. HINTS ${_implib_path} ${_bin_path}
  64. DOC "qrcodegencpp DLL location"
  65. )
  66. if(NOT qrcodegencpp_LIBRARY)
  67. set(qrcodegencpp_LIBRARY "${qrcodegencpp_IMPLIB}")
  68. endif()
  69. unset(_implib_path)
  70. unset(_bin_path)
  71. unset(_dll_version)
  72. endmacro()
  73. find_path(
  74. qrcodegencpp_INCLUDE_DIR
  75. NAMES qrcodegen.hpp
  76. HINTS ${PC_qrcodegencpp_INCLUDE_DIRS}
  77. PATHS /usr/include /usr/local/include
  78. PATH_SUFFIXES qrcodegencpp qrcodegen
  79. DOC "qrcodegencpp include directory"
  80. )
  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(qrcodegencpp_IMPLIB NAMES qrcodegencpp qrcodegencpp DOC "qrcodegencpp import library location")
  91. qrcodegencpp_find_dll()
  92. else()
  93. find_library(
  94. qrcodegencpp_LIBRARY
  95. NAMES qrcodegencpp qrcodegencpp
  96. HINTS ${PC_qrcodegencpp_LIBRARY_DIRS}
  97. PATHS /usr/lib /usr/local/lib
  98. DOC "qrcodegencpp location"
  99. )
  100. endif()
  101. if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows")
  102. set(qrcodegencpp_ERROR_REASON "Ensure that a qrcodegencpp distribution is provided as part of CMAKE_PREFIX_PATH.")
  103. elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD")
  104. set(qrcodegencpp_ERROR_REASON "Ensure that qrcodegencpp is installed on the system.")
  105. endif()
  106. find_package_handle_standard_args(
  107. qrcodegencpp
  108. REQUIRED_VARS qrcodegencpp_LIBRARY qrcodegencpp_INCLUDE_DIR
  109. VERSION_VAR qrcodegencpp_VERSION
  110. REASON_FAILURE_MESSAGE "${qrcodegencpp_ERROR_REASON}"
  111. )
  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
  136. INTERFACE_COMPILE_OPTIONS "${PC_qrcodegencpp_CFLAGS_OTHER}"
  137. INTERFACE_INCLUDE_DIRECTORIES "${qrcodegencpp_INCLUDE_DIR}"
  138. VERSION ${qrcodegencpp_VERSION}
  139. )
  140. endif()
  141. endif()
  142. include(FeatureSummary)
  143. set_package_properties(
  144. qrcodegencpp
  145. PROPERTIES
  146. URL "https://www.nayuki.io/page/qr-code-generator-library"
  147. DESCRIPTION "This project aims to be the best, clearest library for generating QR Codes in C++."
  148. )