-
Notifications
You must be signed in to change notification settings - Fork 13
/
CMakeLists.txt
94 lines (72 loc) · 2.54 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
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
# cmake最低版本号要求
cmake_minimum_required (VERSION 2.8)
set(PROJECT_NAME Breakout)
project (${PROJECT_NAME})
set (${PROJECT_NAME}_VERSION_MAJOR 1)
set (${PROJECT_NAME}_VERSION_MINOR 0)
set (CMAKE_CXX_STAND 11)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# 配置一个头文件来传递一个cmake设置到源代码
configure_file (
"${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.h.in"
"${PROJECT_SOURCE_DIR}/${PROJECT_NAME}Config.h"
)
set (3RD_DIR ${PROJECT_SOURCE_DIR}/3rd)
set(CMAKE_MODULE_PATH ${3RD_DIR})
# IrrKlang
find_package (IrrKlang REQUIRED)
include_directories (${IRRKLANG_INCLUDE_DIR})
# glfw
set (GLFW_DIR ${3RD_DIR}/glfw)
# 保证glfw dir被编译
add_subdirectory (${GLFW_DIR})
# 添加头文件搜索路径
include_directories (${GLFW_DIR}/include)
# glad
set (GLAD_DIR ${3RD_DIR}/glad)
include_directories (${GLAD_DIR}/include)
# 生成链接库
add_library (glad ${GLAD_DIR}/src/glad.c)
# glm
set (GLM_DIR ${3RD_DIR}/glm)
include_directories (${GLM_DIR}/glm)
# freetype
set (FREETYPE_DIR ${3RD_DIR}/freetype)
add_subdirectory (${FREETYPE_DIR})
include_directories (${FREETYPE_DIR}/include)
# stb_image
set (STB_IMAGE_DIR ${3RD_DIR}/stb_image)
include_directories (${STB_IMAGE_DIR})
add_library (stb_image ${STB_IMAGE_DIR}/stb_image.cc)
# 设置MSVC编译编码
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/source-charset:utf-8>")
# 查找当前目录下的所有源文件并存入DIR_SRCS变量
# aux_source_directory(src SRC_DIR)
# 递归列出所有源文件
file (GLOB_RECURSE SOURCE_FILES *.cc)
# 添加一个可编译的目标到工程
add_executable (${PROJECT_NAME} ${SOURCE_FILES})
# 设置工作目录
# set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DEBUGGER_WORKING_DIRECTORY
# ${CMAKE_SOURCE_DIR}/resources
# )
# 添加链接库
target_link_libraries (${PROJECT_NAME} glfw glad freetype stb_image ${IRRKLANG_LIBRARY})
# target_compile_definitions(${PROJECT_NAME} PRIVATE GLFW_INCLUDE_NONE)
# 复制库到工作目录
add_custom_command(TARGET ${PROJECT_NAME} PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${IRRKLANG_BIN_DIR}
$<TARGET_FILE_DIR:${PROJECT_NAME}>
)
# 复制资源文件到工作目录
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/resources
$<TARGET_FILE_DIR:${PROJECT_NAME}>/resources
)
if(APPLE)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND install_name_tool -change /usr/local/lib/libirrklang.dylib @executable_path/libirrklang.dylib ${PROJECT_NAME}
)
endif()