-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
105 lines (88 loc) · 4.24 KB
/
CMakeLists.txt
File metadata and controls
105 lines (88 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
cmake_minimum_required(VERSION 3.23.2)
cmake_policy(VERSION 3.0)
project(ComputerGraphics)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
message("Now System is Mac")
# 检查环境变量
if (NOT DEFINED ENV{GLFW_HOME})
message(FATAL_ERROR "found no env named GLFW_HOME")
endif()
if (NOT DEFINED ENV{GLAD_HOME})
message(FATAL_ERROR "found no env named GLAD_HOME")
endif()
# 暂存环境变量
set(GLFW_HOME $ENV{GLFW_HOME})
set(GLAD_HOME $ENV{GLAD_HOME})
set(ASSIMP_HOME $ENV{ASSIMP_HOME})
# 设置头文件目录
include_directories("${GLFW_HOME}/include")
include_directories("${GLAD_HOME}/include")
include_directories("${PROJECT_SOURCE_DIR}/include ")
include_directories("${ASSIMP_HOME}/include")
# 添加 GLFW3 预编译库
add_library(glfw SHARED IMPORTED)
SET_TARGET_PROPERTIES(glfw PROPERTIES IMPORTED_LOCATION "${GLFW_HOME}/lib/libglfw.dylib")
# 链接 GLFW3 预编译库
link_libraries(glfw)
# 寻找assimp
add_library(assimp SHARED IMPORTED)
SET_TARGET_PROPERTIES(assimp PROPERTIES IMPORTED_LOCATION "${ASSIMP_HOME}/lib/libassimp.5.2.4.dylib")
# 链接assimp库
link_libraries(assimp)
add_executable(main main.cpp src/glad.c include/InitShader.cpp include/Camera.cpp include/TriMesh.cpp)
add_executable(demo demo.cpp src/glad.c include/InitShader.cpp include/Camera.cpp include/TriMesh.cpp)
file(GLOB_RECURSE my_c_list RELATIVE ${CMAKE_SOURCE_DIR} "lab/src/*")
foreach (file_path ${my_c_list})
string(REPLACE ".cpp" "" new_name ${file_path})
get_filename_component(filename ${new_name} NAME)
add_executable(${filename} ${file_path} src/glad.c include/InitShader.cpp include/Camera.cpp include/Texture/Texture.cpp include/TriMesh.cpp)
endforeach ()
# 利用for循环逐步编译tutorial的文件
file(GLOB_RECURSE my_c_list RELATIVE ${CMAKE_SOURCE_DIR} "tutorial/*")
foreach (file_path ${my_c_list})
string(REPLACE ".cpp" "" new_name ${file_path})
get_filename_component(filename ${new_name} NAME)
add_executable(${filename} ${file_path} src/glad.c include/Camera/Camera.cpp include/Texture/Texture.cpp)
endforeach ()
endif ()
# 如果编译期的环境是Windows的话,那么就使用如下的cmake
if (CMAKE_SYSTEM_NAME MATCHES "Windows")
message("Now System is Windows")
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include)
link_directories(${PROJECT_SOURCE_DIR}/lib)
find_package(assimp REQUIRED)
link_libraries(${PROJECT_SOURCE_DIR}/lib/glfw3.dll)
add_executable(main main.cpp src/glad.c include/InitShader.cpp include/Camera/Camera.cpp)
add_executable(demo demo.cpp src/glad.c include/InitShader.cpp include/Camera.cpp include/TriMesh.cpp)
file(GLOB_RECURSE my_c_list RELATIVE ${CMAKE_SOURCE_DIR} "lab/src/*")
foreach (file_path ${my_c_list})
string(REPLACE ".cpp" "" new_name ${file_path})
get_filename_component(filename ${new_name} NAME)
add_executable(${filename} ${file_path} src/glad.c include/InitShader.cpp include/Camera/Camera.cpp include/Texture/Texture.cpp include/TriMesh.cpp)
endforeach ()
link_libraries(assimp)
# 利用for循环逐步编译tutorial的文件
file(GLOB_RECURSE my_c_list RELATIVE ${CMAKE_SOURCE_DIR} "tutorial/*")
foreach (file_path ${my_c_list})
string(REPLACE ".cpp" "" new_name ${file_path})
get_filename_component(filename ${new_name} NAME)
add_executable(${filename} ${file_path} src/glad.c include/Camera/Camera.cpp include/Texture/Texture.cpp)
endforeach ()
endif ()
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
message("Now System is Linux")
link_directories(/usr/lib)
add_subdirectory(glfwSource)
find_package(glfw3 3.3 REQUIRED)
# 利用for循环逐步编译tutorial的文件
file(GLOB_RECURSE my_c_list RELATIVE ${CMAKE_SOURCE_DIR} "tutorial/*")
foreach (file_path ${my_c_list})
string(REPLACE ".cpp" "" new_name ${file_path})
get_filename_component(filename ${new_name} NAME)
add_executable(${filename} ${file_path} src/glad.c)
target_link_libraries(${filename} glfw ${CMAKE_DL_LIBS})
endforeach ()
endif ()