需要先构建WinDevice 在查找 lib

This commit is contained in:
DevWiki 2024-09-27 15:32:00 +08:00
parent b01ab5a972
commit fde177894a

View File

@ -12,6 +12,38 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
# UTF-8 # UTF-8
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/source-charset:utf-8>") add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/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 NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
@ -47,47 +79,24 @@ else()
endif() endif()
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 # 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}) include_directories(${WinDevice_INCLUDE_DIR} ${WinDevice_THIRD_INCLUDE_DIR})
# 使 find_library # 使 find_library
find_library(WinDevice_LIB NAMES WinDevice HINTS ${WinDevice_LIB_DIR}) find_library(WinDevice_LIB NAMES WinDevice HINTS ${WinDevice_LIB_DIR})
# Release WinDevice # WinDevice DeviceManager
target_link_libraries(DeviceManager PRIVATE ${WinDevice_LIB}) 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 set_target_properties(DeviceManager PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com