1 CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
4 # NOTE: On Windows and Cygwin, the dll's are placed in the
5 # CMAKE_RUNTIME_OUTPUT_DIRECTORY, while their corresponding import
6 # libraries end up in CMAKE_ARCHIVE_OUTPUT_DIRECTORY. On other
7 # platforms, such as Linux, the shared libraries are put in
8 # CMAKE_ARCHIVE_OUTPUT_DIRECTORY instead.
9 # Static libraries end up in CMAKE_ARCHIVE_OUTPUT_DIRECTORY on all
11 SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
12 SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
13 SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
15 # setup version numbers
16 # TODO: Update these for each release!
22 # FREEGLUT_BUILD_SHARED_LIBS is already a standard CMake variable, but we need to
23 # re-declare it here so it will show up in the GUI.
24 # by default, we want to build both
25 OPTION(FREEGLUT_BUILD_SHARED_LIBS "Build FreeGLUT shared library." ON)
26 OPTION(FREEGLUT_BUILD_STATIC_LIBS "Build FreeGLUT static library." ON)
28 # option for whether warnings and errors should be printed
29 OPTION(FREEGLUT_PRINT_ERRORS "Lib prints errors to stderr" ON)
30 #MARK_AS_ADVANCED(FREEGLUT_PRINT_ERRORS)
31 OPTION(FREEGLUT_PRINT_WARNINGS "Lib prints warnings to stderr" ON)
32 #MARK_AS_ADVANCED(FREEGLUT_PRINT_WARNINGS)
34 # option to also copy .pdb files to install directory when executing
37 OPTION(INSTALL_PDB "Also install .pdb files" ON)
43 OPTION(FREEGLUT_GLES1 "Use OpenGL ES 1.x (requires EGL)" OFF)
44 OPTION(FREEGLUT_GLES2 "Use OpenGL ES 2.x (requires EGL) (overrides BUILD_GLES1)" OFF)
50 include/GL/freeglut_ext.h
51 include/GL/freeglut_std.h
68 src/fg_input_devices.c
75 src/fg_stroke_mono_roman.c
83 # TODO: OpenGL ES requires a compatible version of these files:
84 IF(NOT FREEGLUT_GLES2 AND NOT FREEGLUT_GLES1)
85 LIST(APPEND FREEGLUT_SRCS
90 LIST(APPEND FREEGLUT_SRCS
96 LIST(APPEND FREEGLUT_SRCS
97 src/mswin/fg_cursor_mswin.c
98 src/mswin/fg_display_mswin.c
99 src/mswin/fg_ext_mswin.c
100 src/mswin/fg_gamemode_mswin.c
101 src/mswin/fg_init_mswin.c
102 src/mswin/fg_internal_mswin.h
103 src/mswin/fg_input_devices_mswin.c
104 src/mswin/fg_joystick_mswin.c
105 src/mswin/fg_main_mswin.c
106 src/mswin/fg_menu_mswin.c
107 src/mswin/fg_spaceball_mswin.c
108 src/mswin/fg_state_mswin.c
109 src/mswin/fg_structure_mswin.c
110 src/mswin/fg_window_mswin.c
111 ${CMAKE_BINARY_DIR}/freeglut.rc # generated below from freeglut.rc.in
113 IF (MSVC AND NOT CMAKE_CL_64)
114 # .def file only for 32bit Windows builds (TODO: MSVC only right
115 # now, needed for any other Windows platform?)
116 LIST(APPEND FREEGLUT_SRCS
117 ${CMAKE_BINARY_DIR}/freeglutdll.def # generated below from src/freeglutdll.def.in
121 ELSEIF(ANDROID OR BLACKBERRY)
122 LIST(APPEND FREEGLUT_SRCS
123 src/android/fg_cursor_android.c
124 src/android/fg_ext_android.c
125 src/android/fg_gamemode_android.c
126 src/android/fg_joystick_android.c
127 src/android/fg_spaceball_android.c
128 src/android/fg_structure_android.c
131 LIST(APPEND FREEGLUT_SRCS
132 src/android/native_app_glue/android_native_app_glue.c
133 src/android/native_app_glue/android_native_app_glue.h
134 src/android/fg_init_android.c
135 src/android/fg_internal_android.h
136 src/android/fg_input_devices_android.c
137 src/android/fg_main_android.c
138 src/android/fg_main_android.h
139 src/android/fg_runtime_android.c
140 src/android/fg_state_android.c
141 src/android/fg_window_android.c
144 LIST(APPEND FREEGLUT_SRCS
145 src/blackberry/fg_init_blackberry.c
146 src/blackberry/fg_internal_blackberry.h
147 src/x11/fg_input_devices_x11.c
148 src/blackberry/fg_main_blackberry.c
149 src/blackberry/fg_main_blackberry.h
150 src/blackberry/fg_state_blackberry.c
151 src/blackberry/fg_window_blackberry.c
155 LIST(APPEND FREEGLUT_SRCS
156 src/x11/fg_cursor_x11.c
158 src/x11/fg_gamemode_x11.c
159 src/x11/fg_glutfont_definitions_x11.c
160 src/x11/fg_init_x11.c
161 src/x11/fg_internal_x11.h
162 src/x11/fg_input_devices_x11.c
163 src/x11/fg_joystick_x11.c
164 src/x11/fg_main_x11.c
165 src/x11/fg_menu_x11.c
166 src/x11/fg_spaceball_x11.c
167 src/x11/fg_state_x11.c
168 src/x11/fg_structure_x11.c
169 src/x11/fg_window_x11.c
170 src/x11/fg_xinput_x11.c
172 IF(NOT(FREEGLUT_GLES2 OR FREEGLUT_GLES1))
173 LIST(APPEND FREEGLUT_SRCS
174 src/x11/fg_internal_x11_glx.h
175 src/x11/fg_display_x11_glx.c
176 src/x11/fg_state_x11_glx.c
177 src/x11/fg_state_x11_glx.h
178 src/x11/fg_window_x11_glx.c
179 src/x11/fg_window_x11_glx.h
183 IF(FREEGLUT_GLES2 OR FREEGLUT_GLES1)
184 LIST(APPEND FREEGLUT_SRCS
185 src/egl/fg_internal_egl.h
186 src/egl/fg_display_egl.c
188 src/egl/fg_init_egl.c
189 src/egl/fg_init_egl.h
190 src/egl/fg_state_egl.c
191 src/egl/fg_state_egl.h
192 src/egl/fg_structure_egl.c
193 src/egl/fg_structure_egl.h
194 src/egl/fg_window_egl.c
195 src/egl/fg_window_egl.h
199 # For OpenGL ES (GLES):
200 # - compile with -DFREEGLUT_GLES1 and -DFREEGLUT_GLES2 to cleanly
201 # bootstrap headers inclusion in freeglut_std.h; these constants
202 # also need to be defined in client applications (e.g. through
203 # pkg-config), but use GLES constants directly for all other needs
204 # - define GLES version-specific library
206 ADD_DEFINITIONS(-DFREEGLUT_GLES2)
207 LIST(APPEND LIBS GLESv2 EGL)
208 ELSEIF(FREEGLUT_GLES1)
209 ADD_DEFINITIONS(-DFREEGLUT_GLES1)
210 LIST(APPEND LIBS GLESv1_CM EGL)
212 FIND_PACKAGE(OpenGL REQUIRED)
213 LIST(APPEND LIBS ${OPENGL_gl_LIBRARY})
214 INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
217 # lib m for math, not needed on windows
221 # For CHECK_FUNCTION_EXISTS:
222 LIST(APPEND CMAKE_REQUIRED_LIBRARIES m)
226 # hide insecure CRT warnings, common practice
227 ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
229 SET( CMAKE_DEBUG_POSTFIX "d" )
234 IF(CMAKE_COMPILER_IS_GNUCC)
235 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
236 IF(NOT(ANDROID OR BLACKBERRY))
237 # not setting -ansi as EGL/KHR headers doesn't support it
238 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ansi")
240 ENDIF(CMAKE_COMPILER_IS_GNUCC)
242 INCLUDE(CheckIncludeFiles)
243 IF(UNIX AND NOT(ANDROID OR BLACKBERRY))
244 FIND_PACKAGE(X11 REQUIRED)
245 LIST(APPEND LIBS ${X11_LIBRARIES})
247 SET(HAVE_X11_EXTENSIONS_XRANDR_H TRUE)
248 LIST(APPEND LIBS ${X11_Xrandr_LIB})
250 IF(X11_xf86vmode_FOUND)
251 SET(HAVE_X11_EXTENSIONS_XF86VMODE_H TRUE)
252 # Work-around http://www.cmake.org/Bug/bug_view_page.php?bug_id=6976
253 IF(NOT "${X11_Xxf86vm_LIB}")
254 SET(X11_Xxf86vm_LIB "Xxf86vm")
256 LIST(APPEND LIBS ${X11_Xxf86vm_LIB})
259 # Needed for multi-touch:
260 CHECK_INCLUDE_FILES("${X11_Xinput_INCLUDE_PATH}/X11/extensions/XInput2.h" HAVE_X11_EXTENSIONS_XINPUT2_H)
261 LIST(APPEND LIBS ${X11_Xinput_LIB})
265 # -landroid for ANativeWindow
266 # -llog for native Android logging
267 LIST(APPEND LIBS android log)
269 # -lbps for event loop
270 # -lslog2 for logging
271 # -screen for native screen
272 LIST(APPEND LIBS bps slog2 screen)
275 INCLUDE(CheckFunctionExists)
276 INCLUDE(CheckTypeSize)
277 CHECK_INCLUDE_FILES(sys/types.h HAVE_SYS_TYPES_H)
278 CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H)
279 CHECK_INCLUDE_FILES(sys/time.h HAVE_SYS_TIME_H)
280 CHECK_INCLUDE_FILES(stdbool.h HAVE_STDBOOL_H)
281 CHECK_INCLUDE_FILES(sys/param.h HAVE_SYS_PARAM_H)
282 CHECK_INCLUDE_FILES(sys/ioctl.h HAVE_SYS_IOCTL_H)
283 CHECK_INCLUDE_FILES(fcntl.h HAVE_FCNTL_H)
284 CHECK_INCLUDE_FILES(errno.h HAVE_ERRNO_H)
285 CHECK_INCLUDE_FILES(usbhid.h HAVE_USBHID_H)
286 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
287 CHECK_FUNCTION_EXISTS(vfprintf HAVE_VFPRINTF)
288 CHECK_FUNCTION_EXISTS(_doprnt HAVE_DOPRNT)
289 CHECK_FUNCTION_EXISTS(XParseGeometry HAVE_XPARSEGEOMETRY)
290 IF (NOT HAVE_XPARSEGEOMETRY)
291 LIST(APPEND FREEGLUT_SRCS
292 src/util/xparsegeometry_repl.c
293 src/util/xparsegeometry_repl.h)
294 SET(NEED_XPARSEGEOMETRY_IMPL TRUE)
296 # decide on suitable type for internal time keeping, 64-bit if possible
297 CHECK_INCLUDE_FILES(stdint.h HAVE_STDINT_H)
298 CHECK_INCLUDE_FILES(inttypes.h HAVE_INTTYPES_H)
299 IF (NOT (HAVE_STDINT_H OR HAVE_INTTYPES_H))
301 # Some old Microsoft VC releases don't support unsigned long
302 # long, but all we care about is support for unsigned __int64 on
303 # MSVC, so test for presence of that type
304 CHECK_TYPE_SIZE("unsigned __int64" U__INT64 BUILTIN_TYPES_ONLY)
306 CHECK_TYPE_SIZE("unsigned long long" ULONG_LONG BUILTIN_TYPES_ONLY)
310 # The generated config.h is placed in the project's build directory, just to
311 # ensure that all CMake-generated files are kept away from the main source tree.
312 # As a result, the build directory must to be added to the include path list.
313 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_BINARY_DIR}/config.h)
314 INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/src)
315 ADD_DEFINITIONS(-DHAVE_CONFIG_H)
317 # we also have to generate freeglut.rc, which contains the version
319 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/freeglut.rc.in ${CMAKE_BINARY_DIR}/freeglut.rc)
320 IF (MSVC AND NOT CMAKE_CL_64)
321 # .def file only for 32bit Windows builds with Visual Studio
322 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/src/freeglutdll.def.in ${CMAKE_BINARY_DIR}/freeglutdll.def)
326 IF(FREEGLUT_BUILD_SHARED_LIBS)
327 ADD_LIBRARY(freeglut SHARED ${FREEGLUT_SRCS})
329 IF(FREEGLUT_BUILD_STATIC_LIBS)
330 ADD_LIBRARY(freeglut_static STATIC ${FREEGLUT_SRCS})
335 LIST(APPEND LIBS winmm)
336 IF(FREEGLUT_BUILD_SHARED_LIBS)
337 SET_TARGET_PROPERTIES(freeglut PROPERTIES COMPILE_FLAGS -DFREEGLUT_EXPORTS)
339 IF(FREEGLUT_BUILD_STATIC_LIBS)
340 SET_TARGET_PROPERTIES(freeglut_static PROPERTIES COMPILE_FLAGS -DFREEGLUT_STATIC)
341 # need to set machine:x64 for linker, at least for VC10, and
342 # doesn't hurt for older compilers:
343 # http://public.kitware.com/Bug/view.php?id=11240#c22768
345 SET_TARGET_PROPERTIES(freeglut_static PROPERTIES STATIC_LIBRARY_FLAGS "/machine:x64")
349 # on UNIX we need to make sure:
350 # - all shared libraries must have a soname/version, see :
351 # http://sourceware.org/autobook/autobook/autobook_91.html#SEC91
352 # http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
353 # Current: -version-info 12:0:9 -> 3.9.0
354 # Note: most platforms now prefer the latter major.minor.revision form
355 # (e.g. FreeBSD, cf. http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8765),
356 # or special-cased FreeGLUT long ago (e.g. .so.4 on OpenBSD), so
357 # the lack of support for current:revision:age in CMake should
359 # - the output library should be named glut so it'll be linkable with -lglut
360 # - the shared library should link to the dependency libraries so that the user
361 # won't have to link them explicitly (they shouldn't have to know that we depend
362 # on Xrandr or Xxf86vm)
364 SET(LIBNAME freeglut-gles2)
365 ELSEIF(FREEGLUT_GLES1)
366 SET(LIBNAME freeglut-gles1)
371 IF(FREEGLUT_BUILD_SHARED_LIBS)
372 SET_TARGET_PROPERTIES(freeglut PROPERTIES VERSION 3.9.0 SOVERSION 3 OUTPUT_NAME ${LIBNAME})
374 IF(FREEGLUT_BUILD_STATIC_LIBS)
375 SET_TARGET_PROPERTIES(freeglut_static PROPERTIES OUTPUT_NAME ${LIBNAME})
378 # Not in CMake toolchain file, because the toolchain
379 # file is called several times and generally doesn't
380 # seem to be meant for modifying CFLAGS:
381 # '-mandroid' is not mandatory but doesn't hurt
382 # '-O0 -gstabs+' helps the currently buggy GDB port
383 # Too late to manipulate ENV: SET(ENV{CFLAGS} "$ENV{CFLAGS} -mandroid")
384 # Not using _INIT variables, they seem to be used internally only
385 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mandroid")
386 SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -gstabs+")
389 IF(FREEGLUT_BUILD_SHARED_LIBS)
390 TARGET_LINK_LIBRARIES(freeglut ${LIBS})
392 IF(FREEGLUT_BUILD_STATIC_LIBS)
393 TARGET_LINK_LIBRARIES(freeglut_static ${LIBS})
396 IF(FREEGLUT_BUILD_SHARED_LIBS)
397 INSTALL(TARGETS freeglut
398 RUNTIME DESTINATION bin
399 LIBRARY DESTINATION lib
400 ARCHIVE DESTINATION lib
403 INSTALL(FILES ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Debug/freeglut${CMAKE_DEBUG_POSTFIX}.pdb
405 CONFIGURATIONS Debug)
408 IF(FREEGLUT_BUILD_STATIC_LIBS)
409 INSTALL(TARGETS freeglut_static
410 RUNTIME DESTINATION bin
411 LIBRARY DESTINATION lib
412 ARCHIVE DESTINATION lib
415 INSTALL(FILES ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/Debug/freeglut_static${CMAKE_DEBUG_POSTFIX}.pdb
417 CONFIGURATIONS Debug)
420 INSTALL(FILES ${FREEGLUT_HEADERS} DESTINATION include/GL)
424 # Optionally build demos, on by default.
425 option( FREEGLUT_BUILD_DEMOS "Build FreeGLUT demos." ON )
427 SET(DEMO_LIBS ${OPENGL_glu_LIBRARY} ${LIBS})
428 # lib m for math, not needed on windows
430 LIST(APPEND DEMO_LIBS m)
434 IF( FREEGLUT_BUILD_DEMOS )
435 IF(FREEGLUT_BUILD_SHARED_LIBS)
436 ADD_EXECUTABLE(${name} ${ARGN})
437 TARGET_LINK_LIBRARIES(${name} ${DEMO_LIBS} freeglut)
439 SET_TARGET_PROPERTIES(${name} PROPERTIES DEBUG_POSTFIX d)
442 IF(FREEGLUT_BUILD_STATIC_LIBS)
443 ADD_EXECUTABLE(${name}_static ${ARGN})
444 TARGET_LINK_LIBRARIES(${name}_static ${DEMO_LIBS} freeglut_static)
445 SET_TARGET_PROPERTIES(${name}_static PROPERTIES COMPILE_FLAGS -DFREEGLUT_STATIC)
447 SET_TARGET_PROPERTIES(${name}_static PROPERTIES DEBUG_POSTFIX d)
453 ADD_DEMO(CallbackMaker progs/demos/CallbackMaker/CallbackMaker.c)
454 ADD_DEMO(Fractals progs/demos/Fractals/fractals.c)
455 ADD_DEMO(Fractals_random progs/demos/Fractals_random/fractals_random.c)
456 ADD_DEMO(Lorenz progs/demos/Lorenz/lorenz.c)
458 ADD_DEMO(One progs/demos/One/one.c)
460 ADD_DEMO(One progs/demos/One/one.c
461 progs/demos/One/one.rc)
463 ADD_DEMO(Resizer progs/demos/Resizer/Resizer.cpp)
464 ADD_DEMO(multi-touch progs/demos/multi-touch/multi-touch.c)
465 ADD_DEMO(shapes progs/demos/shapes/shapes.c
466 progs/demos/shapes/glmatrix.h
467 progs/demos/shapes/glmatrix.c)
468 ADD_DEMO(smooth_opengl3 progs/demos/smooth_opengl3/smooth_opengl3.c)
470 ADD_DEMO(spaceball progs/demos/spaceball/spaceball.c
471 progs/demos/spaceball/vmath.c
472 progs/demos/spaceball/vmath.h)
474 ADD_DEMO(subwin progs/demos/subwin/subwin.c)
475 ADD_DEMO(timer progs/demos/timer/timer.c)
479 # pkg-config support, to install at $(libdir)/pkgconfig
480 # Define static build dependencies
482 SET(PC_LIBS_PRIVATE "-lopengl32 -lwinmm -lgdi32 -lm")
483 ELSEIF(FREEGLUT_GLES2)
485 SET(PC_LIBS_PRIVATE "-llog -landroid -lGLESv2 -lEGL -lm")
487 SET(PC_LIBS_PRIVATE "-lbps -lslog2 -lscreen -lGLESv2 -lEGL -lm")
489 SET(PC_LIBS_PRIVATE "-lX11 -lXxf86vm -lXrandr -lGLESv2 -lEGL -lm")
491 ELSEIF(FREEGLUT_GLES1)
493 SET(PC_LIBS_PRIVATE "-llog -landroid -lGLESv1_CM -lEGL -lm")
495 SET(PC_LIBS_PRIVATE "-lbps -lslog2 -lscreen -lGLESv1_CM -lEGL -lm")
497 SET(PC_LIBS_PRIVATE "-lX11 -lXxf86vm -lXrandr -lGLESv1_CM -lEGL -lm")
500 SET(PC_LIBS_PRIVATE "-lX11 -lXxf86vm -lXrandr -lGL -lm")
502 # Client applications need to define FreeGLUT GLES version to
503 # bootstrap headers inclusion in freeglut_std.h:
504 SET(PC_LIBNAME "glut")
505 SET(PC_FILENAME "freeglut.pc")
507 SET(PC_CFLAGS "-DFREEGLUT_GLES2")
508 SET(PC_LIBNAME "freeglut-gles2")
509 SET(PC_FILENAME "freeglut-gles2.pc")
510 ELSEIF(FREEGLUT_GLES1)
511 SET(PC_CFLAGS "-DFREEGLUT_GLES1")
512 SET(PC_LIBNAME "freeglut-gles1")
513 SET(PC_FILENAME "freeglut-gles1.pc")
515 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/freeglut.pc.in ${CMAKE_BINARY_DIR}/freeglut.pc @ONLY)
516 INSTALL(FILES ${CMAKE_BINARY_DIR}/freeglut.pc DESTINATION share/pkgconfig/ RENAME ${PC_FILENAME})
517 # TODO: change the library and .pc name when building for GLES,