#这里需要区分Qt版本,因此要放到find_package(qt)之后 message(STATUS "***** Find qmqtt.cmake *****") # 0. 定义qmqtt版本 set(qmqtt_VERSION 1.0.3) # 1. 指定头文件路径 find_path(qmqtt_INCLUDE_DIR NAMES qmqtt.h PATHS ${CMAKE_CURRENT_LIST_DIR}/inc NO_DEFAULT_PATH ) #区分Qt版本 if(Qt5Core_FOUND) # message(STATUS "Qt Version : ${Qt5Core_VERSION}") if(${Qt5Core_VERSION} VERSION_LESS 5.15.0 AND ${Qt5Core_VERSION} VERSION_GREATER 5.12.0) set(QtVersion 5.12) elseif(${Qt5Core_VERSION} VERSION_GREATER_EQUAL 5.15.0) set(QtVersion 5.15) endif() elseif(Qt6Core_FOUND) message(STATUS "Qt Version : ${Qt6Core_VERSION}") message(STATUS "qmqtt not support Qt6") endif() # 2. 直接指定库文件,区分gcc,msvc,debug和release if(CMAKE_SYSTEM_NAME MATCHES "Windows") if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") if(QtVersion STREQUAL "5.12") if(CMAKE_BUILD_TYPE STREQUAL "Debug") set(qmqtt_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/lib/gcc/5.12.12/Qt5Qmqttd.dll) else() set(qmqtt_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/lib/gcc/5.12.12/Qt5Qmqtt.dll) endif() elseif(QtVersion STREQUAL "5.15") if(CMAKE_BUILD_TYPE STREQUAL "Debug") set(qmqtt_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/lib/gcc/5.15.2/debug/Qt5Qmqtt.dll) else() set(qmqtt_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/lib/gcc/5.15.2/release/Qt5Qmqtt.dll) endif() endif() elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") # message(STATUS "MSVC") if(QtVersion STREQUAL "5.12") if(CMAKE_BUILD_TYPE STREQUAL "Debug") set(qmqtt_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/lib/msvc/5.12.12/Qt5Qmqttd.lib) else() set(qmqtt_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/lib/msvc/5.12.12/Qt5Qmqtt.lib) endif(CMAKE_BUILD_TYPE STREQUAL "Debug") elseif(QtVersion STREQUAL "5.15") if(CMAKE_BUILD_TYPE STREQUAL "Debug") set(qmqtt_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/lib/msvc/5.15.2/Qt5Qmqttd.lib) else() set(qmqtt_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/lib/msvc/5.15.2/Qt5Qmqtt.lib) endif() endif() endif() #添加Linux库 elseif(CMAKE_SYSTEM_NAME MATCHES "Linux") # message(STATUS "Using ${CMAKE_SYSTEM_NAME} System") if(QtVersion STREQUAL "5.12") if(CMAKE_BUILD_TYPE STREQUAL "Debug") set(qmqtt_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/lib/linux_gcc8.3/5.12.12/debug/libQt5Qmqtt.so) else() set(qmqtt_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/lib/linux_gcc8.3/5.12.12/release/libQt5Qmqtt.so) endif() elseif(QtVersion STREQUAL "5.15") if(CMAKE_BUILD_TYPE STREQUAL "Debug") set(qmqtt_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/lib/linux_gcc8.3/5.15.14/debug/libQt5Qmqtt.so) else() set(qmqtt_LIBRARY ${CMAKE_CURRENT_LIST_DIR}/lib/linux_gcc8.3/5.15.14/debug/libQt5Qmqtt.so) endif() endif() endif() # 3. 设置查找到了变量 if(qmqtt_INCLUDE_DIR AND qmqtt_LIBRARY) set(qmqtt_FOUND TRUE) # message(STATUS "qmqtt Version : ${qmqtt_VERSION}") message(STATUS "include : qmqtt_INCLUDE_DIR") message(STATUS "Library : qmqtt_LIBRARY") else() set(qmqtt_FOUND FALSE) endif() message(STATUS "---------------------------------")