File: CMakeLists.txt

package info (click to toggle)
openlayer 2.1-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,368 kB
  • ctags: 2,295
  • sloc: ansic: 10,432; cpp: 9,890; xml: 109; makefile: 89; sh: 36
file content (350 lines) | stat: -rw-r--r-- 12,481 bytes parent folder | download | duplicates (2)
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
# -------------------------------------------------------
# OpenLayer cmake build script. Creates makefiles for unix 
# based systems and/or
# project files for a given environment like MSVC.
#
# TODO:
#	* Create CYGWIN TARGET
#	* Fix MSVC
#	* Seperate into modules?
#
# Written by: juvinious
# -------------------------------------------------------

# -------------------------------------------------------
# Ensure that we are doing an out of source build
# Prevents any mishaps
# -------------------------------------------------------
if(EXISTS ${CMAKE_SOURCE_DIR}/CMakeCache.txt)
	file(REMOVE ${CMAKE_SOURCE_DIR}/CMakeCache.txt)
	file(REMOVE_RECURSE ${CMAKE_SOURCE_DIR}/CMakeFiles)
endif(EXISTS ${CMAKE_SOURCE_DIR}/CMakeCache.txt)
if(EXISTS ${CMAKE_BINARY_DIR}/Makefile)
	file(REMOVE ${CMAKE_BINARY_DIR}/Makefile)
endif(EXISTS ${CMAKE_BINARY_DIR}/Makefile)	
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
	if(UNIX AND NOT CYGWIN)
		message(FATAL_ERROR "Oops. Don't do an in-source build. Create an extra directory change into it and run cmake pointing to the base directory. IE: \nmkdir mybuild && cd mybuild && cmake ../ && make\nYou may need to remove CMakeCache.txt and the CMakeFiles directory in ${CMAKE_SOURCE_DIR} if you can't get rid of this error.")
	else(UNIX AND NOT CYGWIN)
		message(FATAL_ERROR "Oops. Don't do an in-source build. Create an extra directory change into it and run cmake pointing to the base directory. IE: \nmkdir mybuild; cd mybuild; cmakesetup ../\nYou may need to remove CMakeCache.txt and the CMakeFiles directory in  ${CMAKE_SOURCE_DIR} if you can't get rid of this error.")
	endif(UNIX AND NOT CYGWIN)
endif(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})


# -------------------------------------------------------
# Set working directories
# -------------------------------------------------------
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)


# -------------------------------------------------------
# Directory in which extra macros can be found
# -------------------------------------------------------
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/build)

# -------------------------------------------------------
# Add in uninstall target 
# -------------------------------------------------------
configure_file(
  "${CMAKE_CURRENT_SOURCE_DIR}/build/cmake_uninstall.cmake.in"
  "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
  IMMEDIATE @ONLY)

add_custom_target(uninstall
  "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")

# -------------------------------------------------------
# project name
# -------------------------------------------------------
project (OpenLayer)

# -------------------------------------------------------
# Including needed macros
# -------------------------------------------------------
include(CMakeMacros)
find_package(ZLIB)
find_package(FREETYPE)
find_package(PNG)
find_package(ALLEGRO REQUIRED)
find_package(OpenGL REQUIRED)
find_package(ALLEGROGL REQUIRED)

MARK_AS_ADVANCED(
  CLEAR
  ZLIB_LIBRARY
  ZLIB_INCLUDE_DIR
  PNG_LIBRARY
  PNG_INCLUDE_DIR
  OPENGL_glu_LIBRARY
  OPENGL_gl_LIBRARY
  OPENGL_INCLUDE_DIR
  )

# -------------------------------------------------------
# User setable options
# -------------------------------------------------------
## libraries should be shared by default for Debian
if(UNIX AND NOT CYGWIN)
  option(CREATE_STATIC_LIB "Make the library static?" off)
else(UNIX AND NOT CYGWIN)
  option(CREATE_STATIC_LIB "Make the library static?" on)
endif(UNIX AND NOT CYGWIN)
dependent_option(DISABLE_TTF "Disable TTF Support" off "FREETYPE_FOUND" on)
if(NOT DISABLE_TTF)
	set(TTF_OK 1)
endif(NOT DISABLE_TTF)
dependent_option(ENABLE_INTERNAL_FONT "Use internal font renderer" on "TTF_OK" on)
# dependent_option(DISABLE_PNG "Disable PNG support" on "PNG_FOUND" on)
option(DISABLE_PNG "Disable PNG support" off)
option(DISABLE_OLD_API "Disable backwards compatibility with 2.0 and below" off)
option(DISABLE_STATE_CHANGES "Disable state changes" off)

if(NOT MSVC)
	set(CXXFLAGS "-O2 -Wall -fexpensive-optimizations")
else(NOT MSVC)
	set(CXXFLAGS "-O2")
endif(NOT MSVC)

add_definitions(${CXXFLAGS})

# -------------------------------------------------------
# Check whether to create a shared or static library
# -------------------------------------------------------
if(CREATE_STATIC_LIB)
	set(CREATE_STATIC_LIB STATIC)
else(CREATE_STATIC_LIB)
	set(CREATE_STATIC_LIB SHARED)
	set(OL_SHARED 1)
	set(OL_LIB_BUILD 1)
	if(MSVC)
		add_definitions(/DOL_SHARED)
		add_definitions(/DOL_LIB_BUILD)
	else(MSVC)
		add_definitions(-DOL_SHARED)
		add_definitions(-DOL_LIB_BUILD)
	endif(MSVC)
endif(CREATE_STATIC_LIB)

# -------------------------------------------------------
# Paths and system setup
# -------------------------------------------------------

# -------------------------------------------------------
# UNIX BASED SYSTEMS
# -------------------------------------------------------
if(UNIX AND NOT CYGWIN)
	# -------------------------------------------------------
	# Take those user options and set the necessary compile time preprocessors
	# -------------------------------------------------------
	if(NOT DISABLE_TTF)
		if(ENABLE_INTERNAL_FONT)
			add_definitions(-DUSE_NEW_TTF)
			set(USE_NEW_TTF 1)
		endif(ENABLE_INTERNAL_FONT)
	else(NOT DISABLE_TTF)
		add_definitions(-DOL_NO_TTF)
		set(OL_NO_TTF 1)
	endif(NOT DISABLE_TTF)
	if(DISABLE_PNG)
		add_definitions(-DOL_NO_PNG)
		set(OL_NO_PNG 1)
	endif(DISABLE_PNG)
	if(DISABLE_OLD_API)
		add_definitions(-DOL_NO_OLD_API)
		set(OL_NO_OLD_API 1)
	endif(DISABLE_OLD_API)
	if(DISABLE_STATE_CHANGES)
		add_definitions(-DOL_NO_STATE_CHANGE)
		set(OL_NO_STATE_CHANGE 1)
	endif(DISABLE_STATE_CHANGES)
	
	if(NOT ENABLE_INTERNAL_FONT)
		add_subdirectory(utils/glyphkeeper)
		set(GLYPHKEEPER_LIB glyph-agl)
	endif(NOT ENABLE_INTERNAL_FONT)

endif(UNIX AND NOT CYGWIN)

# -------------------------------------------------------
# MINGW
# -------------------------------------------------------

if(MINGW)
	# -------------------------------------------------------
	# Take those user options and set the necessary compile time preprocessors
	# -------------------------------------------------------
	if(NOT DISABLE_TTF)
		if(ENABLE_INTERNAL_FONT)
			add_definitions(-DUSE_NEW_TTF)
			set(USE_NEW_TTF 1)
		endif(ENABLE_INTERNAL_FONT)
	else(NOT DISABLE_TTF)
		add_definitions(-DOL_NO_TTF)
		set(OL_NO_TTF 1)
	endif(NOT DISABLE_TTF)
	if(DISABLE_PNG)
		add_definitions(-DOL_NO_PNG)
		set(OL_NO_PNG 1)
	endif(DISABLE_PNG)
	if(DISABLE_OLD_API)
		add_definitions(-DOL_NO_OLD_API)
		set(OL_NO_OLD_API 1)
	endif(DISABLE_OLD_API)
	if(DISABLE_STATE_CHANGES)
		add_definitions(-DOL_NO_STATE_CHANGE)
		set(OL_NO_STATE_CHANGE 1)
	endif(DISABLE_STATE_CHANGES)
	
	if(NOT ENABLE_INTERNAL_FONT)
		add_subdirectory(utils/glyphkeeper)
		set(GLYPHKEEPER_LIB glyph-agl)
	endif(NOT ENABLE_INTERNAL_FONT)
	
	set(WIN_LIBS -luser32 -lgdi32) 
endif(MINGW)

# -------------------------------------------------------
# MSVC
# -------------------------------------------------------

if(MSVC)
	# -------------------------------------------------------
	# Take those user options and set the necessary compile time preprocessors
	# -------------------------------------------------------
	SET(CMAKE_CXX_FLAGS "/nologo /W3 /Gy")
    	SET(CMAKE_CXX_FLAGS_DEBUG "/MTd /Z7 /Od")
	SET(CMAKE_CXX_FLAGS_RELEASE "/MT /O2")
	SET(CMAKE_CXX_FLAGS_MINSIZEREL "/MT /O2")
	SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MTd /Z7 /Od")
	set(CMAKE_CONFIGURATION_TYPES Release)
	add_definitions("/link SUBSYSTEM:WINDOWS")
	
	if(NOT DISABLE_TTF)
		if(ENABLE_INTERNAL_FONT)
			add_definitions(/DUSE_NEW_TTF)
			set(USE_NEW_TTF 1)
		endif(ENABLE_INTERNAL_FONT)
	else(NOT DISABLE_TTF)
		add_definitions(/DOL_NO_TTF)
		set(OL_NO_TTF 1)
	endif(NOT DISABLE_TTF)
	if(DISABLE_PNG)
		add_definitions(/DOL_NO_PNG)
		set(OL_NO_PNG 1)
	endif(DISABLE_PNG)
	if(DISABLE_OLD_API)
		add_definitions(/DOL_NO_OLD_API)
		set(OL_NO_OLD_API 1)
	endif(DISABLE_OLD_API)
	if(DISABLE_STATE_CHANGES)
		add_definitions(/DOL_NO_STATE_CHANGE)
		set(OL_NO_STATE_CHANGE 1)
	endif(DISABLE_STATE_CHANGES)
	
	if(NOT ENABLE_INTERNAL_FONT)
		add_subdirectory(utils/glyphkeeper)
		set(GLYPHKEEPER_LIB glyph-agl)
	endif(NOT ENABLE_INTERNAL_FONT)
	
	set(WIN_LIBS /user32 /gdi32) 
endif(MSVC)

# -------------------------------------------------------
# Added stuff for osx
# -------------------------------------------------------
if(APPLE)
	set(WIN_LIBS "-framework Carbon")
endif(APPLE)

# -------------------------------------------------------
# Setup some vars that might cause dep issues
# -------------------------------------------------------
if(DISABLE_PNG)
	set(PNG_LIB "")
else(DISABLE_PNG)
	set(PNG_LIB ${PNG_LIBRARY})
endif(DISABLE_PNG)
if(DISABLE_TTF)
	set(FREETYPE_LIB "")
	set(FREETYPE_INCLUDE "")
	set(ZLIB_LIB "")
else(DISABLE_TTF)
	set(FREETYPE_LIB ${FREETYPE_LIBRARY})
	set(FREETYPE_INCLUDE ${FREETYPE_INCLUDE_DIR})
	set(ZLIB_LIB ${ZLIB_LIBRARY})
endif(DISABLE_TTF)	

# -------------------------------------------------------
# Create the necessary header file for the library
# -------------------------------------------------------
configure_file(build/OpenLayer.hpp.in ${CMAKE_BINARY_DIR}/include/OpenLayer.hpp)

# -------------------------------------------------------
# openlayer-config for *nix based systems
# -------------------------------------------------------
if(UNIX AND NOT CYGWIN)
	if(NOT DISABLE_TTF)
		if(NOT ENABLE_INTERNAL_FONT)
			set(R_GK -lglyph-agl)
		endif(NOT ENABLE_INTERNAL_FONT)
		set(R_FT -lfreetype)
	endif(NOT DISABLE_TTF)
	if(NOT DISABLE_PNG)
		set(R_PNG -lpng)
	endif(NOT DISABLE_PNG)
	set(REQUIRED_LIBS "-lagl ${R_PNG} ${R_GK} ${R_FT} -lz `allegro-config --libs` -lGL -lGLU")
	configure_file(build/openlayer-config.in ${CMAKE_BINARY_DIR}/bin/openlayer-config ESCAPE_QUOTES)
endif(UNIX AND NOT CYGWIN)

# -------------------------------------------------------
# Source directory containing all the necessary .cpp files
# -------------------------------------------------------
aux_source_directory(src SOURCES)

# -------------------------------------------------------
# Include directory
# -------------------------------------------------------
if(UNIX AND NOT CYGWIN)
  set(FREETYPE_INCLUDE "/usr/include/freetype2")
endif(UNIX AND NOT CYGWIN)

include_directories(include ${CMAKE_BINARY_DIR}/include include/OpenLayer ${FREETYPE_INCLUDE})

# -------------------------------------------------------
# OpenLayer Library
# -------------------------------------------------------
add_library (openlayer ${CREATE_STATIC_LIB} ${SOURCES})
if(UNIX AND NOT CYGWIN)
  SET_TARGET_PROPERTIES(
    openlayer
    PROPERTIES
    SOVERSION 2
    VERSION 2.1.0
    )
endif(UNIX AND NOT CYGWIN)

# -------------------------------------------------------
# Create the library
# -------------------------------------------------------
target_link_libraries(openlayer ${ALLEGROGL_LIBRARY} ${PNG_LIB} ${GLYPHKEEPER_LIB} ${FREETYPE_LIB} ${ZLIB_LIB} ${ALLEGRO_LIBRARY} ${OPENGL_LIBRARIES} ${WIN_LIBS})

# -------------------------------------------------------
# Demos
# -------------------------------------------------------
add_subdirectory(${CMAKE_SOURCE_DIR}/demos)

# -------------------------------------------------------
# Installation
# -------------------------------------------------------
if(NOT MSVC)
	if(NOT ${CMAKE_INSTALL_PREFIX} AND ${CMAKE_INSTALL_PREFIX} STREQUAL "")
		message(FATAL_ERROR "You need to set the base location where to install OpenLayer (ie /usr/local)")
	endif(NOT ${CMAKE_INSTALL_PREFIX} AND ${CMAKE_INSTALL_PREFIX} STREQUAL "")
	install(FILES ${CMAKE_BINARY_DIR}/include/OpenLayer.hpp DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
	install(DIRECTORY include/OpenLayer DESTINATION ${CMAKE_INSTALL_PREFIX}/include PATTERN ".svn" EXCLUDE PATTERN "*~" EXCLUDE)
	install(TARGETS openlayer DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
	if(UNIX AND NOT CYGWIN)
		install(PROGRAMS ${CMAKE_BINARY_DIR}/bin/openlayer-config DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
	endif(UNIX AND NOT CYGWIN)
endif(NOT MSVC)