252 lines
7.7 KiB
CMake
252 lines
7.7 KiB
CMake
cmake_minimum_required(VERSION 3.10)
|
||
|
||
# 支持 MSVC
|
||
# 注意:配置 CMake 时请选择合适的生成器(例如 "Visual Studio 17 2022" 或 "Ninja")
|
||
|
||
project(image_capture LANGUAGES CXX)
|
||
|
||
# 检查是否使用 MSVC 风格的编译器
|
||
if(NOT (MSVC OR CMAKE_CXX_COMPILER_ID STREQUAL "MSVC"))
|
||
message(FATAL_ERROR "This project requires MSVC (Visual Studio) compiler. Please use Ninja with MSVC or Visual Studio generator.")
|
||
endif()
|
||
|
||
# ============================================================================
|
||
# 输出目录
|
||
# ============================================================================
|
||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||
|
||
# 生成 compile_commands.json 文件,供 IntelliSense 使用
|
||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||
|
||
# ============================================================================
|
||
# CMake 模块路径
|
||
# ============================================================================
|
||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||
include(CompilerOptions)
|
||
|
||
# ============================================================================
|
||
# 依赖项 (Qt6, OpenCV)
|
||
# ============================================================================
|
||
include(Dependencies)
|
||
|
||
# ============================================================================
|
||
# 相机 SDK 配置
|
||
# ============================================================================
|
||
include(PercipioSDK)
|
||
|
||
# ============================================================================
|
||
# 算法库
|
||
# ============================================================================
|
||
add_library(algorithm_lib STATIC
|
||
src/algorithm/core/detection_base.cpp
|
||
src/algorithm/core/detection_result.cpp
|
||
src/algorithm/utils/image_processor.cpp
|
||
|
||
src/algorithm/detections/slot_occupancy/slot_occupancy_detection.cpp
|
||
src/algorithm/detections/pallet_offset/pallet_offset_detection.cpp
|
||
src/algorithm/detections/beam_rack_deflection/beam_rack_deflection_detection.cpp
|
||
src/algorithm/detections/visual_inventory/visual_inventory_detection.cpp
|
||
|
||
)
|
||
|
||
target_link_libraries(algorithm_lib PUBLIC
|
||
${OpenCV_LIBS}
|
||
Open3D::Open3D
|
||
Qt6::Core
|
||
${HALCON_LIBRARIES}
|
||
)
|
||
|
||
target_include_directories(algorithm_lib PUBLIC
|
||
${HALCON_INCLUDE_DIRS}
|
||
${OpenCV_INCLUDE_DIRS}
|
||
src
|
||
${CMAKE_CURRENT_SOURCE_DIR}/third_party/percipio/common
|
||
)
|
||
|
||
target_link_directories(algorithm_lib PUBLIC ${OpenCV_LIB_DIRS})
|
||
|
||
# ============================================================================
|
||
# 主可执行文件
|
||
# ============================================================================
|
||
set(SOURCES
|
||
src/main.cpp
|
||
src/camera/ty_multi_camera_capture.cpp
|
||
src/camera/mvs_multi_camera_capture.cpp
|
||
src/device/device_manager.cpp
|
||
src/redis/redis_communicator.cpp
|
||
src/task/task_manager.cpp
|
||
src/vision/vision_controller.cpp
|
||
src/common/log_manager.cpp
|
||
src/common/config_manager.cpp
|
||
src/gui/mainwindow.cpp
|
||
src/gui/mainwindow.h
|
||
src/gui/mainwindow.ui
|
||
src/gui/settings_widget.cpp
|
||
src/gui/settings_widget.h
|
||
)
|
||
|
||
add_executable(${PROJECT_NAME} WIN32 ${SOURCES})
|
||
|
||
target_include_directories(${PROJECT_NAME} PRIVATE
|
||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||
${CMAKE_CURRENT_SOURCE_DIR}/third_party/mvs/Includes
|
||
${OpenCV_INCLUDE_DIRS}
|
||
${CMAKE_CURRENT_BINARY_DIR} # Qt AUTOUIC 生成的头文件
|
||
)
|
||
|
||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||
algorithm_lib
|
||
cpp_api_lib
|
||
tycam
|
||
${OpenCV_LIBS}
|
||
Qt6::Core
|
||
Qt6::Widgets
|
||
ws2_32
|
||
${CMAKE_CURRENT_SOURCE_DIR}/third_party/mvs/Libraries/win64/MvCameraControl.lib
|
||
)
|
||
|
||
target_link_directories(${PROJECT_NAME} PRIVATE
|
||
${OpenCV_LIB_DIRS}
|
||
${CMAKE_CURRENT_SOURCE_DIR}/third_party/percipio/lib/win/x64
|
||
)
|
||
|
||
if(Open3D_RUNTIME_DLLS)
|
||
foreach(DLL_FILE ${Open3D_RUNTIME_DLLS})
|
||
get_filename_component(DLL_NAME "${DLL_FILE}" NAME)
|
||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||
"${DLL_FILE}"
|
||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||
COMMENT "Copying runtime dependency: ${DLL_NAME}"
|
||
)
|
||
endforeach()
|
||
endif()
|
||
|
||
# Copy tycam.dll to executable directory
|
||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||
"${CAMPORT3_LIB_DIR}/tycam.dll"
|
||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||
COMMENT "Copying tycam.dll to executable directory"
|
||
)
|
||
|
||
# Copy Halcon DLLs
|
||
if(HALCON_ROOT)
|
||
set(HALCON_BIN_DIR "${HALCON_ROOT}/bin/x64-win64")
|
||
# Verify directory exists
|
||
if(EXISTS "${HALCON_BIN_DIR}")
|
||
set(HALCON_DLLS "halcon.dll" "halconcpp.dll")
|
||
foreach(DLL_NAME ${HALCON_DLLS})
|
||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||
"${HALCON_BIN_DIR}/${DLL_NAME}"
|
||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||
COMMENT "Copying Halcon DLL: ${DLL_NAME}"
|
||
)
|
||
endforeach()
|
||
else()
|
||
message(WARNING "Halcon bin directory not found at: ${HALCON_BIN_DIR}. DLLs will not be copied.")
|
||
endif()
|
||
endif()
|
||
|
||
|
||
|
||
|
||
# ============================================================================
|
||
# 工具链
|
||
# ============================================================================
|
||
add_executable(slot_algo_tuner WIN32
|
||
src/tools/slot_algo_tuner/main.cpp
|
||
src/tools/slot_algo_tuner/tuner_widget.cpp
|
||
src/tools/slot_algo_tuner/tuner_widget.h
|
||
)
|
||
|
||
target_include_directories(slot_algo_tuner PRIVATE
|
||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||
${OpenCV_INCLUDE_DIRS}
|
||
${CMAKE_CURRENT_BINARY_DIR}
|
||
)
|
||
|
||
target_link_libraries(slot_algo_tuner PRIVATE
|
||
${OpenCV_LIBS}
|
||
Qt6::Core
|
||
Qt6::Widgets
|
||
)
|
||
|
||
target_link_directories(slot_algo_tuner PRIVATE ${OpenCV_LIB_DIRS})
|
||
|
||
add_executable(calibration_tool WIN32
|
||
src/tools/calibration_tool/main.cpp
|
||
src/tools/calibration_tool/calibration_widget.cpp
|
||
src/tools/calibration_tool/calibration_widget.h
|
||
)
|
||
|
||
target_include_directories(calibration_tool PRIVATE
|
||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||
${OpenCV_INCLUDE_DIRS}
|
||
${CMAKE_CURRENT_BINARY_DIR}
|
||
${CMAKE_CURRENT_SOURCE_DIR}/third_party/percipio/include
|
||
${CMAKE_CURRENT_SOURCE_DIR}/third_party/mvs/Includes
|
||
)
|
||
|
||
target_link_libraries(calibration_tool PRIVATE
|
||
${OpenCV_LIBS}
|
||
Qt6::Core
|
||
Qt6::Widgets
|
||
Open3D::Open3D
|
||
tycam
|
||
)
|
||
|
||
target_compile_definitions(calibration_tool PRIVATE NOMINMAX)
|
||
|
||
target_link_directories(calibration_tool PRIVATE ${OpenCV_LIB_DIRS})
|
||
|
||
# Intrinsic Dumper Tool
|
||
add_executable(intrinsic_dumper
|
||
src/tools/intrinsic_dumper/main.cpp
|
||
)
|
||
|
||
target_include_directories(intrinsic_dumper PRIVATE
|
||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||
${OpenCV_INCLUDE_DIRS}
|
||
${CMAKE_CURRENT_BINARY_DIR}
|
||
${CMAKE_CURRENT_SOURCE_DIR}/third_party/percipio/include
|
||
)
|
||
|
||
target_link_libraries(intrinsic_dumper PRIVATE
|
||
Qt6::Core
|
||
tycam
|
||
)
|
||
|
||
# Reference Generator (Teach Tool)
|
||
add_executable(generate_reference
|
||
src/tools/generate_reference/main.cpp
|
||
src/device/device_manager.cpp
|
||
src/camera/ty_multi_camera_capture.cpp
|
||
src/camera/mvs_multi_camera_capture.cpp
|
||
src/common/log_manager.cpp
|
||
src/common/config_manager.cpp
|
||
)
|
||
|
||
target_include_directories(generate_reference PRIVATE
|
||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||
${OpenCV_INCLUDE_DIRS}
|
||
${CMAKE_CURRENT_BINARY_DIR}
|
||
${CMAKE_CURRENT_SOURCE_DIR}/third_party/percipio/include
|
||
${CMAKE_CURRENT_SOURCE_DIR}/third_party/mvs/Includes
|
||
)
|
||
|
||
target_link_libraries(generate_reference PRIVATE
|
||
algorithm_lib
|
||
cpp_api_lib
|
||
${OpenCV_LIBS}
|
||
Qt6::Core
|
||
Qt6::Widgets
|
||
tycam
|
||
${CMAKE_CURRENT_SOURCE_DIR}/third_party/mvs/Libraries/win64/MvCameraControl.lib
|
||
)
|
||
|
||
target_link_directories(generate_reference PRIVATE ${OpenCV_LIB_DIRS})
|