9d9600ae1aa95b80bb75e1c614938f8a3250a52f
[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 # XXX: Update these for each release!
20 set(VERSION_MAJOR 3)
21 set(VERSION_MINOR 2)
22 set(VERSION_PATCH 2)
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 (XXX: change before release)
29 set(SO_MAJOR 3)         # increment on backwards incompatible API/ABI changes
30 set(SO_MINOR 11)        # increment on backwards compatible API additions
31 set(SO_REV 1)           # increment if only internal changes happened between releases
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 INCLUDE(CheckCCompilerFlag)
356 CHECK_INCLUDE_FILES(sys/types.h HAVE_SYS_TYPES_H)
357 CHECK_INCLUDE_FILES(unistd.h    HAVE_UNISTD_H)
358 CHECK_INCLUDE_FILES(sys/time.h  HAVE_SYS_TIME_H)
359 CHECK_INCLUDE_FILES(stdbool.h   HAVE_STDBOOL_H)
360 CHECK_INCLUDE_FILES(sys/param.h HAVE_SYS_PARAM_H)
361 CHECK_INCLUDE_FILES(sys/ioctl.h HAVE_SYS_IOCTL_H)
362 CHECK_INCLUDE_FILES(fcntl.h     HAVE_FCNTL_H)
363 CHECK_INCLUDE_FILES(usbhid.h    HAVE_USBHID_H)
364 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
365 CHECK_FUNCTION_EXISTS(XParseGeometry   HAVE_XPARSEGEOMETRY)
366 IF (NOT HAVE_XPARSEGEOMETRY)
367    LIST(APPEND FREEGLUT_SRCS
368         src/util/xparsegeometry_repl.c
369         src/util/xparsegeometry_repl.h)
370    SET(NEED_XPARSEGEOMETRY_IMPL TRUE)
371 ENDIF()
372 # decide on suitable type for internal time keeping, 64-bit if possible
373 CHECK_INCLUDE_FILES(stdint.h    HAVE_STDINT_H)
374 CHECK_INCLUDE_FILES(inttypes.h  HAVE_INTTYPES_H)
375 IF (NOT (HAVE_STDINT_H OR HAVE_INTTYPES_H))
376     IF (MSVC)
377         # Some old Microsoft VC releases don't support unsigned long
378         # long, but all we care about is support for unsigned __int64 on
379         # MSVC, so test for presence of that type
380         CHECK_TYPE_SIZE("unsigned __int64" U__INT64 BUILTIN_TYPES_ONLY)
381     ELSEIF()
382         CHECK_TYPE_SIZE("unsigned long long" ULONG_LONG BUILTIN_TYPES_ONLY)
383     ENDIF()
384 ENDIF()
385
386 # The generated config.h is placed in the project's build directory, just to
387 # ensure that all CMake-generated files are kept away from the main source tree.
388 # As a result, the build directory must to be added to the include path list.
389 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_BINARY_DIR}/config.h)
390 INCLUDE_DIRECTORIES(BEFORE ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/src)
391 ADD_DEFINITIONS(-DHAVE_CONFIG_H)
392 IF(WIN32)
393     # we also have to generate freeglut.rc, which contains the version
394     # number
395     CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/freeglut.rc.in ${CMAKE_BINARY_DIR}/freeglut.rc)
396     IF (MSVC AND NOT CMAKE_CL_64)
397         # .def file only for 32bit Windows builds with Visual Studio
398         CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/src/freeglutdll.def.in ${CMAKE_BINARY_DIR}/freeglutdll.def)
399     ENDIF()
400 ENDIF()
401
402 IF(FREEGLUT_BUILD_SHARED_LIBS)
403     ADD_LIBRARY(freeglut SHARED ${FREEGLUT_SRCS})
404 ENDIF()
405 IF(FREEGLUT_BUILD_STATIC_LIBS)
406     ADD_LIBRARY(freeglut_static STATIC ${FREEGLUT_SRCS})
407 ENDIF()
408
409
410 SET(LIBNAME freeglut)
411 IF(WIN32)
412     IF(FREEGLUT_REPLACE_GLUT)
413         SET(LIBNAME glut)
414     ENDIF()
415
416     LIST(APPEND LIBS winmm)
417     IF(FREEGLUT_BUILD_SHARED_LIBS)
418         TARGET_COMPILE_DEFINITIONS(freeglut PRIVATE FREEGLUT_EXPORTS)
419         SET_TARGET_PROPERTIES(freeglut PROPERTIES OUTPUT_NAME ${LIBNAME})
420     ENDIF()
421     IF(FREEGLUT_BUILD_STATIC_LIBS)
422         TARGET_COMPILE_DEFINITIONS(freeglut_static PUBLIC FREEGLUT_STATIC)
423         IF(FREEGLUT_REPLACE_GLUT)
424             SET_TARGET_PROPERTIES(freeglut_static PROPERTIES OUTPUT_NAME ${LIBNAME})
425         ENDIF()
426         # need to set machine:x64 for linker, at least for VC10, and
427         # doesn't hurt for older compilers:
428         # http://public.kitware.com/Bug/view.php?id=11240#c22768
429         IF (CMAKE_CL_64)
430             SET_TARGET_PROPERTIES(freeglut_static PROPERTIES STATIC_LIBRARY_FLAGS "/machine:x64")
431         ENDIF()
432     ENDIF()
433 ELSE()
434     # on UNIX we need to make sure:
435     # - all shared libraries must have a soname/version, see :
436     #   http://sourceware.org/autobook/autobook/autobook_91.html#SEC91
437     #   http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
438     #   Current: -version-info 12:0:9 -> 3.9.0
439     #   Note: most platforms now prefer the latter major.minor.revision form
440     #   (e.g. FreeBSD, cf. http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8765),
441     #   or special-cased FreeGLUT long ago (e.g. .so.4 on OpenBSD), so
442     #   the lack of support for current:revision:age in CMake should
443     #   not be a problem.
444     # - the output library should be named glut so it'll be linkable with -lglut
445     #   (unless FREEGLUT_REPLACE_GLUT is false).
446     # - the shared library should link to the dependency libraries so that the user
447     #   won't have to link them explicitly (they shouldn't have to know that we depend
448     #   on Xrandr or Xxf86vm)
449     IF(FREEGLUT_GLES)
450         SET(LIBNAME freeglut-gles)
451     ELSE()
452         IF(FREEGLUT_REPLACE_GLUT)
453             SET(LIBNAME glut)
454         ENDIF()
455     ENDIF()
456
457     IF(FREEGLUT_BUILD_SHARED_LIBS)
458       SET_TARGET_PROPERTIES(freeglut PROPERTIES VERSION ${SO_MAJOR}.${SO_MINOR}.${SO_REV} SOVERSION ${SO_MAJOR} OUTPUT_NAME ${LIBNAME})
459     ENDIF()
460     IF(FREEGLUT_BUILD_STATIC_LIBS)
461       SET_TARGET_PROPERTIES(freeglut_static PROPERTIES OUTPUT_NAME ${LIBNAME})
462     ENDIF()
463     IF(ANDROID)
464         # Not in CMake toolchain file, because the toolchain
465         # file is called several times and generally doesn't
466         # seem to be meant for modifying CFLAGS:
467         # '-mandroid' is not mandatory but doesn't hurt
468         # '-O0 -gstabs+' helps the currently buggy GDB port
469         # Too late to manipulate ENV: SET(ENV{CFLAGS} "$ENV{CFLAGS} -mandroid")
470         # Not using _INIT variables, they seem to be used internally only
471         IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
472             SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mandroid")
473         ENDIF()
474         CHECK_C_COMPILER_FLAG(-O0 HAVE_O0_FLAG)
475         IF(HAVE_O0_FLAG)
476             SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
477         ENDIF()
478         CHECK_C_COMPILER_FLAG(-gstabs+ HAVE_GSTABSP_FLAG)
479         IF(HAVE_gstabsp_FLAG)
480             SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -gstabs+")
481         ENDIF()
482     ENDIF()
483 ENDIF()
484 IF(FREEGLUT_BUILD_SHARED_LIBS)
485     TARGET_LINK_LIBRARIES(freeglut ${LIBS})
486     TARGET_COMPILE_DEFINITIONS(freeglut PUBLIC ${PUBLIC_DEFINITIONS})
487 ENDIF()
488 IF(FREEGLUT_BUILD_STATIC_LIBS)
489     TARGET_LINK_LIBRARIES(freeglut_static ${LIBS})
490     TARGET_COMPILE_DEFINITIONS(freeglut_static PUBLIC ${PUBLIC_DEFINITIONS})
491 ENDIF()
492
493 IF(FREEGLUT_BUILD_SHARED_LIBS)
494     INSTALL(TARGETS freeglut EXPORT FreeGLUTTargets
495             RUNTIME DESTINATION bin
496             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
497             ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
498             INCLUDES DESTINATION include
499     )
500     IF(INSTALL_PDB)
501         IF(CMAKE_GENERATOR MATCHES "^Visual Studio")
502             INSTALL(FILES ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Debug/freeglut${CMAKE_DEBUG_POSTFIX}.pdb
503                 DESTINATION bin
504                 CONFIGURATIONS Debug
505                 COMPONENT Devel)
506         ELSE()
507             INSTALL(FILES ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/freeglut${CMAKE_DEBUG_POSTFIX}.pdb
508                 DESTINATION bin
509                 CONFIGURATIONS Debug
510                 COMPONENT Devel)
511         ENDIF()
512     ENDIF()
513 ENDIF()
514 IF(FREEGLUT_BUILD_STATIC_LIBS)
515     INSTALL(TARGETS freeglut_static EXPORT FreeGLUTTargets
516             RUNTIME DESTINATION bin
517             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
518             ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
519             INCLUDES DESTINATION include
520     )
521 ENDIF()
522 INSTALL(FILES ${FREEGLUT_HEADERS} DESTINATION include/GL COMPONENT Devel)
523
524
525
526 # Optionally build demos, on by default.
527 option( FREEGLUT_BUILD_DEMOS "Build FreeGLUT demos." ON )
528
529 SET(DEMO_LIBS ${OPENGL_glu_LIBRARY} ${LIBS})
530 # lib m for math, not needed on windows
531 IF (NOT WIN32)
532     LIST(APPEND DEMO_LIBS m)
533 ENDIF()
534
535 MACRO(ADD_DEMO name)
536     IF( FREEGLUT_BUILD_DEMOS )
537         IF(FREEGLUT_BUILD_SHARED_LIBS)
538             ADD_EXECUTABLE(${name} ${ARGN})
539             TARGET_LINK_LIBRARIES(${name} ${DEMO_LIBS} freeglut)
540             IF(WIN32 AND MSVC)
541                 SET_TARGET_PROPERTIES(${name} PROPERTIES DEBUG_POSTFIX d)
542             ENDIF()
543         ENDIF()
544         IF(FREEGLUT_BUILD_STATIC_LIBS)
545             ADD_EXECUTABLE(${name}_static ${ARGN})
546             TARGET_LINK_LIBRARIES(${name}_static ${DEMO_LIBS} freeglut_static)
547             IF(WIN32 AND MSVC)
548                 SET_TARGET_PROPERTIES(${name}_static PROPERTIES DEBUG_POSTFIX d)
549             ENDIF()
550         ENDIF()
551     ENDIF()
552 ENDMACRO()
553
554 ADD_DEMO(CallbackMaker   progs/demos/CallbackMaker/CallbackMaker.c)
555 ADD_DEMO(Fractals        progs/demos/Fractals/fractals.c)
556 ADD_DEMO(Fractals_random progs/demos/Fractals_random/fractals_random.c)
557 ADD_DEMO(Lorenz          progs/demos/Lorenz/lorenz.c)
558 IF (NOT WIN32)
559     ADD_DEMO(One             progs/demos/One/one.c)
560 ELSE()
561     ADD_DEMO(One             progs/demos/One/one.c
562                              progs/demos/One/one.rc)
563 ENDIF()
564 ADD_DEMO(Resizer         progs/demos/Resizer/Resizer.cpp)
565 ADD_DEMO(multi-touch     progs/demos/multi-touch/multi-touch.c)
566 ADD_DEMO(shapes          progs/demos/shapes/shapes.c
567                          progs/demos/shapes/glmatrix.h
568                          progs/demos/shapes/glmatrix.c)
569 ADD_DEMO(smooth_opengl3  progs/demos/smooth_opengl3/smooth_opengl3.c)
570 ADD_DEMO(spaceball       progs/demos/spaceball/spaceball.c
571                          progs/demos/spaceball/vmath.c
572                          progs/demos/spaceball/vmath.h)
573 ADD_DEMO(subwin          progs/demos/subwin/subwin.c)
574 ADD_DEMO(timer           progs/demos/timer/timer.c)
575 ADD_DEMO(timer_callback  progs/demos/timer_callback/timer.c)
576 ADD_DEMO(keyboard        progs/demos/keyboard/keyboard.c)
577
578
579
580 # pkg-config support, to install at $(libdir)/pkgconfig
581 # Define static build dependencies
582 IF(WIN32)
583   SET(PC_LIBS_PRIVATE "-lopengl32 -lwinmm -lgdi32 -lm")
584 ELSEIF(FREEGLUT_GLES)
585   IF(ANDROID)
586     SET(PC_LIBS_PRIVATE "-llog -landroid -lGLESv2 -lGLESv1_CM -lEGL -lm")
587   ELSEIF(BLACKBERRY)
588     IF(PLAYBOOK)
589       SET(PC_LIBS_PRIVATE "-lbps -lscreen -lGLESv2 -lGLESv1_CM -lEGL -lm")
590     ELSE()
591       SET(PC_LIBS_PRIVATE "-lbps -lslog2 -lscreen -lGLESv2 -lGLESv1_CM -lEGL -lm")
592     ENDIF()
593   ELSEIF(FREEGLUT_WAYLAND)
594     SET(PC_LIBS_PRIVATE "-lwayland-client -lwayland-cursor -lwayland-egl -lGLESv2 -lGLESv1_CM -lEGL -lxkbcommon -lm")
595   ELSE()
596     SET(PC_LIBS_PRIVATE "-lX11 -lXxf86vm -lXrandr -lGLESv2 -lGLESv1_CM -lEGL -lm")
597   ENDIF()
598 ELSE()
599   IF(FREEGLUT_WAYLAND)
600     SET(PC_LIBS_PRIVATE "-lwayland-client -lwayland-cursor -lwayland-egl -lGL -lxkbcommon -lm")
601   ELSE()
602     SET(PC_LIBS_PRIVATE "-lX11 -lXxf86vm -lXrandr -lGL -lm")
603   ENDIF()
604 ENDIF()
605 # Client applications need to define FreeGLUT GLES version to
606 # bootstrap headers inclusion in freeglut_std.h:
607 SET(PC_LIBNAME ${LIBNAME})
608 SET(PC_FILENAME "${LIBNAME}.pc")
609 IF(FREEGLUT_GLES)
610   SET(PC_CFLAGS "-DFREEGLUT_GLES")
611 ENDIF()
612 IF(FREEGLUT_BUILD_STATIC_LIBS)
613   LIST(APPEND PC_CFLAGS -DFREEGLUT_STATIC)
614 ENDIF()
615 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/freeglut.pc.in ${CMAKE_BINARY_DIR}/freeglut.pc @ONLY)
616 INSTALL(FILES ${CMAKE_BINARY_DIR}/freeglut.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig/ RENAME ${PC_FILENAME} COMPONENT Devel)
617 # TODO: change the library and .pc name when building for GLES,
618 # e.g. -lglut-GLES
619
620 INCLUDE(CMakePackageConfigHelpers)
621 WRITE_BASIC_PACKAGE_VERSION_FILE(
622     "${CMAKE_CURRENT_BINARY_DIR}/FreeGLUT/FreeGLUTConfigVersion.cmake"
623     VERSION ${VERSION}
624     COMPATIBILITY AnyNewerVersion
625 )
626
627 # needs cmake 3.0 (as does the "INCLUDES DIRECTORY" argument to install(TARGETS)):
628 EXPORT(EXPORT FreeGLUTTargets
629     FILE "${CMAKE_CURRENT_BINARY_DIR}/FreeGLUT/FreeGLUTTargets.cmake"
630     NAMESPACE FreeGLUT::
631 )
632 CONFIGURE_FILE(FreeGLUTConfig.cmake.in
633     "${CMAKE_CURRENT_BINARY_DIR}/FreeGLUT/FreeGLUTConfig.cmake"
634     @ONLY
635 )
636 SET(ConfigPackageLocation ${CMAKE_INSTALL_LIBDIR}/cmake/FreeGLUT)
637 INSTALL(EXPORT FreeGLUTTargets
638     FILE FreeGLUTTargets.cmake
639     NAMESPACE FreeGLUT::
640     DESTINATION ${ConfigPackageLocation}
641 )
642 INSTALL(
643     FILES
644     "${CMAKE_CURRENT_BINARY_DIR}/FreeGLUT/FreeGLUTConfig.cmake"
645     "${CMAKE_CURRENT_BINARY_DIR}/FreeGLUT/FreeGLUTConfigVersion.cmake"
646     DESTINATION ${ConfigPackageLocation}
647     COMPONENT Devel
648 )