221 lines
6.1 KiB
CMake
221 lines
6.1 KiB
CMake
cmake_minimum_required(VERSION 3.15)
|
||
project(Viewer VERSION 1.0.0 LANGUAGES CXX C)
|
||
|
||
# 设置C++标准
|
||
set(CMAKE_CXX_STANDARD 17)
|
||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||
|
||
# Qt6特定配置
|
||
set(CMAKE_AUTOMOC ON)
|
||
set(CMAKE_AUTORCC ON)
|
||
set(CMAKE_AUTOUIC ON)
|
||
|
||
# 设置输出目录
|
||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
|
||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
|
||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_SOURCE_DIR}/bin)
|
||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_SOURCE_DIR}/bin)
|
||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_SOURCE_DIR}/bin)
|
||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_SOURCE_DIR}/bin)
|
||
|
||
# 添加include目录
|
||
include_directories(${CMAKE_SOURCE_DIR}/include)
|
||
include_directories(${CMAKE_SOURCE_DIR}/src)
|
||
|
||
# ==================== 查找依赖库 ====================
|
||
# 查找Qt6
|
||
find_package(Qt6 REQUIRED COMPONENTS
|
||
Core
|
||
Widgets
|
||
OpenGL
|
||
OpenGLWidgets
|
||
Network
|
||
Concurrent
|
||
)
|
||
|
||
# 查找PCL
|
||
find_package(PCL REQUIRED COMPONENTS common io visualization filters)
|
||
if(PCL_FOUND)
|
||
include_directories(${PCL_INCLUDE_DIRS})
|
||
link_directories(${PCL_LIBRARY_DIRS})
|
||
add_definitions(${PCL_DEFINITIONS})
|
||
message(STATUS "PCL found: ${PCL_VERSION}")
|
||
endif()
|
||
|
||
# 查找OpenCV
|
||
find_package(OpenCV REQUIRED COMPONENTS core highgui imgproc)
|
||
if(OpenCV_FOUND)
|
||
include_directories(${OpenCV_INCLUDE_DIRS})
|
||
message(STATUS "OpenCV found: ${OpenCV_VERSION}")
|
||
endif()
|
||
|
||
# 查找OpenCL
|
||
find_package(OpenCL REQUIRED)
|
||
if(OpenCL_FOUND)
|
||
include_directories(${OpenCL_INCLUDE_DIRS})
|
||
message(STATUS "OpenCL found")
|
||
endif()
|
||
|
||
# ==================== 源文件配置 ====================
|
||
set(GUI_SOURCES
|
||
src/main.cpp
|
||
src/gui/MainWindow.cpp
|
||
src/gui/PointCloudWidget.cpp
|
||
src/gui/PointCloudGLWidget.cpp
|
||
)
|
||
|
||
set(CONFIG_SOURCES
|
||
src/config/ConfigManager.cpp
|
||
)
|
||
set(CORE_SOURCES
|
||
src/core/NetworkManager.cpp
|
||
src/core/DeviceScanner.cpp
|
||
src/core/GVSPParser.cpp
|
||
src/core/Logger.cpp
|
||
src/core/PointCloudProcessor.cpp
|
||
)
|
||
set(HEADERS
|
||
src/gui/MainWindow.h
|
||
include/gui/PointCloudWidget.h
|
||
include/gui/PointCloudGLWidget.h
|
||
src/config/ConfigManager.h
|
||
src/core/NetworkManager.h
|
||
src/core/DeviceScanner.h
|
||
include/core/Logger.h
|
||
include/core/GVSPParser.h
|
||
include/core/PointCloudProcessor.h
|
||
)
|
||
|
||
# 资源文件
|
||
set(RESOURCES
|
||
resources/resources.qrc
|
||
resources/app_icon.rc
|
||
)
|
||
|
||
# 创建可执行文件
|
||
add_executable(${PROJECT_NAME} WIN32
|
||
${GUI_SOURCES}
|
||
${CONFIG_SOURCES}
|
||
${CORE_SOURCES}
|
||
${HEADERS}
|
||
${RESOURCES}
|
||
)
|
||
|
||
# ==================== 标定文件(cmos0)检查 ====================
|
||
set(VIEWER_CALIBRATION_DIR "${CMAKE_SOURCE_DIR}/cmos0")
|
||
set(VIEWER_REQUIRED_CALIB_FILES
|
||
"coe.txt"
|
||
"kc.txt"
|
||
"KK.txt"
|
||
)
|
||
|
||
set(VIEWER_MISSING_CALIB_FILES "")
|
||
foreach(_calib_file IN LISTS VIEWER_REQUIRED_CALIB_FILES)
|
||
if(NOT EXISTS "${VIEWER_CALIBRATION_DIR}/${_calib_file}")
|
||
list(APPEND VIEWER_MISSING_CALIB_FILES "${_calib_file}")
|
||
endif()
|
||
endforeach()
|
||
|
||
option(VIEWER_REQUIRE_CALIB_FILES "Fail configure when required cmos0 calibration files are missing" ON)
|
||
|
||
if(VIEWER_MISSING_CALIB_FILES)
|
||
if(VIEWER_REQUIRE_CALIB_FILES)
|
||
message(FATAL_ERROR
|
||
"Missing calibration file(s) in ${VIEWER_CALIBRATION_DIR}: ${VIEWER_MISSING_CALIB_FILES}\n"
|
||
"Please ensure cmos0 contains: ${VIEWER_REQUIRED_CALIB_FILES}"
|
||
)
|
||
else()
|
||
message(WARNING
|
||
"Missing calibration file(s) in ${VIEWER_CALIBRATION_DIR}: ${VIEWER_MISSING_CALIB_FILES}\n"
|
||
"Build continues, but runtime or MSI may be incomplete."
|
||
)
|
||
endif()
|
||
else()
|
||
message(STATUS "Calibration files found: ${VIEWER_REQUIRED_CALIB_FILES}")
|
||
endif()
|
||
|
||
# 复制标定文件到运行目录(bin/cmos0)
|
||
if(EXISTS "${VIEWER_CALIBRATION_DIR}" AND NOT VIEWER_MISSING_CALIB_FILES)
|
||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||
COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:${PROJECT_NAME}>/cmos0"
|
||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||
"${VIEWER_CALIBRATION_DIR}"
|
||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/cmos0"
|
||
COMMENT "Copy cmos0 calibration files to runtime directory"
|
||
)
|
||
else()
|
||
message(WARNING "Skip copying cmos0 because required calibration files are missing.")
|
||
endif()
|
||
|
||
# 链接库
|
||
target_link_libraries(${PROJECT_NAME}
|
||
Qt6::Core
|
||
Qt6::Widgets
|
||
Qt6::OpenGL
|
||
Qt6::OpenGLWidgets
|
||
Qt6::Network
|
||
Qt6::Concurrent
|
||
${PCL_LIBRARIES}
|
||
${OpenCV_LIBS}
|
||
${OpenCL_LIBRARIES}
|
||
ws2_32
|
||
)
|
||
|
||
# Windows特定配置
|
||
if(WIN32)
|
||
target_compile_definitions(${PROJECT_NAME} PRIVATE
|
||
_WINSOCK_DEPRECATED_NO_WARNINGS
|
||
_CRT_SECURE_NO_WARNINGS
|
||
)
|
||
endif()
|
||
|
||
# ==================== 安装配置 ====================
|
||
# 安装可执行文件到根目录
|
||
install(TARGETS ${PROJECT_NAME}
|
||
RUNTIME DESTINATION .
|
||
)
|
||
|
||
# 安装所有DLL到根目录
|
||
install(DIRECTORY ${CMAKE_SOURCE_DIR}/bin/
|
||
DESTINATION .
|
||
FILES_MATCHING PATTERN "*.dll"
|
||
)
|
||
|
||
# 安装Qt平台插件到platforms子目录
|
||
install(DIRECTORY ${CMAKE_SOURCE_DIR}/bin/platforms/
|
||
DESTINATION platforms
|
||
FILES_MATCHING PATTERN "*.dll"
|
||
)
|
||
|
||
# 安装标定文件目录(用于MSI)
|
||
if(EXISTS "${VIEWER_CALIBRATION_DIR}" AND NOT VIEWER_MISSING_CALIB_FILES)
|
||
install(DIRECTORY ${VIEWER_CALIBRATION_DIR}/
|
||
DESTINATION cmos0
|
||
FILES_MATCHING
|
||
PATTERN "*.txt"
|
||
)
|
||
endif()
|
||
|
||
# ==================== CPack配置 - MSI安装程序 ====================
|
||
set(CPACK_PACKAGE_NAME "Viewer")
|
||
set(CPACK_PACKAGE_VENDOR "Lorenzo Zhao")
|
||
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Depth Camera Control System")
|
||
set(CPACK_PACKAGE_VERSION "0.3.3")
|
||
set(CPACK_PACKAGE_VERSION_MAJOR "0")
|
||
set(CPACK_PACKAGE_VERSION_MINOR "3")
|
||
set(CPACK_PACKAGE_VERSION_PATCH "3")
|
||
set(CPACK_PACKAGE_INSTALL_DIRECTORY "Viewer")
|
||
|
||
# WiX生成器配置(用于MSI)
|
||
set(CPACK_GENERATOR "WIX")
|
||
set(CPACK_WIX_UPGRADE_GUID "42365CB0-5840-487F-A2C8-56F9699A9022")
|
||
set(CPACK_WIX_PROGRAM_MENU_FOLDER "Viewer")
|
||
set(CPACK_WIX_LICENSE_RTF "${CMAKE_SOURCE_DIR}/LICENSE.rtf")
|
||
|
||
# 创建开始菜单和桌面快捷方式
|
||
set(CPACK_PACKAGE_EXECUTABLES "Viewer" "Viewer")
|
||
set(CPACK_CREATE_DESKTOP_LINKS "Viewer")
|
||
|
||
# 包含CPack模块
|
||
include(CPack)
|