-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists_for_macos.txt
56 lines (44 loc) · 1.49 KB
/
CMakeLists_for_macos.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# macOS
cmake_minimum_required(VERSION 3.10)
project(QRScanner VERSION 1.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# 允许用户指定自定义的OpenCV路径
if(NOT DEFINED OpenCV_DIR)
set(OpenCV_DIR "/opt/homebrew/Cellar/opencv/4.10.0_3/lib/cmake/opencv4" CACHE PATH "Path to OpenCVConfig.cmake")
endif()
# 查找OpenCV
find_package(OpenCV REQUIRED)
if(NOT OpenCV_FOUND)
message(FATAL_ERROR "OpenCV not found. Please install OpenCV or set OpenCV_DIR.")
endif()
# 查找ZBar
find_package(PkgConfig REQUIRED)
pkg_check_modules(ZBAR REQUIRED IMPORTED_TARGET zbar)
if(NOT ZBAR_FOUND)
message(FATAL_ERROR "ZBar not found. Please install ZBar.")
endif()
# 设置包含目录
include_directories(${OpenCV_INCLUDE_DIRS} ${ZBAR_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/include)
# 添加可执行文件
add_executable(${PROJECT_NAME} src/main.cpp src/QRScanner.cpp)
# 链接库
target_link_libraries(${PROJECT_NAME} PRIVATE ${OpenCV_LIBS} PkgConfig::ZBAR)
# 设置输出目录
set_target_properties(${PROJECT_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
# 添加安装规则
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION bin
)
# 打印一些信息
include(CMakePrintHelpers)
cmake_print_variables(CMAKE_CXX_STANDARD)
cmake_print_properties(
TARGETS ${PROJECT_NAME}
PROPERTIES RUNTIME_OUTPUT_DIRECTORY
)
cmake_print_variables(OpenCV_VERSION OpenCV_LIBS)
cmake_print_variables(ZBAR_VERSION ZBAR_LIBRARIES)