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