forked from g-truc/ogl-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
238 lines (181 loc) · 6.41 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
cmake_policy(VERSION 2.6)
project(ogl-samples-pack)
enable_testing()
#CMAKE_BUILD_TOOL
if(CMAKE_CURRENT_SOURCE_DIR EQUAL CMAKE_CURRENT_BINARY_DIR)
message(FATAL_ERROR "Source and binary directories must be different")
endif(CMAKE_CURRENT_SOURCE_DIR EQUAL CMAKE_CURRENT_BINARY_DIR)
################################
# Add GLEXT
find_package(OpenGL)
if(WIN32)
set(GL_LIBRARY OpenGL32.lib)
elseif(APPLE)
set(GL_LIBRARY ${OPENGL_LIBRARY})
elseif(UNIX)
set(GL_LIBRARY GL)
endif(WIN32)
set(GL_DIRECTORY gl)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/${GL_DIRECTORY}/)
if(NOT OPENGL_FOUND)
message("ERROR: OpenGL not found")
endif(NOT OPENGL_FOUND)
################################
# Add GLFW
set(GLFW_DIRECTORY glfw-2.7.7)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/${GLFW_DIRECTORY}/include)
if(APPLE)
find_library(GLFW_LIBRARY GLFW)
else()
if(MSVC AND NOT CMAKE_CL_64)
set(GLFW_BINARY_DIRECTORY "win32-vc")
endif(MSVC AND NOT CMAKE_CL_64)
if(MSVC AND CMAKE_CL_64)
set(GLFW_BINARY_DIRECTORY "win64-vc")
endif(MSVC AND CMAKE_CL_64)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/${GLFW_DIRECTORY}/bin/${GLFW_BINARY_DIRECTORY})
set(GLFW_LIBRARY glfw)
endif()
################################
# Add Cocoa
if(APPLE)
find_library(COCOA_LIBRARY cocoa)
find_library(IOKIT_LIBRARY iokit)
endif()
################################
# Add GLM
set(GLM_DIRECTORY glm-0.9.4.1)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/${GLM_DIRECTORY})
################################
# Add GLI
set(GLI_DIRECTORY gli-0.4.1.0)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/${GLI_DIRECTORY})
################################
# Add GLO
set(GLO_DIRECTORY glo-0.1.0.0)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/${GLO_DIRECTORY})
################################
# Add GLF
set(GLF_DIRECTORY glf)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/)
################################
# Add OpenGL ES
set(ES_DIRECTORY gles-2.0)
if(MSVC AND NOT CMAKE_CL_64)
set(ES_BINARY_DIRECTORY "win32-vc")
endif(MSVC AND NOT CMAKE_CL_64)
if(MSVC AND CMAKE_CL_64)
set(ES_BINARY_DIRECTORY "win64-vc")
endif(MSVC AND CMAKE_CL_64)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/${ES_DIRECTORY})
if(WIN32)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/${ES_DIRECTORY}/lib/${ES_BINARY_DIRECTORY})
endif()
set(ES_LIBRARY libGLESv2)
################################
# Add EGL
set(EGL_DIRECTORY egl-1.4)
if(MSVC AND NOT CMAKE_CL_64)
set(EGL_BINARY_DIRECTORY "win32-vc")
endif(MSVC AND NOT CMAKE_CL_64)
if(MSVC AND CMAKE_CL_64)
set(EGL_BINARY_DIRECTORY "win64-vc")
endif(MSVC AND CMAKE_CL_64)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/${EGL_DIRECTORY})
if(WIN32)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/external/${EGL_DIRECTORY}/lib/${EGL_BINARY_DIRECTORY})
endif()
set(EGL_LIBRARY libEGL)
################################
# Add libraries to executables
set(BINARY_FILES
${GL_LIBRARY}
${GLEW_LIBRARY}
${GLFW_LIBRARY}
${GLM_LIBRARY}
${GLI_LIBRARY}
${COCOA_LIBRARY}
${IOKIT_LIBRARY})
################################
# Add output directory
if(MSVC)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/build/)
else(MSVC)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/build/debug )
else(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/build/release )
endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
endif(MSVC)
################################
# Add custom target to copy all data
if(APPLE)
add_custom_target(
${TARGET_DATA_COPY}
COMMAND ls)
else(APPLE)
set(TARGET_DATA_COPY DATA_COPY)
if(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
add_custom_target(
${TARGET_DATA_COPY}
COMMAND ${CMAKE_COMMAND} -E echo "In source build")
else(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
add_custom_target(
${TARGET_DATA_COPY}
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/data ${CMAKE_CURRENT_BINARY_DIR}/data)
endif(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR})
endif(APPLE)
set(OGL_DATA_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/data)
################################
# Add options
option(OGL_SAMPLES_STATUS "OGL_SAMPLES_STATUS" OFF)
if(OGL_SAMPLES_STATUS)
add_definitions(-DGLF_AUTO_STATUS)
endif()
################################
# Add definitions
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif(MSVC)
################################
# function to create a project for the sample in the solution
function(createSample NAME)
file(GLOB PROJECT_SOURCE *.cpp)
file(GLOB_RECURSE PROJECT_SHADER *.vert *.frag *.geom *.cont *.eval *.glsl *.vs *.fs *.gs *.ps *.es)
file(GLOB PROJECT_INLINE *.inl)
file(GLOB PROJECT_HEADER *.hpp)
file(GLOB PROJECT_TEXT readme.txt)
source_group("Text Files" FILES ${PROJECT_TEXT})
source_group("Inline Files" FILES ${PROJECT_INLINE})
source_group("Shader Files" FILES ${PROJECT_SHADER})
add_executable(${NAME} ${PROJECT_SOURCE} ${PROJECT_INLINE} ${PROJECT_HEADER} ${PROJECT_SHADER} ${PROJECT_TEXT})
add_custom_command(
TARGET ${NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/data ${CMAKE_CURRENT_BINARY_DIR}/data)
add_custom_command(
TARGET ${NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${ASSIMP_BINARY} ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(${NAME} ${BINARY_FILES})
endfunction(createSample)
function(createSampleWGL NAME)
file(GLOB PROJECT_SOURCE *.cpp)
file(GLOB_RECURSE PROJECT_SHADER *.vert *.frag *.geom *.cont *.eval *.glsl)
file(GLOB PROJECT_INLINE *.inl)
file(GLOB PROJECT_HEADER *.hpp)
file(GLOB PROJECT_TEXT readme.txt)
source_group("Text Files" FILES ${PROJECT_TEXT})
source_group("Inline Files" FILES ${PROJECT_INLINE})
source_group("Shader Files" FILES ${PROJECT_SHADER})
add_executable(${NAME} WIN32 ${PROJECT_SOURCE} ${PROJECT_INLINE} ${PROJECT_HEADER} ${PROJECT_SHADER} ${PROJECT_TEXT})
add_custom_command(
TARGET ${NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/data ${CMAKE_CURRENT_BINARY_DIR}/data)
add_custom_command(
TARGET ${NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${ASSIMP_BINARY} ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(${NAME} ${BINARY_FILES})
endfunction(createSampleWGL)
################################
# Add subdirectory
add_subdirectory(samples)