-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCmakeLists.txt
More file actions
139 lines (113 loc) · 4.24 KB
/
Copy pathCmakeLists.txt
File metadata and controls
139 lines (113 loc) · 4.24 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# 最低指定的CMake版本
cmake_minimum_required(VERSION 3.5)
# 括号里面填你的工程名
PROJECT(OpenGLSamples)
set(CMAKE_CXX_STANDARD 17)
add_compile_options(-Wno-nonportable-include-path)
# 设置输出路径
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# 三方库路径
set(third-party-path ${CMAKE_CURRENT_SOURCE_DIR}/third-party)
# Data路径
set(data-path ${CMAKE_CURRENT_SOURCE_DIR}/data)
set(DATA_PATH ${data-path}/)
# 添加三方库
set(Freetype_DIR ${third-party-path}/deploy/freetype/lib/cmake/freetype)
find_package(Freetype CONFIG REQUIRED)
if(NOT Freetype_FOUND)
message(FATAL_ERROR "freetype library not found in: " ${Freetype_DIR})
endif()
set(glm_DIR ${third-party-path}/deploy/glm/lib/cmake/glm)
find_package(glm CONFIG REQUIRED)
if(NOT glm_FOUND)
message(FATAL_ERROR "glm library not found in: " ${glm_DIR})
endif()
set(glfw3_DIR ${third-party-path}/deploy/glfw/lib/cmake/glfw3)
find_package(glfw3 CONFIG REQUIRED)
if(NOT glfw3_FOUND)
message(FATAL_ERROR "glfw library not found in: " ${glfw3_DIR})
endif()
set(OpenCV_DIR ${third-party-path}/deploy/opencv-4.0/lib/cmake/opencv4)
find_package(OpenCV CONFIG REQUIRED COMPONENTS opencv_core opencv_video opencv_videoio opencv_highgui)
if(NOT OpenCV_FOUND)
message(FATAL_ERROR "OpenCV library not found in: " ${OpenCV_DIR})
endif()
set(assimp_DIR ${third-party-path}/deploy/assimp/lib/cmake/assimp-5.0)
# assimp export checks ${_IMPORT_PREFIX}/lib/... without defining _IMPORT_PREFIX.
set(_IMPORT_PREFIX "${third-party-path}/deploy/assimp")
find_package(assimp CONFIG REQUIRED)
unset(_IMPORT_PREFIX)
if(NOT assimp_FOUND)
message(FATAL_ERROR "assimp library not found in: " ${assimp_DIR})
endif()
set(nlohmann_json_DIR ${third-party-path}/deploy/json/lib/cmake/nlohmann_json)
find_package(nlohmann_json CONFIG REQUIRED)
if(NOT nlohmann_json_FOUND)
message(FATAL_ERROR "nlohmann_json library not found in: " ${nlohmann_json_DIR})
endif()
set(soil2_DIR ${third-party-path}/deploy/soil/share/soil2)
find_package(soil2 CONFIG REQUIRED)
if(NOT soil2_FOUND)
message(FATAL_ERROR "soil2 library not found in: " ${soil2_DIR})
endif()
# 添加头文件
list(APPEND INCLUDES_DIR ${third-party-path}/glad/include)
list(APPEND INCLUDES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/samples/common)
# 添加源文件
set(glad-c ${CMAKE_CURRENT_SOURCE_DIR}/third-party/glad/src/glad.c)
set(stbimage-c ${CMAKE_CURRENT_SOURCE_DIR}/samples/common/stb_image.cpp)
file(GLOB_RECURSE SRC_TEST_CPP_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/samples/*Test.cpp)
# 匹配...Test.cpp所在文件夹下所有文件
foreach(TEST_CPP_DIR ${SRC_TEST_CPP_DIRS})
string(REGEX REPLACE ".*/\(.*\)" "\\1" SUFFIX ${TEST_CPP_DIR})
string(REGEX REPLACE "/${SUFFIX}" "" SRC_DIR ${TEST_CPP_DIR})
list(APPEND SRC_DIRS ${SRC_DIR})
endforeach()
# 配置文件
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/samples/common/Config.h.in"
"${CMAKE_CURRENT_SOURCE_DIR}/samples/common/Config.h"
)
# imgui
list(APPEND INCLUDES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/samples/common/imgui)
list(APPEND INCLUDES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/samples/common/imgui/backends)
list(APPEND INCLUDES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/samples/common/stb_image_write.h)
list(APPEND INCLUDES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/samples/common/stb_image_resize.h)
file(GLOB IMGUI_SRC
${CMAKE_CURRENT_SOURCE_DIR}/samples/common/imgui/*.h
${CMAKE_CURRENT_SOURCE_DIR}/samples/common/imgui/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/samples/common/imgui/backends/imgui_impl_opengl3.cpp
${CMAKE_CURRENT_SOURCE_DIR}/samples/common/imgui/backends/imgui_impl_glfw.cpp
)
# 遍历源代码文件,构建工程
foreach(SRC_DIR ${SRC_DIRS})
file(GLOB_RECURSE SRC_CPP ${SRC_DIR}/*.cpp ${SRC_DIR}/*.c)
file(GLOB_RECURSE SRC_H ${SRC_DIR}/*.h ${SRC_DIR}/*.hpp)
string(REGEX REPLACE ".*/\(.*\)" "\\1" SRC ${SRC_DIR})
string(REGEX REPLACE "/${SRC}" "" PRO_DIR ${SRC_DIR})
string(REGEX REPLACE ".*/\(.*\)" "\\1" PRO_NAME ${PRO_DIR})
add_executable(${PRO_NAME}
${SRC_CPP}
${SRC_H}
${glad-c}
${stbimage-c}
${IMGUI_SRC}
)
target_include_directories(${PRO_NAME}
PUBLIC
${INCLUDES_DIR}
)
target_link_libraries(${PRO_NAME}
PRIVATE
assimp::assimp
nlohmann_json::nlohmann_json
Freetype::Freetype
soil2::soil2
glfw
glm
opencv_core
opencv_video
opencv_videoio
opencv_highgui
)
endforeach()