-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
53 lines (45 loc) · 1.64 KB
/
CMakeLists.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
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
PROJECT(SJTU-RM-CV-ML)
SET(CMAKE_CXX_STANDARD 17)
ADD_COMPILE_OPTIONS("-O3")
ADD_DEFINITIONS("-DPROJECT_DIR=\"${PROJECT_SOURCE_DIR}\"")
ADD_DEFINITIONS("-D${CMAKE_SYSTEM_NAME}")
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
SET(BIN_NAME "run")
# 尝试使用ccache加速编译
FIND_PROGRAM(CCACHE_FOUND ccache)
IF(CCACHE_FOUND)
SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
SET_PROPERTY(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
MESSAGE("< Use ccache for compiler >")
ENDIF()
# 寻找必要依赖库
FIND_PACKAGE(OpenCV 4 REQUIRED)
FIND_PACKAGE(Boost COMPONENTS timer REQUIRED)
FIND_PACKAGE(Threads)
# 设置头文件目录
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/utils)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/algorithm)
# 寻找必要源文件
FILE(GLOB_RECURSE sourcefiles "utils/*.cpp" "main/*.cpp")
# 添加算法子目录
ADD_SUBDIRECTORY(algorithm)
ADD_DEFINITIONS(${ALGORITHM_DEFINES})
MESSAGE(${ALGORITHM_DEFINES})
MESSAGE(${ALGORITHM_LIBS})
# 根据编译方式不同生成不同名称的可执行文件
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
SET(BIN_NAME "${BIN_NAME}-debug")
else()
SET(CMAKE_BUILD_TYPE "Release")
ADD_DEFINITIONS("-DFIXED_OPTIONS")
SET(BIN_NAME "${BIN_NAME}-release")
endif()
# 添加可执行文件以及链接
ADD_EXECUTABLE("${BIN_NAME}" ${sourcefiles})
TARGET_LINK_LIBRARIES(${BIN_NAME} MVSDK)
TARGET_LINK_LIBRARIES(${BIN_NAME} ${OpenCV_LIBS})
TARGET_LINK_LIBRARIES(${BIN_NAME} ${Boost_LIBRARIES})
TARGET_LINK_LIBRARIES(${BIN_NAME} ${ALGORITHM_LIBS})