-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
150 lines (121 loc) Β· 4.87 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
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
140
141
142
143
144
145
146
147
148
149
150
# From https://gist.github.com/rokups/f771217b2d530d170db5cb1e08e9a8f4
cmake_minimum_required(VERSION 3.10)
########### Variables ############
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(PROJECT_NAME "PetForDesktop")
set(PROJECT_VERSION 1.4.1)
set(REL_RESOURCES_DIR "content")
set(ABS_RESOURCE_DIR "${CMAKE_SOURCE_DIR}/${REL_RESOURCES_DIR}")
set(ABS_DEPS_DIR "${CMAKE_SOURCE_DIR}/deps")
set(ABS_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/include")
set(ABS_SRC_DIR "${CMAKE_SOURCE_DIR}/src")
set(ABS_MAIN_FILE "${ABS_SRC_DIR}/main.cpp")
set(ABS_RESOURCES_BUILD_LINK "${CMAKE_CURRENT_BINARY_DIR}/${REL_RESOURCES_DIR}")
set(ABS_LICENSE_PATH "${CMAKE_SOURCE_DIR}/LICENSE")
set(ABS_README_PATH "${CMAKE_SOURCE_DIR}/README.md")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
########### Create project ############
project(${PROJECT_NAME} VERSION ${PROJECT_VERSION})
message(STATUS "Project ${PROJECT_NAME} ${PROJECT_VERSION}")
########### Setup ############
# Set env variable
if (CMAKE_BUILD_TYPE MATCHES Release)
message(STATUS "Generate CMake cache for Release")
if (WIN32)
set(SUB_SYS WIN32)
endif(WIN32)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
else ()
message(STATUS "Generate CMake cache for Debug")
endif (CMAKE_BUILD_TYPE MATCHES Release)
# Graphic API
option(USE_OPENGL_API "Use OpenGL graphic api" FALSE)
message(STATUS "USE_OPENGL_API: ${USE_OPENGL_API}")
########### Build ############
file(GLOB_RECURSE project_source_files LIST_DIRECTORIES false CONFIGURE_DEPENDS src/*.cpp src/*.c)
file(GLOB_RECURSE project_headers LIST_DIRECTORIES false CONFIGURE_DEPENDS include/*.hpp include/*.h)
message(STATUS "Headers: ${project_headers}")
message(STATUS "Sources : ${project_source_files}")
# Set include directory
include_directories("${ABS_INCLUDE_DIR}/")
# Set icon
if (WIN32)
set(APP_ICON_RESOURCE "${CMAKE_CURRENT_SOURCE_DIR}/appicon.rc")
endif ()
# add the executable
add_executable(${PROJECT_NAME} ${SUB_SYS} ${project_headers} ${project_source_files} ${APP_ICON_RESOURCE})
########### Install setup ############
# Setup install process
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}/)
if (WIN32)
install(DIRECTORY ${REL_RESOURCES_DIR} DESTINATION ${CMAKE_INSTALL_DATADIR}/)
else()
install(DIRECTORY ${REL_RESOURCES_DIR} DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR})
endif()
########### Deps ############
# GLFW
set (GLFW_BUILD_EXAMPLES OFF)
set (GLFW_BUILD_TESTS OFF)
set (GLFW_BUILD_DOCS OFF)
set (GLFW_INSTALL OFF)
add_subdirectory(${ABS_DEPS_DIR}/glfw)
target_link_libraries(${PROJECT_NAME} glfw)
# Graphic API
if(USE_OPENGL_API)
find_package(OpenGL REQUIRED)
target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARIES})
endif()
# Boxer
add_subdirectory(${ABS_DEPS_DIR}/Boxer)
target_link_libraries(${PROJECT_NAME} Boxer)
# yaml-cpp
add_subdirectory(${ABS_DEPS_DIR}/yaml-cpp)
target_link_libraries(${PROJECT_NAME} yaml-cpp)
# cpr
set(CURL_ZLIB OFF CACHE STRING "" FORCE)
add_subdirectory(${ABS_DEPS_DIR}/cpr)
target_link_libraries(${PROJECT_NAME} cpr)
# imgui
set(IMGUI_IMPL_OPENGL3 ON)
set(IMGUI_IMPL_GLFW ON)
set(IMGUI_EXAMPLES OFF)
set(IMGUI_DEMO OFF)
set(IMGUI_ENABLE_FREETYPE OFF)
set(IMGUI_IMPL_SDL OFF)
set(IMGUI_IMPL_METAL OFF)
set(IMGUI_IMPL_OSX OFF)
set(IMGUI_IMPL_WIN32 OFF)
set(IMGUI_IMPL_GLUT OFF)
set(IMGUI_IMPL_OPENGL2 OFF)
set(IMGUI_IMPL_DX9 OFF)
set(IMGUI_IMPL_DX10 OFF)
set(IMGUI_IMPL_DX11 OFF)
set(IMGUI_IMPL_DX12 OFF)
set(IMGUI_IMPL_VULKAN OFF)
add_subdirectory(${ABS_DEPS_DIR}/imgui)
target_link_libraries(${PROJECT_NAME} imgui imgui-glfw imgui-opengl3)
########### Define ############
target_compile_definitions(${PROJECT_NAME} PRIVATE RESOURCE_PATH="${REL_RESOURCES_DIR}")
target_compile_definitions(${PROJECT_NAME} PRIVATE PROJECT_NAME="${PROJECT_NAME}")
target_compile_definitions(${PROJECT_NAME} PRIVATE PROJECT_VERSION="${PROJECT_VERSION}")
target_compile_definitions(${PROJECT_NAME} PRIVATE IMGUI_DEFINE_MATH_OPERATORS)
# Graphic API
if(USE_OPENGL_API)
target_compile_definitions(${PROJECT_NAME} PRIVATE SHADER_RESOURCE_PATH="${REL_RESOURCES_DIR}/shader/glsl")
target_compile_definitions(${PROJECT_NAME} PRIVATE SHADER_VERTEX_EXT=".vs")
target_compile_definitions(${PROJECT_NAME} PRIVATE SHADER_FRAG_EXT=".fs")
target_compile_definitions(${PROJECT_NAME} PRIVATE GLFW_INCLUDE_NONE)
target_compile_definitions(${PROJECT_NAME} PRIVATE USE_OPENGL_API)
endif()
if (WIN32)
target_compile_definitions(${PROJECT_NAME} PRIVATE NOMINMAX)
endif ()
########### Build link ############
# Set a symbolic link so exe can find the /Data folder
add_custom_target(copy_assets
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/${REL_RESOURCES_DIR} ${CMAKE_CURRENT_BINARY_DIR}/${REL_RESOURCES_DIR}
)
add_dependencies(${PROJECT_NAME} copy_assets)