This repository has been archived by the owner on Feb 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
376 lines (283 loc) · 11.4 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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
#####################################################################
# Main CMake file for the OpenGLCourse Project
cmake_minimum_required (VERSION 2.8)
project (OpenGLCourse)
set(OPENGLCOURSE_VERSION_MAJOR "1")
set(OPENGLCOURSE_VERSION_MINOR "1")
set(OPENGLCOURSE_VERSION_PATCH "0")
set(OPENGLCOURSE_VERSION_EXTRA "")
set(OPENGLCOURSE_VERSION "${OPENGLCOURSE_VERSION_MAJOR}.${OPENGLCOURSE_VERSION_MINOR}")
set(OPENGLCOURSE_VERSION_FULL "${OPENGLCOURSE_VERSION}.${OPENGLCOURSE_VERSION_PATCH}${OPENGLCOURSE_VERSION_EXTRA}")
#####################################################################
# Options
option(OPENGLCOURSE_BUILD_EXAMPLES "Build the OpenGLCourse example programs" ON)
#####################################################################
# Detect OS and Basic Compiler settings
# Assume GCC under Linux, Clang under OSX and CL under Windows32
# No target for Windows 64 as yet.
# Need to test for 64 bit Linux. OSX is 64 bit non universal by default
if (WIN32)
set(_OPENGLCOURSE_WIN32 1)
message(STATUS "Building OPENGLCOURSE Shared on a Win32 system")
add_definitions(-D_OPENGLCOURSE_WIN32)
add_definitions(-D_OPENGLCOURSE_BUILD_DLL)
SET(CMAKE_CXX_FLAGS "/EHsc")
FILE(GLOB OSSources src/win32/*)
#SET(CMAKE_MODULE_LINKER_FLAGS "/NODEFAULTLIB")
#CMAKE_EXE_LINKER_FLAGS
#CMAKE_SHARED_LINKER_FLAGS
#CMAKE_MODULE_LINKER_FLAGS
elseif (UNIX AND APPLE)
set(_OPENGLCOURSE_OSX 1)
add_definitions(-D_OPENGLCOURSE_OSX)
message(STATUS "Building OPENGLCOURSE Shared on Mac OS X")
FILE(GLOB OSSources src/osx/*)
elseif (UNIX AND NOT APPLE)
set(_OPENGLCOURSE_LINUX 1)
add_definitions(-D_OPENGLCOURSE_LINUX)
message(STATUS "Building OPENGLCOURSE Shared on a Unix-like system")
FILE(GLOB OSSources src/linux/*)
else()
message(FATAL_ERROR "No supported platform was detected")
endif()
################################
# DEBUG mode for Compilation
# TODO - Should affect linking also
option(DEBUG "Debug Mode" ON)
if(DEBUG)
add_definitions(-DDEBUG)
set(_OPENGLCOURSE_DEBUG 1)
if (_OPENGLCOURSE_OSX OR _OPENGLCOURSE_LINUX)
SET(CMAKE_CXX_FLAGS_DEBUG "-g")
else()
endif()
else()
endif()
###########
#####################################################################
# S9 Includes
include_directories(include)
#####################################################################
# OpenGL for now
FILE(GLOB GLSources src/gl/*)
FILE(GLOB GLUtils src/gl/utils/*)
#####################################################################
# Macro to find libraries in the local lib directory then system wide
macro(OPENGLCOURSE_find_library libname)
string(TOLOWER ${libname} libnamelow)
find_library(${libname}_LIB NAMES ${libname} PATHS ${LOCAL_LIBRARIES_SEARCH_PATHS} NO_DEFAULT_PATH)
if (NOT ${libname}_LIB)
find_library(${libname}_LIB NAMES ${libnamelow} PATHS ${LIBRARIES_SEARCH_PATHS})
endif()
if (NOT ${libname}_LIB)
message(FATAL_ERROR "Cannot find '${libname}' library")
else()
message(STATUS "Found '${libname}' library in ${${libname}_LIB}")
set(OPENGLCOURSE_LIBRARIES ${OPENGLCOURSE_LIBRARIES} ${${libname}_LIB})
endif()
endmacro()
#####################################################################
# Extra Libraries and their paths
if (_OPENGLCOURSE_LINUX)
set (CMAKE_FIND_LIBRARY_PREFIXES "lib" "")
set (CMAKE_FIND_LIBRARY_SUFFIXES ".so" ".a")
set(LIBRARIES_SEARCH_PATHS
/usr/local/lib/
/usr/local/lib64/
CACHE STRING "Library search paths")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(LOCAL_LIBRARIES_SEARCH_PATHS
${CMAKE_SOURCE_DIR}/lib/linux64
CACHE STRING "Local Library search paths")
link_directories(${PROJECT_SOURCE_DIR}/lib/linux64)
else()
set(LOCAL_LIBRARIES_SEARCH_PATHS
${CMAKE_SOURCE_DIR}/lib/linux32
CACHE STRING "Local Library search paths")
link_directories(${PROJECT_SOURCE_DIR}/lib/linux32)
endif()
# Setup pkgconfig macro for including extra things
macro(OPENGLCOURSE_find_pkgconfig_lib pkgname)
include(FindPkgConfig)
pkg_check_modules(${pkgname}_pkg REQUIRED ${pkgname})
if ( DEFINED ${pkgname}_pkg_FOUND )
set (OPENGLCOURSE_LIBRARIES ${OPENGLCOURSE_LIBRARIES} ${${pkgname}_pkg_LIBRARIES}
${${pkgname}_pkg_LDFLAGS} ${${pkgname}_pkg_LDFLAGS_OTHER})
set (OPENGLCOURSE_INCLUDES ${OPENGLCOURSE_INCLUDES} ${${pkgname}_pkg_INCLUDE_DIRS})
set (OPENGLCOURSE_CXX_FLAGS ${OPENGLCOURSE_CXX_FLAGS} ${${pkgname}_pkg_CFLAGS})
else()
message( FATAL_ERROR "Cannot find pkgconfig file for ${pkgconfig}. Check your PKG_CONFIG_PATH environment variable.")
endif()
endmacro(OPENGLCOURSE_find_pkgconfig_lib)
OPENGLCOURSE_find_pkgconfig_lib(gtkmm-3.0)
OPENGLCOURSE_find_pkgconfig_lib(gl)
OPENGLCOURSE_find_library(glfw)
OPENGLCOURSE_find_library(AntTweakBar)
OPENGLCOURSE_find_pkgconfig_lib(xxf86vm)
OPENGLCOURSE_find_pkgconfig_lib(xrandr)
OPENGLCOURSE_find_pkgconfig_lib(xi)
include_directories(${PROJECT_SOURCE_DIR}/lib/linux
${OPENGLCOURSE_INCLUDES}
)
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -lXi -lXrandr -lXxf86vm")
elseif(_OPENGLCOURSE_OSX)
link_directories(${PROJECT_SOURCE_DIR}/lib/osx)
set (CMAKE_FIND_LIBRARY_PREFIXES "" "lib")
set (CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".a" ".lib", ".so")
#set (CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-m32")
#set (CMAKE_OSX_ARCHITECTURES "i386")
find_library(IOKIT_FRAMEWORK IOKit)
find_library(CORE_FOUNDATION_FRAMEWORK CoreFoundation)
FIND_LIBRARY(OPENGL_LIBRARY OpenGL)
FIND_LIBRARY(COCOA_LIBRARY Cocoa )
MARK_AS_ADVANCED (COCOA_LIBRARY
OPENGL_LIBRARY)
SET(OSX_FRAMEWORKS ${COCOA_LIBRARY}
${OPENGL_LIBRARY}
${IOKIT_FRAMEWORK}
${CORE_FOUNDATION_FRAMEWORK}
)
set(LIBRARIES_SEARCH_PATHS
/usr/local/lib/
/usr/local/lib64/
CACHE STRING "Library search paths")
set(LOCAL_LIBRARIES_SEARCH_PATHS
${CMAKE_SOURCE_DIR}/lib/osx
CACHE STRING "Local Library search paths")
OPENGLCOURSE_find_library(glfw3)
OPENGLCOURSE_find_library(AntTweakBar)
elseif(_OPENGLCOURSE_WIN32)
if (DEBUG)
link_directories(${PROJECT_SOURCE_DIR}/lib/win32/Debug)
set(LOCAL_LIBRARIES_SEARCH_PATHS
${CMAKE_SOURCE_DIR}/lib/win32/Debug
CACHE STRING "Local Library search paths")
elseif()
link_directories(${PROJECT_SOURCE_DIR}/lib/win32/Release)
set(LOCAL_LIBRARIES_SEARCH_PATHS
${CMAKE_SOURCE_DIR}/lib/win32/Release
CACHE STRING "Local Library search paths")
endif()
find_package(OpenGL REQUIRED)
OPENGLCOURSE_find_library(glfw3) # Built from the github version 3 build
OPENGLCOURSE_find_library(AntTweakBar)
else()
message(FATAL_ERROR "No supported platform was detected")
endif()
#####################################################################
# Boost - Regular and installed
# This assumes boost is built for static inclusion as libs for
# MSVC 2010 in release mode
# http://cpprocks.com/using-cmake-to-build-a-cross-platform-project-with-a-boost-dependency/
if(WIN32)
SET(Boost_USE_STATIC_LIBS ON)
SET(Boost_USE_MULTITHREADED ON)
SET(Boost_USE_STATIC_RUNTIME ON)
SET(BOOST_ALL_DYN_LINK OFF)
#add_definitions(-DBOOST_ALL_NO_LIB)
#SET(CMAKE_SHARED_LINKER_FLAGS /NODEFAULTLIB:LIBC;LIBCMT;MSVCRT)
endif()
message("Looking for Installed BOOST Libraries")
find_package(Boost COMPONENTS system filesystem signals iostreams program_options thread REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIRS})
message(status "** Boost Include: ${Boost_INCLUDE_DIR}")
message(status "** Boost Libraries: ${Boost_LIBRARY_DIRS}")
message(status "** Boost Libraries: ${Boost_LIBRARIES}")
######################################################################
# Glob Source files
FILE(GLOB CommonSources src/*)
# Not sure why I have these?
list(REMOVE_ITEM GLUtils ${PROJECT_SOURCE_DIR}/src/gl/utils/glewinfo.c)
list(REMOVE_ITEM GLUtils ${PROJECT_SOURCE_DIR}/src/gl/utils/visualinfo.c)
#####################################################################
# Create Target
# Final removals for Win32 until we add fixes
if (_OPENGLCOURSE_WIN32)
#list(REMOVE_ITEM GLSources ${PROJECT_SOURCE_DIR}/src/gl/glew.c)
# Make sure we are using /MT this time around. We may change to /MD
# but we MUST be consistent
set(CompilerFlags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
)
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()
elseif(_OPENGLCOURSE_LINUX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif()
add_library(OpenGLCourse SHARED
${CommonSources}
${GLSources}
${GLUtils}
${OSSources}
)
# Now link the found libraries to the OPENGLCOURSE library
target_link_libraries(OpenGLCourse
${OPENGLCOURSE_LIBRARIES}
${OPENGL_LIBRARY}
${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARY}
${Boost_THREAD_LIBRARY}
${Boost_IOSTREAMS_LIBRARY}
${Boost_SIGNALS_LIBRARY}
${Boost_PROGRAM_OPTIONS_LIBRARY}
)
# seperate libs depending on OS
if (UNIX AND APPLE)
target_link_libraries(OpenGLCourse
${OSX_FRAMEWORKS}
)
endif()
project(${PROJECT_NAME})
##########################################################
# GLFW Windowed mode (in case you want multiple windows in your GLFW3
# Application)
#option(MULTIWINDOW "Multiple Window Support" OFF)
##########################################################
# Define a bundling Macro for OSX only
if (_OPENGLCOURSE_OSX)
macro(OPENGLCOURSE_bundler)
add_executable(${PROJECT_NAME} MACOSX_BUNDLE app.cpp)
SET(MACOSX_BUNDLE_ICON_FILE ${CMAKE_SOURCE_DIR}/s9.icns)
SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/s9.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "${PROJECT_NAME}")
set(DIRS ${CMAKE_SOURCE_DIR}/lib/osx
${CMAKE_SOURCE_DIR}/data
${CMAKE_SOURCE_DIR}/shaders/3
)
set(MACOSX_BUNDLE_INFO_STRING "${PROJECT_NAME}")
set(MACOSX_BUNDLE_GUI_IDENTIFIER "uk.co.section9.openglcourse.${PROJECT_NAME}")
set(MACOSX_BUNDLE_LONG_VERSION_STRING "${PROJECT_NAME}")
set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
set(MACOSX_BUNDLE_SHORT_VERSION_STRING ${VTK_VERSION})
set(MACOSX_BUNDLE_BUNDLE_VERSION ${VTK_VERSION})
set(MACOSX_BUNDLE_COPYRIGHT "Copyright 2013. All Rights Reserved.")
# Setup the Bundle Files
#add_custom_command (TARGET ${PROJECT_NAME} PRE_BUILD
# COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.app/Contents/Resources)
#add_custom_command (TARGET ${PROJECT_NAME} PRE_BUILD
# COMMAND cp -r ${CMAKE_SOURCE_DIR}/shaders ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.app/Contents/Resources/.)
add_custom_command (TARGET ${PROJECT_NAME} PRE_BUILD
COMMAND cp ${CMAKE_SOURCE_DIR}/lib/osx/* ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.app/Contents/MacOS/.)
INSTALL(CODE "
include(BundleUtilities)
fixup_bundle( ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.app \"\" \"${DIRS}\")
" COMPONENT Runtime)
endmacro(OPENGLCOURSE_bundler)
endif()
#####################################################################
# Go into exercises directory and build these
if (OPENGLCOURSE_BUILD_EXAMPLES)
if (NOT TARGET exercises)
FILE(GLOB exercises exercises/*)
foreach(exercise ${exercises})
add_subdirectory(${exercise})
endforeach()
endif()
endif()