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