From 0b3e9b1b386aa44700c31d86ab43ce6613247acd Mon Sep 17 00:00:00 2001 From: wyc <1104749580@qq.com> Date: Mon, 3 Aug 2026 10:56:46 +0800 Subject: [PATCH] =?UTF-8?q?qt5=E6=9F=A5=E6=89=BE=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 0_cmake_library/main.cmake | 1 + cmake_moudle/FindQt5.cmake | 98 ++++++++++++++++++++++++++++++++++++++ start.cmake | 1 + 3 files changed, 100 insertions(+) create mode 100644 cmake_moudle/FindQt5.cmake diff --git a/0_cmake_library/main.cmake b/0_cmake_library/main.cmake index c71611c..aae65ab 100644 --- a/0_cmake_library/main.cmake +++ b/0_cmake_library/main.cmake @@ -101,6 +101,7 @@ endfunction() macro(_load_cmake_library) project(Radio LANGUAGES C CXX) _initialize_cxx_default_options() + list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_moudle") # set(CMAKE_C_LINKER_LAUNCHER "D:/ae/proj/ae/0_cmake_library/set_utf8.bat") # set(CMAKE_CXX_LINKER_LAUNCHER "D:/ae/proj/ae/0_cmake_library/set_utf8.bat") # 清除默认环境 diff --git a/cmake_moudle/FindQt5.cmake b/cmake_moudle/FindQt5.cmake new file mode 100644 index 0000000..28cf116 --- /dev/null +++ b/cmake_moudle/FindQt5.cmake @@ -0,0 +1,98 @@ +set(Qt5_ROOT "" CACHE PATH "Qt5 install prefix") +set(_qt5_components ${Qt5_FIND_COMPONENTS}) +set(_qt5_prefix_candidates) +foreach (_qt5_prefix IN ITEMS + "${Qt5_ROOT}" + "$ENV{Qt5_ROOT}" + "$ENV{QTDIR}" + "${CMAKE_CURRENT_LIST_DIR}/../../Qt/Qt5.14.2/5.14.2/msvc2017_64" + "C:/Qt/Qt5.14.2/5.14.2/msvc2017_64" + "D:/Qt/Qt5.14.2/5.14.2/msvc2017_64" + "C:/Qt/5.14.2/msvc2017_64" + "D:/Qt/5.14.2/msvc2017_64" +) + if (NOT "${_qt5_prefix}" STREQUAL "") + list(APPEND _qt5_prefix_candidates "${_qt5_prefix}") + endif () +endforeach () +if (Qt5_DIR AND NOT EXISTS "${Qt5_DIR}/Qt5Config.cmake") + message(STATUS "Qt5_DIR ignored: ${Qt5_DIR}") + unset(Qt5_DIR CACHE) + unset(Qt5_DIR) +endif () +if (NOT Qt5_DIR) + unset(_qt5_config_dir CACHE) + find_path(_qt5_config_dir + NAMES Qt5Config.cmake + PATHS ${_qt5_prefix_candidates} + PATH_SUFFIXES lib/cmake/Qt5 lib64/cmake/Qt5 cmake/Qt5 + NO_DEFAULT_PATH + ) + if (NOT _qt5_config_dir) + find_path(_qt5_config_dir + NAMES Qt5Config.cmake + PATH_SUFFIXES lib/cmake/Qt5 lib64/cmake/Qt5 cmake/Qt5 + ) + endif () + if (_qt5_config_dir) + set(Qt5_DIR "${_qt5_config_dir}" CACHE PATH "Qt5 cmake config dir" FORCE) + endif () +endif () +if (Qt5_DIR) + get_filename_component(Qt5_BaseDIR "${Qt5_DIR}/../../.." ABSOLUTE) + set(Qt5_BaseDIR "${Qt5_BaseDIR}" CACHE PATH "Qt5 base dir" FORCE) + set(Qt5_Plugin_DIR "${Qt5_BaseDIR}/plugins" CACHE PATH "Qt5 plugin dir" FORCE) +endif () +find_package(Qt5 CONFIG QUIET COMPONENTS ${_qt5_components}) +function(_qt5_print_target_property target property) + if (NOT TARGET ${target}) + return() + endif () + get_target_property(_qt5_value ${target} ${property}) + if (_qt5_value) + message(STATUS "${target} ${property}=${_qt5_value}") + endif () +endfunction() +function(_qt5_print_status) + message(STATUS "Qt5_FOUND=${Qt5_FOUND}") + message(STATUS "Qt5_VERSION=${Qt5_VERSION}") + message(STATUS "Qt5_DIR=${Qt5_DIR}") + message(STATUS "Qt5_BaseDIR=${Qt5_BaseDIR}") + message(STATUS "Qt5_Plugin_DIR=${Qt5_Plugin_DIR}") + message(STATUS "Qt5 requested components=${_qt5_components}") + foreach (_qt5_component ${_qt5_components}) + message(STATUS "Qt5${_qt5_component}_FOUND=${Qt5${_qt5_component}_FOUND}") + if (TARGET Qt5::${_qt5_component}) + message(STATUS "Qt5 target found: Qt5::${_qt5_component}") + _qt5_print_target_property(Qt5::${_qt5_component} IMPORTED_LOCATION_DEBUG) + _qt5_print_target_property(Qt5::${_qt5_component} IMPORTED_LOCATION_RELEASE) + _qt5_print_target_property(Qt5::${_qt5_component} IMPORTED_IMPLIB_DEBUG) + _qt5_print_target_property(Qt5::${_qt5_component} IMPORTED_IMPLIB_RELEASE) + _qt5_print_target_property(Qt5::${_qt5_component} INTERFACE_INCLUDE_DIRECTORIES) + else () + message(STATUS "Qt5 target missing: Qt5::${_qt5_component}") + endif () + endforeach () +endfunction() +function(_qt5_fail message_text) + if (Qt5_FIND_REQUIRED) + message(FATAL_ERROR "${message_text}") + else () + message(STATUS "${message_text}") + endif () +endfunction() +#_qt5_print_status() +if (NOT Qt5_FOUND) + set(_qt5_missing_components) + foreach (_qt5_component ${_qt5_components}) + if (NOT Qt5${_qt5_component}_FOUND) + list(APPEND _qt5_missing_components ${_qt5_component}) + endif () + endforeach () + if (_qt5_missing_components) + _qt5_fail("Could NOT find Qt5 components: ${_qt5_missing_components}, Qt5_DIR=${Qt5_DIR}") + return() + endif () + _qt5_fail("Could NOT find Qt5, Qt5_DIR=${Qt5_DIR}") + return() +endif () \ No newline at end of file diff --git a/start.cmake b/start.cmake index 3d93363..2cfa723 100644 --- a/start.cmake +++ b/start.cmake @@ -25,3 +25,4 @@ include(${dqi}/Cppcheck/export.cmake) # 静态代码分析工具:检测 C include(${dqi}/lizard/export.cmake) # 代码复杂度分析工具:统计圈复杂度、函数规模等指标 include(${dqi}/cloc_tokei/export.cmake) # 代码统计工具:统计代码行数、语言组成等信息 include(${dqi}/CodeMetrics/export.cmake) # 软件度量工具:分析代码质量指标 +