-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
124 lines (107 loc) · 3.37 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
# https://jacquesh.github.io/post/basic-cmake/
# Project definition
cmake_minimum_required(VERSION 3.8.0)
project(glinit)
#set(PRE ${CMAKE_STATIC_LIBRARY_PREFIX})
#set(SUF ${CMAKE_STATIC_LIBRARY_SUFFIX})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /nologo")
# Source directorioes and files
set(SRC_DIR ${CMAKE_SOURCE_DIR}/src)
set(LIB_DIR ${CMAKE_SOURCE_DIR}/lib)
set(BIN_DIR ${CMAKE_SOURCE_DIR}/bin)
# Executable output directory
set(EXECUTABLE_OUTPUT_PATH ${BIN_DIR})
# All needed source files
file(GLOB_RECURSE SOURCES
${SRC_DIR}/*.cpp
${SRC_DIR}/*.h
)
# External glad source file
set(EXTERNAL_SOURCES
${LIB_DIR}/glad/src/glad.c
)
# More external source files.
# In this case, this must be apart because the "ExternalProject_Add"
# that will add imgui, must specify the files that will be generated
# by it with the "BUILD_BYPRODUCTS" option.
set(EXTERNAL_IMGUI_SOURCES
${LIB_DIR}/imgui/imgui.cpp
${LIB_DIR}/imgui/imgui_draw.cpp
${LIB_DIR}/imgui/examples/imgui_impl_glfw.cpp
)
include(ExternalProject)
# -- GLAD ----------------------------------------------------------
set(GLAD_INCLUDE ${LIB_DIR}/glad/include)
# ------------------------------------------------------------------
# -- GLFW ----------------------------------------------------------
set(GLFW_DIR ${LIB_DIR}/glfw)
set(GLFW_INCLUDE ${GLFW_DIR}/include)
set(GLFW_LIB ${GLFW_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}glfw3${CMAKE_STATIC_LIBRARY_SUFFIX})
ExternalProject_Add(glfw
GIT_REPOSITORY https://github.com/glfw/glfw.git
GIT_SHALLOW 1
GIT_TAG 3.2.1
CMAKE_ARGS
-DGLFW_BUILD_EXAMPLES=OFF
-DGLFW_BUILD_TESTS=OFF
-DGLFW_BUILD_DOCS=OFF
-DGLFW_VULKAN_STATIC=OFF
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_INSTALL_PREFIX=${GLFW_DIR}
SOURCE_DIR ${GLFW_DIR}
UPDATE_COMMAND ""
)
# ------------------------------------------------------------------
# -- GLM -----------------------------------------------------------
set(GLM_DIR ${LIB_DIR}/glm)
set(GLM_INCLUDE ${GLM_DIR})
ExternalProject_Add(glm
GIT_REPOSITORY https://github.com/g-truc/glm.git
GIT_SHALLOW 1
GIT_TAG 0.9.9.0
SOURCE_DIR ${GLM_DIR}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
UPDATE_COMMAND ""
)
# ------------------------------------------------------------------
# -- Imgui----------------------------------------------------------
set(IMGUI_DIR ${LIB_DIR}/imgui)
set(IMGUI_INCLUDE ${IMGUI_DIR})
set(IMGUI_IMPL_INCLUDE ${IMGUI_INCLUDE}/examples) # imgui implementation for OpenGL3+
ExternalProject_Add(imgui
GIT_REPOSITORY https://github.com/ocornut/imgui.git
GIT_SHALLOW 1
GIT_TAG v1.62
CMAKE_ARGS -DGLM_INSTALL_ENABLE=OFF
SOURCE_DIR ${IMGUI_DIR}
UPDATE_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
BUILD_BYPRODUCTS ${EXTERNAL_IMGUI_SOURCES}
)
# ------------------------------------------------------------------
# Mian executable
add_executable(${PROJECT_NAME}
${EXTERNAL_SOURCES}
${EXTERNAL_IMGUI_SOURCES}
${SOURCES}
)
# glfw glm and imgui must be download and built before the project
add_dependencies(${PROJECT_NAME} glfw glm imgui)
# Find OpenGL
include(FindOpenGL)
# Add the (.a/.lib) libraries
target_link_libraries(${PROJECT_NAME}
${OPENGL_gl_LIBRARY}
${GLFW_LIB}
)
include_directories(${PROJECT_NAME}
${GLAD_INCLUDE}
${GLFW_INCLUDE}
${GLM_INCLUDE}
${IMGUI_INCLUDE}
${IMGUI_IMPL_INCLUDE}
)