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