CMakeLists详细指令学习笔记链接:
配置和生成项目时,CMake将尝试查找和链接ZeroMQ和OpenCV库。如果找到,它将输出相关信息并配置项目以使用这两个库。如果未找到任一库,它将产生致命错误消息并停止配置过程。
cmake_minimum_required(VERSION 3.0)
project(YourProjectName)
# 查找 ZeroMQ 库
find_package(ZMQ REQUIRED)
# 查找 OpenCV 库
find_package(OpenCV REQUIRED)
if(ZMQ_FOUND AND OpenCV_FOUND)
message(STATUS "ZeroMQ found (version ${ZMQ_VERSION}).")
message(STATUS "OpenCV found (version ${OpenCV_VERSION}).")
# 包含 ZeroMQ 头文件和 OpenCV 头文件
include_directories(
${ZMQ_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
)
# 添加可执行文件,并链接 ZeroMQ 和 OpenCV 库
add_executable(your_executable_name your_source_files.cpp)
target_link_libraries(your_executable_name ${ZMQ_LIBRARIES} ${OpenCV_LIBS})
else()
if(NOT ZMQ_FOUND)
message(FATAL_ERROR "ZeroMQ not found. Please install ZeroMQ and try again.")
endif()
if(NOT OpenCV_FOUND)
message(FATAL_ERROR "OpenCV not found. Please install OpenCV and try again.")
endif()
endif()