FindLibqrcodegencpp.cmake 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #[=======================================================================[.rst
  2. FindLibqrcodegencpp
  3. -------------------
  4. FindModule for Libqrcodegencpp and associated libraries
  5. Imported Targets
  6. ^^^^^^^^^^^^^^^^
  7. .. versionadded:: 3.0
  8. This module defines the :prop_tgt:`IMPORTED` target ``Libqrcodegencpp::Libqrcodegencpp``.
  9. Result Variables
  10. ^^^^^^^^^^^^^^^^
  11. This module sets the following variables:
  12. ``Libqrcodegencpp_FOUND``
  13. True, if all required components and the core library were found.
  14. ``Libqrcodegencpp_VERSION``
  15. Detected version of found Libqrcodegencpp libraries.
  16. Cache variables
  17. ^^^^^^^^^^^^^^^
  18. The following cache variables may also be set:
  19. ``Libqrcodegencpp_LIBRARY``
  20. Path to the library component of Libqrcodegencpp.
  21. ``Libqrcodegencpp_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_Libqrcodegencpp QUIET qrcodegencpp)
  32. endif()
  33. # Libqrcodegencpp_set_soname: Set SONAME on imported library target
  34. macro(Libqrcodegencpp_set_soname)
  35. if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
  36. execute_process(
  37. COMMAND sh -c "otool -D '${Libqrcodegencpp_LIBRARY}' | grep -v '${Libqrcodegencpp_LIBRARY}'"
  38. OUTPUT_VARIABLE _output
  39. RESULT_VARIABLE _result)
  40. if(_result EQUAL 0 AND _output MATCHES "^@rpath/")
  41. set_property(TARGET Libqrcodegencpp::Libqrcodegencpp 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 '${Libqrcodegencpp_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 Libqrcodegencpp::Libqrcodegencpp PROPERTY IMPORTED_SONAME "${_soname}")
  51. unset(_soname)
  52. endif()
  53. endif()
  54. unset(_output)
  55. unset(_result)
  56. endmacro()
  57. # Libqrcodegencpp_find_dll: Find DLL for corresponding import library
  58. macro(Libqrcodegencpp_find_dll)
  59. cmake_path(GET Libqrcodegencpp_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 "${Libqrcodegencpp_VERSION}")
  62. find_program(
  63. Libqrcodegencpp_LIBRARY
  64. NAMES qrcodegencpp.dll
  65. HINTS ${_implib_path} ${_bin_path}
  66. DOC "Libqrcodegencpp DLL location")
  67. if(NOT Libqrcodegencpp_LIBRARY)
  68. set(Libqrcodegencpp_LIBRARY "${Libqrcodegencpp_IMPLIB}")
  69. endif()
  70. unset(_implib_path)
  71. unset(_bin_path)
  72. unset(_dll_version)
  73. endmacro()
  74. find_path(
  75. Libqrcodegencpp_INCLUDE_DIR
  76. NAMES qrcodegen.hpp
  77. HINTS ${PC_Libqrcodegencpp_INCLUDE_DIRS}
  78. PATHS /usr/include /usr/local/include
  79. PATH_SUFFIXES qrcodegencpp qrcodegen
  80. DOC "Libqrcodegencpp include directory")
  81. if(PC_Libqrcodegencpp_VERSION VERSION_GREATER 0)
  82. set(Libqrcodegencpp_VERSION ${PC_Libqrcodegencpp_VERSION})
  83. else()
  84. if(NOT Libqrcodegencpp_FIND_QUIETLY)
  85. message(AUTHOR_WARNING "Failed to find Libqrcodegencpp version.")
  86. endif()
  87. set(Libqrcodegencpp_VERSION 0.0.0)
  88. endif()
  89. if(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
  90. find_library(
  91. Libqrcodegencpp_IMPLIB
  92. NAMES libqrcodegencpp qrcodegencpp
  93. DOC "Libqrcodegencpp import library location")
  94. libqrcodegencpp_find_dll()
  95. else()
  96. find_library(
  97. Libqrcodegencpp_LIBRARY
  98. NAMES libqrcodegencpp qrcodegencpp
  99. HINTS ${PC_Libqrcodegencpp_LIBRARY_DIRS}
  100. PATHS /usr/lib /usr/local/lib
  101. DOC "Libqrcodegencpp location")
  102. endif()
  103. if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows")
  104. set(Libqrcodegencpp_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(Libqrcodegencpp_ERROR_REASON "Ensure that qrcodegencpp is installed on the system.")
  107. endif()
  108. find_package_handle_standard_args(
  109. Libqrcodegencpp
  110. REQUIRED_VARS Libqrcodegencpp_LIBRARY Libqrcodegencpp_INCLUDE_DIR
  111. VERSION_VAR Libqrcodegencpp_VERSION REASON_FAILURE_MESSAGE "${Libqrcodegencpp_ERROR_REASON}")
  112. mark_as_advanced(Libqrcodegencpp_INCLUDE_DIR Libqrcodegencpp_LIBRARY Libqrcodegencpp_IMPLIB)
  113. unset(Libqrcodegencpp_ERROR_REASON)
  114. if(Libqrcodegencpp_FOUND)
  115. if(NOT TARGET Libqrcodegencpp::Libqrcodegencpp)
  116. if(IS_ABSOLUTE "${Libqrcodegencpp_LIBRARY}")
  117. if(DEFINED Libqrcodegencpp_IMPLIB)
  118. if(Libqrcodegencpp_IMPLIB STREQUAL Libqrcodegencpp_LIBRARY)
  119. add_library(Libqrcodegencpp::Libqrcodegencpp STATIC IMPORTED)
  120. else()
  121. add_library(Libqrcodegencpp::Libqrcodegencpp SHARED IMPORTED)
  122. set_property(TARGET Libqrcodegencpp::Libqrcodegencpp PROPERTY IMPORTED_IMPLIB "${Libqrcodegencpp_IMPLIB}")
  123. endif()
  124. else()
  125. add_library(Libqrcodegencpp::Libqrcodegencpp UNKNOWN IMPORTED)
  126. endif()
  127. set_property(TARGET Libqrcodegencpp::Libqrcodegencpp PROPERTY IMPORTED_LOCATION "${Libqrcodegencpp_LIBRARY}")
  128. else()
  129. add_library(Libqrcodegencpp::Libqrcodegencpp INTERFACE IMPORTED)
  130. set_property(TARGET Libqrcodegencpp::Libqrcodegencpp PROPERTY IMPORTED_LIBNAME "${Libqrcodegencpp_LIBRARY}")
  131. endif()
  132. libqrcodegencpp_set_soname()
  133. set_target_properties(
  134. Libqrcodegencpp::Libqrcodegencpp
  135. PROPERTIES INTERFACE_COMPILE_OPTIONS "${PC_Libqrcodegencpp_CFLAGS_OTHER}"
  136. INTERFACE_INCLUDE_DIRECTORIES "${Libqrcodegencpp_INCLUDE_DIR}"
  137. VERSION ${Libqrcodegencpp_VERSION})
  138. endif()
  139. endif()
  140. include(FeatureSummary)
  141. set_package_properties(
  142. Libqrcodegencpp 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++.")