FindQwt.cmake 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. # FindQwt
  2. # --------
  3. #
  4. # Find the Qwt libraries(Only for Qwt provided by GJDM)
  5. #
  6. # Result Variables
  7. # ^^^^^^^^^^^^^^^^
  8. #
  9. # The following variables will be defined:
  10. #
  11. # ``Qwt_FOUND`` True if Qwt found on the local system
  12. #
  13. # ``Qwt_VERSION`` Qwt Version(x.x.x)
  14. #
  15. # ``Qwt_VERSION_MAJOR`` Qwt Major Version
  16. #
  17. # ``Qwt_VERSION_MINOR`` Qwt Minor Version
  18. #
  19. # ``Qwt_VERSION_PATCH`` Qwt Patch Version
  20. #
  21. # ``QwtPolar_VERSION`` QwtPolar Version(x.x.x)
  22. #
  23. # ``QwtPolar_VERSION_MAJOR`` QwtPolar Major Version
  24. #
  25. # ``QwtPolar_VERSION_MINOR`` QwtPolar Minor Version
  26. #
  27. # ``QwtPolar_VERSION_PATCH`` QwtPolar Patch Version
  28. #
  29. # ``Qwt_DIRS`` Location of Qwt(root dir)
  30. #
  31. # ``Qwt_INCLUDE_DIRS`` Location of Qwt(QwtPolar) header files
  32. #
  33. # ``Qwt_LIBRARY_DIRS`` Location of Qwt(QwtPolar) libraries
  34. #
  35. # ``Qwt_LIBRARIES`` List of the Qwt libraries(with QwtPolar libraries) found
  36. #
  37. # ``Qwt_BINARY_DIRS`` Location of VTK binary
  38. #
  39. # 防止重复引入
  40. if(GJDM_Qwt_ALREADY_INCLUDED)
  41. return()
  42. endif()
  43. set(GJDM_Qwt_ALREADY_INCLUDED 1)
  44. # find_path 搜索包含某个文件的路径
  45. # 如果在某个路径下发现了该文件,该结果会被存储到该变量中;如果没有找到,存储的结果将会是<VAR>-NOTFOUND
  46. find_path(Qwt_DIRS
  47. NAMES
  48. include/qwt.h
  49. PATHS
  50. ${CMAKE_SOURCE_DIR}/extlib/Qwt
  51. NO_SYSTEM_ENVIRONMENT_PATH
  52. NO_CMAKE_SYSTEM_PATH
  53. )
  54. set(Qwt_VERSION_MAJOR 6)
  55. set(Qwt_VERSION_MINOR 1)
  56. set(Qwt_VERSION_PATCH 6)
  57. set(QwtPolar_VERSION_MAJOR 1)
  58. set(QwtPolar_VERSION_MINOR 1)
  59. set(QwtPolar_VERSION_PATCH 1)
  60. set(Qwt_VERSION "${Qwt_VERSION_MAJOR}.${Qwt_VERSION_MINOR}.${Qwt_VERSION_PATCH}")
  61. set(QwtPolar_VERSION "${QwtPolar_VERSION_MAJOR}.${QwtPolar_VERSION_MINOR}.${QwtPolar_VERSION_PATCH}")
  62. find_path(Qwt_INCLUDE_DIRS
  63. NAMES
  64. qwt.h
  65. HINTS
  66. ${Qwt_DIRS}/include
  67. )
  68. find_path(Qwt_LIBRARY_DIRS
  69. NAMES
  70. qwt.lib libqwt.so
  71. HINTS
  72. ${Qwt_DIRS}/lib
  73. )
  74. find_path(Qwt_BINARY_DIRS
  75. NAMES
  76. qwt.dll libqwt.so
  77. HINTS
  78. ${Qwt_DIRS}/lib
  79. )
  80. set(Qwt_LIBRARIES GJDM::QWT;GJDM::QWTPOLAR)
  81. add_library(GJDM::QWT SHARED IMPORTED)
  82. add_library(GJDM::QWTPOLAR SHARED IMPORTED)
  83. set_property(TARGET GJDM::QWT PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${Qwt_INCLUDE_DIRS})
  84. set_property(TARGET GJDM::QWT APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
  85. set_property(TARGET GJDM::QWT PROPERTY INTERFACE_LINK_LIBRARIES Qt5::Svg Qt5::OpenGL)
  86. set_property(TARGET GJDM::QWT PROPERTY INTERFACE_COMPILE_DEFINITIONS "QWT_DLL")
  87. set_property(TARGET GJDM::QWTPOLAR PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${Qwt_INCLUDE_DIRS})
  88. set_property(TARGET GJDM::QWTPOLAR APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
  89. set_property(TARGET GJDM::QWTPOLAR PROPERTY INTERFACE_LINK_LIBRARIES GJDM::QWT Qt5::PrintSupport)
  90. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  91. set_target_properties(GJDM::QWT PROPERTIES
  92. IMPORTED_LOCATION_RELEASE "${Qwt_LIBRARY_DIRS}/libqwt.so.${Qwt_VERSION_MAJOR}.${Qwt_VERSION_MINOR}.${Qwt_VERSION_PATCH}"
  93. IMPORTED_SONAME_RELEASE "libqwt.so.${Qwt_VERSION_MAJOR}"
  94. )
  95. set_target_properties(GJDM::QWTPOLAR PROPERTIES
  96. IMPORTED_LOCATION_RELEASE "${Qwt_LIBRARY_DIRS}/libqwtpolar.so.${QwtPolar_VERSION_MAJOR}.${QwtPolar_VERSION_MINOR}.${QwtPolar_VERSION_PATCH}"
  97. IMPORTED_SONAME_RELEASE "libqwtpolar.so.${QwtPolar_VERSION_MAJOR}"
  98. )
  99. elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
  100. set_property(TARGET GJDM::QWT APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
  101. set_property(TARGET GJDM::QWTPOLAR APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
  102. set_target_properties(GJDM::QWT PROPERTIES
  103. IMPORTED_IMPLIB_RELEASE "${Qwt_LIBRARY_DIRS}/qwt.lib"
  104. IMPORTED_LOCATION_RELEASE "${Qwt_BINARY_DIRS}/qwt.dll"
  105. IMPORTED_IMPLIB_DEBUG "${Qwt_LIBRARY_DIRS}/qwtd.lib"
  106. IMPORTED_LOCATION_DEBUG "${Qwt_BINARY_DIRS}/qwtd.dll"
  107. )
  108. set_target_properties(GJDM::QWTPOLAR PROPERTIES
  109. IMPORTED_IMPLIB_RELEASE "${Qwt_LIBRARY_DIRS}/qwtpolar.lib"
  110. IMPORTED_LOCATION_RELEASE "${Qwt_BINARY_DIRS}/qwtpolar.dll"
  111. IMPORTED_IMPLIB_DEBUG "${Qwt_LIBRARY_DIRS}/qwtpolard.lib"
  112. IMPORTED_LOCATION_DEBUG "${Qwt_BINARY_DIRS}/qwtpolard.dll"
  113. )
  114. endif()
  115. include(FindPackageHandleStandardArgs)
  116. # 如果找到所有需要的变量,并且版本匹配,则将Qwt_FOUND变量设置为TRUE
  117. find_package_handle_standard_args(Qwt
  118. FOUND_VAR
  119. Qwt_FOUND
  120. REQUIRED_VARS
  121. Qwt_DIRS
  122. Qwt_INCLUDE_DIRS
  123. Qwt_LIBRARY_DIRS
  124. Qwt_LIBRARIES
  125. Qwt_BINARY_DIRS
  126. VERSION_VAR
  127. Qwt_VERSION
  128. )