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