minor update making code more compact.
[freeglut] / CMakeLists.txt
1 CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8 FATAL_ERROR)
2 PROJECT(freeglut)
3
4 # for multiarch LIBDIR support (requires cmake>=2.8.8)
5 INCLUDE(GNUInstallDirs)
6
7 # NOTE: On Windows and Cygwin, the dll's are placed in the
8 # CMAKE_RUNTIME_OUTPUT_DIRECTORY, while their corresponding import
9 # libraries end up in CMAKE_ARCHIVE_OUTPUT_DIRECTORY. On other
10 # platforms, such as Linux, the shared libraries are put in
11 # CMAKE_ARCHIVE_OUTPUT_DIRECTORY instead.
12 # Static libraries end up in CMAKE_ARCHIVE_OUTPUT_DIRECTORY on all
13 # platforms.
14 SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
15 SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
16 SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
17
18 # setup version numbers
19 # TODO: Update these for each release!
20 set(VERSION_MAJOR 3)
21 set(VERSION_MINOR 0)
22 set(VERSION_PATCH 0)
23
24 # Update fg_version.h to match the versions number here in cmake
25 CONFIGURE_FILE(src/fg_version.h.in src/fg_version.h)
26
27 # shared lib version numbers (change before release)
28 set(SO_MAJOR 3)         # increment on backwards incompatible API/ABI changes
29 set(SO_MINOR 10)        # increment on backwards compatible or internal changes
30 set(SO_REV 0)           # if nothing else changed increment this
31
32 # FREEGLUT_BUILD_SHARED_LIBS is already a standard CMake variable, but we need to
33 # re-declare it here so it will show up in the GUI.
34 # by default, we want to build both
35 OPTION(FREEGLUT_BUILD_SHARED_LIBS "Build FreeGLUT shared library." ON)
36 OPTION(FREEGLUT_BUILD_STATIC_LIBS "Build FreeGLUT static library." ON)
37
38 # option for whether warnings and errors should be printed
39 OPTION(FREEGLUT_PRINT_ERRORS "Lib prints errors to stderr" ON)
40 #MARK_AS_ADVANCED(FREEGLUT_PRINT_ERRORS)
41 OPTION(FREEGLUT_PRINT_WARNINGS "Lib prints warnings to stderr" ON)
42 #MARK_AS_ADVANCED(FREEGLUT_PRINT_WARNINGS)
43
44 # option to also copy .pdb files to install directory when executing
45 # INSTALL target
46 IF(MSVC)
47     OPTION(INSTALL_PDB "Also install .pdb files" ON)
48 ELSE()
49     SET(INSTALL_PDB OFF)
50 ENDIF()
51
52 # OpenGL ES support
53 OPTION(FREEGLUT_GLES "Use OpenGL ES (requires EGL)" OFF)
54
55 IF(NOT WIN32)
56     # Wayland support
57     OPTION(FREEGLUT_WAYLAND "Use Wayland (no X11)" OFF)
58     # option to build either as "glut" (ON) or "freeglut" (OFF)
59     OPTION(FREEGLUT_REPLACE_GLUT "Be a replacement for GLUT" ON)
60 ENDIF()
61
62
63 SET(FREEGLUT_HEADERS
64     include/GL/freeglut.h
65     include/GL/freeglut_ext.h
66     include/GL/freeglut_std.h
67     include/GL/glut.h
68 )
69 SET(FREEGLUT_SRCS
70     ${FREEGLUT_HEADERS}
71     src/fg_callbacks.c
72     src/fg_cursor.c
73     src/fg_display.c
74     src/fg_ext.c
75     src/fg_font_data.c
76     src/fg_gamemode.c
77     src/fg_geometry.c
78     src/fg_gl2.c
79     src/fg_gl2.h
80     src/fg_init.c
81     src/fg_init.h
82     src/fg_internal.h
83     src/fg_input_devices.c
84     src/fg_joystick.c
85     src/fg_main.c
86     src/fg_misc.c
87     src/fg_overlay.c
88     src/fg_spaceball.c
89     src/fg_state.c
90     src/fg_stroke_mono_roman.c
91     src/fg_stroke_roman.c
92     src/fg_structure.c
93     src/fg_teapot.c
94     src/fg_teapot_data.h
95     src/fg_videoresize.c
96     src/fg_window.c
97 )
98 # TODO: OpenGL ES requires a compatible version of these files:
99 IF(NOT FREEGLUT_GLES)
100     LIST(APPEND FREEGLUT_SRCS
101         src/fg_font.c
102         src/fg_menu.c
103     )
104 ELSE()
105     LIST(APPEND FREEGLUT_SRCS
106         src/gles_stubs.c
107     )
108 ENDIF()
109
110 IF(WIN32)
111     LIST(APPEND FREEGLUT_SRCS
112         src/mswin/fg_cursor_mswin.c
113         src/mswin/fg_display_mswin.c
114         src/mswin/fg_ext_mswin.c
115         src/mswin/fg_gamemode_mswin.c
116         src/mswin/fg_init_mswin.c
117         src/mswin/fg_internal_mswin.h
118         src/mswin/fg_input_devices_mswin.c
119         src/mswin/fg_joystick_mswin.c
120         src/mswin/fg_main_mswin.c
121         src/mswin/fg_menu_mswin.c
122         src/mswin/fg_spaceball_mswin.c
123         src/mswin/fg_state_mswin.c
124         src/mswin/fg_structure_mswin.c
125         src/mswin/fg_window_mswin.c
126         ${CMAKE_BINARY_DIR}/freeglut.rc # generated below from freeglut.rc.in
127     )
128     IF (MSVC AND NOT CMAKE_CL_64)
129         # .def file only for 32bit Windows builds (TODO: MSVC only right
130         # now, needed for any other Windows platform?)
131         LIST(APPEND FREEGLUT_SRCS
132             ${CMAKE_BINARY_DIR}/freeglutdll.def # generated below from src/freeglutdll.def.in
133         )
134     ENDIF()
135
136 ELSEIF(ANDROID OR BLACKBERRY)
137     # BlackBerry and Android share some similar design concepts and ideas, as with many mobile devices.
138     # As such, some classes can be shared between the two. XXX: Possibly rename shareable classes to
139     # a more generic name. *_stub? *_mobile?
140     LIST(APPEND FREEGLUT_SRCS
141         src/android/fg_cursor_android.c
142         src/android/fg_ext_android.c
143         src/android/fg_gamemode_android.c
144         src/android/fg_joystick_android.c
145         src/android/fg_spaceball_android.c
146     )
147     IF(ANDROID)
148         LIST(APPEND FREEGLUT_SRCS
149             src/android/native_app_glue/android_native_app_glue.c
150             src/android/native_app_glue/android_native_app_glue.h
151             src/android/fg_internal_android.h
152             src/android/fg_init_android.c
153             src/android/fg_input_devices_android.c
154             src/android/fg_main_android.c
155             src/android/fg_main_android.h
156             src/android/fg_runtime_android.c
157             src/android/fg_state_android.c
158             src/android/fg_structure_android.c
159             src/android/fg_window_android.c
160         )
161     ELSE()
162         LIST(APPEND FREEGLUT_SRCS
163             src/blackberry/fg_internal_blackberry.h
164             src/blackberry/fg_init_blackberry.c
165             src/x11/fg_input_devices_x11.c
166             src/blackberry/fg_main_blackberry.c
167             src/blackberry/fg_state_blackberry.c
168             src/blackberry/fg_structure_blackberry.c
169             src/blackberry/fg_window_blackberry.c
170         )
171     ENDIF()
172
173 ELSE()
174     # UNIX (Wayland)
175     IF(FREEGLUT_WAYLAND)
176         LIST(APPEND FREEGLUT_SRCS
177             src/wayland/fg_cursor_wl.c
178             src/wayland/fg_ext_wl.c
179             src/wayland/fg_gamemode_wl.c
180             src/wayland/fg_init_wl.c
181             src/wayland/fg_internal_wl.h
182             src/wayland/fg_input_devices_wl.c
183             src/wayland/fg_main_wl.c
184             src/wayland/fg_state_wl.c
185             src/wayland/fg_structure_wl.c
186             src/wayland/fg_window_wl.c
187             # font, serial port & joystick code are agnostic
188             src/x11/fg_glutfont_definitions_x11.c
189             src/x11/fg_input_devices_x11.c
190             src/x11/fg_joystick_x11.c
191         )
192     # UNIX (X11)
193     ELSE()
194         LIST(APPEND FREEGLUT_SRCS
195             src/x11/fg_cursor_x11.c
196             src/x11/fg_ext_x11.c
197             src/x11/fg_gamemode_x11.c
198             src/x11/fg_glutfont_definitions_x11.c
199             src/x11/fg_init_x11.c
200             src/x11/fg_internal_x11.h
201             src/x11/fg_input_devices_x11.c
202             src/x11/fg_joystick_x11.c
203             src/x11/fg_main_x11.c
204             src/x11/fg_menu_x11.c
205             src/x11/fg_spaceball_x11.c
206             src/x11/fg_state_x11.c
207             src/x11/fg_structure_x11.c
208             src/x11/fg_window_x11.c
209             src/x11/fg_xinput_x11.c
210         )
211         IF(NOT(FREEGLUT_GLES))
212             LIST(APPEND FREEGLUT_SRCS
213                 src/x11/fg_internal_x11_glx.h
214                 src/x11/fg_display_x11_glx.c
215                 src/x11/fg_state_x11_glx.c
216                 src/x11/fg_state_x11_glx.h
217                 src/x11/fg_window_x11_glx.c
218                 src/x11/fg_window_x11_glx.h
219             )
220         ENDIF()
221     ENDIF()
222 ENDIF()
223
224 # OpenGL ES requires EGL, and so does Wayland
225 IF(FREEGLUT_GLES OR FREEGLUT_WAYLAND)
226     LIST(APPEND FREEGLUT_SRCS
227         src/egl/fg_internal_egl.h
228         src/egl/fg_display_egl.c
229         src/egl/fg_ext_egl.c
230         src/egl/fg_init_egl.c
231         src/egl/fg_init_egl.h
232         src/egl/fg_state_egl.c
233         src/egl/fg_state_egl.h
234         src/egl/fg_structure_egl.c
235         src/egl/fg_structure_egl.h
236         src/egl/fg_window_egl.c
237         src/egl/fg_window_egl.h
238     )
239 ENDIF()
240
241 # For OpenGL ES (GLES): compile with -DFREEGLUT_GLES to cleanly
242 # bootstrap headers inclusion in freeglut_std.h; this constant also
243 # need to be defined in client applications (e.g. through pkg-config),
244 # but do use GLES constants directly for all other needs
245 # GLES1 and GLES2 libraries are compatible and can be co-linked.
246 IF(FREEGLUT_GLES)
247   ADD_DEFINITIONS(-DFREEGLUT_GLES)
248   LIST(APPEND LIBS GLESv2 GLESv1_CM EGL)
249 ELSE()
250   FIND_PACKAGE(OpenGL REQUIRED)
251   LIST(APPEND LIBS ${OPENGL_gl_LIBRARY})
252   INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
253 ENDIF()
254
255 # For Wayland: compile with -DFREEGLUT_WAYLAND and pull EGL
256 IF(FREEGLUT_WAYLAND)
257   ADD_DEFINITIONS(-DFREEGLUT_WAYLAND)
258   LIST(APPEND LIBS wayland-client wayland-cursor wayland-egl EGL xkbcommon)
259 ENDIF()
260
261 # lib m for math, not needed on windows
262 IF (NOT WIN32)
263     # For compilation:
264     LIST(APPEND LIBS m)
265     # For CHECK_FUNCTION_EXISTS:
266     LIST(APPEND CMAKE_REQUIRED_LIBRARIES m)
267 ENDIF()
268
269 IF(WIN32)
270     # hide insecure CRT warnings, common practice
271     ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
272     IF(MSVC)
273         SET( CMAKE_DEBUG_POSTFIX "d" )
274     ENDIF(MSVC)
275     
276     # enable the use of Win2000 APIs (needed for really old compilers like MSVC6)
277     ADD_DEFINITIONS(-D_WIN32_WINNT=0x0500)
278     ADD_DEFINITIONS(-DWINVER=0x0500)
279 ENDIF()
280
281 IF(CMAKE_COMPILER_IS_GNUCC)
282   SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
283   IF(NOT(ANDROID OR BLACKBERRY OR FREEGLUT_WAYLAND))
284     # not setting -ansi as EGL/KHR headers doesn't support it
285     SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic")
286   ENDIF()
287 ENDIF(CMAKE_COMPILER_IS_GNUCC)
288
289 INCLUDE(CheckIncludeFiles)
290 IF(UNIX AND NOT(ANDROID OR BLACKBERRY OR FREEGLUT_WAYLAND))
291     FIND_PACKAGE(X11 REQUIRED)
292     INCLUDE_DIRECTORIES(${X11_INCLUDE_DIR})
293     LIST(APPEND LIBS ${X11_LIBRARIES})
294     IF(X11_Xrandr_FOUND)
295         SET(HAVE_X11_EXTENSIONS_XRANDR_H TRUE)
296         LIST(APPEND LIBS ${X11_Xrandr_LIB})
297     ENDIF()
298     IF(X11_xf86vmode_FOUND)
299         SET(HAVE_X11_EXTENSIONS_XF86VMODE_H TRUE)
300         LIST(APPEND LIBS ${X11_Xxf86vm_LIB})
301     ENDIF()
302     IF(X11_Xinput_FOUND)
303         # Needed for multi-touch:
304         CHECK_INCLUDE_FILES("${X11_Xinput_INCLUDE_PATH}/X11/extensions/XInput2.h" HAVE_X11_EXTENSIONS_XINPUT2_H)
305         LIST(APPEND LIBS ${X11_Xinput_LIB})
306     ENDIF()
307 ENDIF()
308 IF(ANDROID)
309     # -landroid for ANativeWindow
310     # -llog for native Android logging
311     LIST(APPEND LIBS android log)
312 ELSEIF(BLACKBERRY)
313     # -lbps for event loop
314     # -screen for native screen
315     LIST(APPEND LIBS bps screen)
316
317     if(NOT PLAYBOOK)
318         # -lslog2 for logging
319         # -pps for low-level screen manipulation
320         LIST(APPEND LIBS slog2 pps)
321     ENDIF()
322 ENDIF()
323
324 INCLUDE(CheckFunctionExists)
325 INCLUDE(CheckTypeSize)
326 CHECK_INCLUDE_FILES(sys/types.h HAVE_SYS_TYPES_H)
327 CHECK_INCLUDE_FILES(unistd.h    HAVE_UNISTD_H)
328 CHECK_INCLUDE_FILES(sys/time.h  HAVE_SYS_TIME_H)
329 CHECK_INCLUDE_FILES(stdbool.h   HAVE_STDBOOL_H)
330 CHECK_INCLUDE_FILES(sys/param.h HAVE_SYS_PARAM_H)
331 CHECK_INCLUDE_FILES(sys/ioctl.h HAVE_SYS_IOCTL_H)
332 CHECK_INCLUDE_FILES(fcntl.h     HAVE_FCNTL_H)
333 CHECK_INCLUDE_FILES(usbhid.h    HAVE_USBHID_H)
334 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
335 CHECK_FUNCTION_EXISTS(XParseGeometry   HAVE_XPARSEGEOMETRY)
336 IF (NOT HAVE_XPARSEGEOMETRY)
337    LIST(APPEND FREEGLUT_SRCS
338         src/util/xparsegeometry_repl.c
339         src/util/xparsegeometry_repl.h)
340    SET(NEED_XPARSEGEOMETRY_IMPL TRUE)
341 ENDIF()
342 # decide on suitable type for internal time keeping, 64-bit if possible
343 CHECK_INCLUDE_FILES(stdint.h    HAVE_STDINT_H)
344 CHECK_INCLUDE_FILES(inttypes.h  HAVE_INTTYPES_H)
345 IF (NOT (HAVE_STDINT_H OR HAVE_INTTYPES_H))
346     IF (MSVC)
347         # Some old Microsoft VC releases don't support unsigned long
348         # long, but all we care about is support for unsigned __int64 on
349         # MSVC, so test for presence of that type
350         CHECK_TYPE_SIZE("unsigned __int64" U__INT64 BUILTIN_TYPES_ONLY)
351     ELSEIF()
352         CHECK_TYPE_SIZE("unsigned long long" ULONG_LONG BUILTIN_TYPES_ONLY)
353     ENDIF()
354 ENDIF()
355
356 # The generated config.h is placed in the project's build directory, just to
357 # ensure that all CMake-generated files are kept away from the main source tree.
358 # As a result, the build directory must to be added to the include path list.
359 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_BINARY_DIR}/config.h)
360 INCLUDE_DIRECTORIES(BEFORE ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/src)
361 ADD_DEFINITIONS(-DHAVE_CONFIG_H)
362 IF(WIN32)
363     # we also have to generate freeglut.rc, which contains the version
364     # number
365     CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/freeglut.rc.in ${CMAKE_BINARY_DIR}/freeglut.rc)
366     IF (MSVC AND NOT CMAKE_CL_64)
367         # .def file only for 32bit Windows builds with Visual Studio
368         CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/src/freeglutdll.def.in ${CMAKE_BINARY_DIR}/freeglutdll.def)
369     ENDIF()
370 ENDIF()
371
372 IF(FREEGLUT_BUILD_SHARED_LIBS)
373     ADD_LIBRARY(freeglut SHARED ${FREEGLUT_SRCS})
374 ENDIF()
375 IF(FREEGLUT_BUILD_STATIC_LIBS)
376     ADD_LIBRARY(freeglut_static STATIC ${FREEGLUT_SRCS})
377 ENDIF()
378
379
380 IF(WIN32)
381     LIST(APPEND LIBS winmm)
382     IF(FREEGLUT_BUILD_SHARED_LIBS)
383         SET_TARGET_PROPERTIES(freeglut PROPERTIES COMPILE_FLAGS -DFREEGLUT_EXPORTS)
384     ENDIF()
385     IF(FREEGLUT_BUILD_STATIC_LIBS)
386         SET_TARGET_PROPERTIES(freeglut_static PROPERTIES COMPILE_FLAGS -DFREEGLUT_STATIC)
387         # need to set machine:x64 for linker, at least for VC10, and
388         # doesn't hurt for older compilers:
389         # http://public.kitware.com/Bug/view.php?id=11240#c22768
390         IF (CMAKE_CL_64)
391             SET_TARGET_PROPERTIES(freeglut_static PROPERTIES STATIC_LIBRARY_FLAGS "/machine:x64")
392         ENDIF()
393     ENDIF()
394 ELSE()
395     # on UNIX we need to make sure:
396     # - all shared libraries must have a soname/version, see :
397     #   http://sourceware.org/autobook/autobook/autobook_91.html#SEC91
398     #   http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
399     #   Current: -version-info 12:0:9 -> 3.9.0
400     #   Note: most platforms now prefer the latter major.minor.revision form
401     #   (e.g. FreeBSD, cf. http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8765),
402     #   or special-cased FreeGLUT long ago (e.g. .so.4 on OpenBSD), so
403     #   the lack of support for current:revision:age in CMake should
404     #   not be a problem.
405         # - the output library should be named glut so it'll be linkable with -lglut
406         #   (unless FREEGLUT_REPLACE_GLUT is false).
407     # - the shared library should link to the dependency libraries so that the user
408     #   won't have to link them explicitly (they shouldn't have to know that we depend
409     #   on Xrandr or Xxf86vm)
410     IF(FREEGLUT_GLES)
411                 SET(LIBNAME freeglut-gles)
412     ELSE()
413                 IF(FREEGLUT_REPLACE_GLUT)
414                         SET(LIBNAME glut)
415                 ELSE()
416                         SET(LIBNAME freeglut)
417                 ENDIF()
418         ENDIF()
419
420     IF(FREEGLUT_BUILD_SHARED_LIBS)
421       SET_TARGET_PROPERTIES(freeglut PROPERTIES VERSION ${SO_MAJOR}.${SO_MINOR}.${SO_REV} SOVERSION ${SO_MAJOR} OUTPUT_NAME ${LIBNAME})
422     ENDIF()
423     IF(FREEGLUT_BUILD_STATIC_LIBS)
424       SET_TARGET_PROPERTIES(freeglut_static PROPERTIES OUTPUT_NAME ${LIBNAME})
425     ENDIF()
426     IF(ANDROID)
427         # Not in CMake toolchain file, because the toolchain
428         # file is called several times and generally doesn't
429         # seem to be meant for modifying CFLAGS:
430         # '-mandroid' is not mandatory but doesn't hurt
431         # '-O0 -gstabs+' helps the currently buggy GDB port
432         # Too late to manipulate ENV: SET(ENV{CFLAGS} "$ENV{CFLAGS} -mandroid")
433         # Not using _INIT variables, they seem to be used internally only
434         SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mandroid")
435         SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -gstabs+")
436     ENDIF()
437 ENDIF()
438 IF(FREEGLUT_BUILD_SHARED_LIBS)
439     TARGET_LINK_LIBRARIES(freeglut ${LIBS})
440 ENDIF()
441 IF(FREEGLUT_BUILD_STATIC_LIBS)
442     TARGET_LINK_LIBRARIES(freeglut_static ${LIBS})
443 ENDIF()
444
445 IF(FREEGLUT_BUILD_SHARED_LIBS)
446     INSTALL(TARGETS freeglut
447             RUNTIME DESTINATION bin
448             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
449             ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
450     )
451     IF(INSTALL_PDB)
452         INSTALL(FILES ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Debug/freeglut${CMAKE_DEBUG_POSTFIX}.pdb
453             DESTINATION bin
454                         CONFIGURATIONS Debug)
455     ENDIF()
456 ENDIF()
457 IF(FREEGLUT_BUILD_STATIC_LIBS)
458     INSTALL(TARGETS freeglut_static
459             RUNTIME DESTINATION bin
460             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
461             ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
462     )
463     IF(INSTALL_PDB)
464         INSTALL(FILES ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/Debug/freeglut_static${CMAKE_DEBUG_POSTFIX}.pdb
465             DESTINATION lib
466                         CONFIGURATIONS Debug)
467     ENDIF()
468 ENDIF()
469 INSTALL(FILES ${FREEGLUT_HEADERS} DESTINATION include/GL)
470
471
472
473 # Optionally build demos, on by default.
474 option( FREEGLUT_BUILD_DEMOS "Build FreeGLUT demos." ON )
475
476 SET(DEMO_LIBS ${OPENGL_glu_LIBRARY} ${LIBS})
477 # lib m for math, not needed on windows
478 IF (NOT WIN32)
479     LIST(APPEND DEMO_LIBS m)
480 ENDIF()
481
482 MACRO(ADD_DEMO name)
483     IF( FREEGLUT_BUILD_DEMOS )
484         IF(FREEGLUT_BUILD_SHARED_LIBS)
485             ADD_EXECUTABLE(${name} ${ARGN})
486             TARGET_LINK_LIBRARIES(${name} ${DEMO_LIBS} freeglut)
487             IF(WIN32 AND MSVC)
488                 SET_TARGET_PROPERTIES(${name} PROPERTIES DEBUG_POSTFIX d)
489             ENDIF()
490         ENDIF()
491         IF(FREEGLUT_BUILD_STATIC_LIBS)
492             ADD_EXECUTABLE(${name}_static ${ARGN})
493             TARGET_LINK_LIBRARIES(${name}_static ${DEMO_LIBS} freeglut_static)
494             SET_TARGET_PROPERTIES(${name}_static PROPERTIES COMPILE_FLAGS -DFREEGLUT_STATIC)
495             IF(WIN32 AND MSVC)
496                 SET_TARGET_PROPERTIES(${name}_static PROPERTIES DEBUG_POSTFIX d)
497             ENDIF()
498         ENDIF()
499     ENDIF()
500 ENDMACRO()
501
502 ADD_DEMO(CallbackMaker   progs/demos/CallbackMaker/CallbackMaker.c)
503 ADD_DEMO(Fractals        progs/demos/Fractals/fractals.c)
504 ADD_DEMO(Fractals_random progs/demos/Fractals_random/fractals_random.c)
505 ADD_DEMO(Lorenz          progs/demos/Lorenz/lorenz.c)
506 IF (NOT WIN32)
507     ADD_DEMO(One             progs/demos/One/one.c)
508 ELSE()
509     ADD_DEMO(One             progs/demos/One/one.c
510                              progs/demos/One/one.rc)
511 ENDIF()
512 ADD_DEMO(Resizer         progs/demos/Resizer/Resizer.cpp)
513 ADD_DEMO(multi-touch     progs/demos/multi-touch/multi-touch.c)
514 ADD_DEMO(shapes          progs/demos/shapes/shapes.c
515                          progs/demos/shapes/glmatrix.h
516                          progs/demos/shapes/glmatrix.c)
517 ADD_DEMO(smooth_opengl3  progs/demos/smooth_opengl3/smooth_opengl3.c)
518 IF(UNIX)
519     ADD_DEMO(spaceball       progs/demos/spaceball/spaceball.c
520                              progs/demos/spaceball/vmath.c
521                              progs/demos/spaceball/vmath.h)
522 ENDIF()
523 ADD_DEMO(subwin          progs/demos/subwin/subwin.c)
524 ADD_DEMO(timer           progs/demos/timer/timer.c)
525
526
527
528 # pkg-config support, to install at $(libdir)/pkgconfig
529 # Define static build dependencies
530 IF(WIN32)
531   SET(PC_LIBS_PRIVATE "-lopengl32 -lwinmm -lgdi32 -lm")
532 ELSEIF(FREEGLUT_GLES)
533   IF(ANDROID)
534     SET(PC_LIBS_PRIVATE "-llog -landroid -lGLESv2 -lGLESv1_CM -lEGL -lm")
535   ELSEIF(BLACKBERRY)
536     IF(PLAYBOOK)
537       SET(PC_LIBS_PRIVATE "-lbps -lscreen -lGLESv2 -lGLESv1_CM -lEGL -lm")
538     ELSE()
539       SET(PC_LIBS_PRIVATE "-lbps -lslog2 -lscreen -lGLESv2 -lGLESv1_CM -lEGL -lm")
540     ENDIF()
541   ELSEIF(FREEGLUT_WAYLAND)
542     SET(PC_LIBS_PRIVATE "-lwayland-client -lwayland-cursor -lwayland-egl -lGLESv2 -lGLESv1_CM -lEGL -lxkbcommon -lm")
543   ELSE()
544     SET(PC_LIBS_PRIVATE "-lX11 -lXxf86vm -lXrandr -lGLESv2 -lGLESv1_CM -lEGL -lm")
545   ENDIF()
546 ELSE()
547   IF(FREEGLUT_WAYLAND)
548     SET(PC_LIBS_PRIVATE "-lwayland-client -lwayland-cursor -lwayland-egl -lGL -lxkbcommon -lm")
549   ELSE()
550     SET(PC_LIBS_PRIVATE "-lX11 -lXxf86vm -lXrandr -lGL -lm")
551   ENDIF()
552 ENDIF()
553 # Client applications need to define FreeGLUT GLES version to
554 # bootstrap headers inclusion in freeglut_std.h:
555 SET(PC_LIBNAME "glut")
556 SET(PC_FILENAME "freeglut.pc")
557 IF(FREEGLUT_GLES)
558   SET(PC_CFLAGS "-DFREEGLUT_GLES")
559   SET(PC_LIBNAME "freeglut-gles")
560   SET(PC_FILENAME "freeglut-gles.pc")
561 ENDIF()
562 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/freeglut.pc.in ${CMAKE_BINARY_DIR}/freeglut.pc @ONLY)
563 INSTALL(FILES ${CMAKE_BINARY_DIR}/freeglut.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig/ RENAME ${PC_FILENAME})
564 # TODO: change the library and .pc name when building for GLES,
565 # e.g. -lglut-GLES