diff --git a/DeviceManager/CMakeLists.txt b/DeviceManager/CMakeLists.txt index b7dce12..60992c6 100644 --- a/DeviceManager/CMakeLists.txt +++ b/DeviceManager/CMakeLists.txt @@ -12,6 +12,38 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # 设置源代码文件编码为UTF-8 add_compile_options("$<$:/source-charset:utf-8>") + +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(ARCH_DIR "x64") +else() + set(ARCH_DIR "x86") +endif() + +set(WinDevice_OUTPUT "../WinDevice/output") +message("WinDevice_OUTPUT: ${WinDevice_OUTPUT}") +# 获取架构信息 + +set(WinDevice_INCLUDE_DIR "${WinDevice_OUTPUT}/include/") +message("WinDevice_INCLUDE_DIR: ${WinDevice_INCLUDE_DIR}") +set(WinDevice_THIRD_INCLUDE_DIR "${WinDevice_OUTPUT}/third_lib/") +message("WinDevice_THIRD_INCLUDE_DIR: ${WinDevice_THIRD_INCLUDE_DIR}") +if (CMAKE_BUILD_TYPE STREQUAL "Debug") + set(WinDevice_LIB_DIR "${WinDevice_OUTPUT}/${ARCH_DIR}/debug/") +else() + set(WinDevice_LIB_DIR "${WinDevice_OUTPUT}/${ARCH_DIR}/release/") +endif() +message("WinDevice_LIB_DIR: ${WinDevice_LIB_DIR}") + +message("build WinDecie in: ${CMAKE_BUILD_TYPE} mode") + + +add_custom_target(BuildWinDevice ALL + COMMAND ${CMAKE_COMMAND} -E echo "Starting to build WinDevice project..." + COMMAND ${CMAKE_COMMAND} -S ../WinDevice -B ../WinDevice/build -G "Visual Studio 17 2022" -A ${ARCH_DIR} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + COMMAND ${CMAKE_COMMAND} --build ../WinDevice/build --config ${CMAKE_BUILD_TYPE} + COMMENT "Building WinDevice project in ${CMAKE_BUILD_TYPE} mode" +) + find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) @@ -47,47 +79,24 @@ else() endif() endif() -target_link_libraries(DeviceManager PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) - - -if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(ARCH_DIR "x64") -else() - set(ARCH_DIR "x86") -endif() - -set(WinDevice_OUTPUT "../WinDevice/output") -message("WinDevice_OUTPUT: ${WinDevice_OUTPUT}") -# 获取架构信息 -set(WinDevice_INCLUDE_DIR "${WinDevice_OUTPUT}/include/") -message("WinDevice_INCLUDE_DIR: ${WinDevice_INCLUDE_DIR}") -set(WinDevice_THIRD_INCLUDE_DIR "${WinDevice_OUTPUT}/third_lib/") -message("WinDevice_THIRD_INCLUDE_DIR: ${WinDevice_THIRD_INCLUDE_DIR}") -if (CMAKE_BUILD_TYPE STREQUAL "Debug") - set(WinDevice_LIB_DIR "${WinDevice_OUTPUT}/${ARCH_DIR}/debug/") -else() - set(WinDevice_LIB_DIR "${WinDevice_OUTPUT}/${ARCH_DIR}/release/") -endif() -message("WinDevice_LIB_DIR: ${WinDevice_LIB_DIR}") - -message("build WinDecie in: ${CMAKE_BUILD_TYPE} mode") - - -add_custom_target(BuildWinDevice ALL - COMMAND ${CMAKE_COMMAND} -E echo "Starting to build WinDevice project..." - COMMAND ${CMAKE_COMMAND} -S ../WinDevice -B ../WinDevice/build -G "Visual Studio 17 2022" -A ${ARCH_DIR} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} - COMMAND ${CMAKE_COMMAND} --build ../WinDevice/build --config ${CMAKE_BUILD_TYPE} - COMMENT "Building WinDevice project in ${CMAKE_BUILD_TYPE} mode" -) # 将 DeviceManager 目标的构建依赖于 BuildWinDevice 自定义目标 -add_dependencies(DeviceManager BuildWinDevice) +# add_dependencies(DeviceManager BuildWinDevice) - # 添加头文件目录 +message("include_directories ${WinDevice_INCLUDE_DIR} ${WinDevice_THIRD_INCLUDE_DIR}") + +# 添加头文件目录 include_directories(${WinDevice_INCLUDE_DIR} ${WinDevice_THIRD_INCLUDE_DIR}) # 使用 find_library 查找动态库文件 find_library(WinDevice_LIB NAMES WinDevice HINTS ${WinDevice_LIB_DIR}) -# Release 模式下,链接 WinDevice 生成的库文件 -target_link_libraries(DeviceManager PRIVATE ${WinDevice_LIB}) +# 如果找到 WinDevice 库,才链接到 DeviceManager +if(WinDevice_LIB) + message(STATUS "Found WinDevice library: ${WinDevice_LIB}") + target_link_libraries(DeviceManager PRIVATE ${WinDevice_LIB}) +else() + message(WARNING "WinDevice library not found in ${WinDevice_LIB_DIR}") +endif() + +target_link_libraries(DeviceManager PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) set_target_properties(DeviceManager PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com