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