2 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
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_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
14 # setup version numbers
15 # TODO: Update these for each release!
21 # BUILD_SHARED_LIBS is already a standard CMake variable, but we need to
22 # re-declare it here so it will show up in the GUI.
23 # by default, we want to build both
24 OPTION(BUILD_SHARED_LIBS "Build FreeGLUT shared library." ON)
25 OPTION(BUILD_STATIC_LIBS "Build FreeGLUT static library." ON)
28 OPTION(FREEGLUT_GLES1 "Use OpenGL ES 1.x (requires EGL)" OFF)
29 OPTION(FREEGLUT_GLES2 "Use OpenGL ES 2.x (requires EGL) (overrides BUILD_GLES1)" OFF)
34 include/GL/freeglut_ext.h
35 include/GL/freeglut_std.h
50 src/fg_input_devices.c
58 src/fg_stroke_mono_roman.c
64 # TODO: OpenGL ES requires a compatible version of these files:
65 IF(NOT FREEGLUT_GLES2 AND NOT FREEGLUT_GLES1)
66 LIST(APPEND FREEGLUT_SRCS
74 LIST(APPEND FREEGLUT_SRCS
81 LIST(APPEND FREEGLUT_SRCS
82 src/mswin/fg_cursor_mswin.c
83 src/mswin/fg_display_mswin.c
84 src/mswin/fg_ext_mswin.c
85 src/mswin/fg_gamemode_mswin.c
86 src/mswin/fg_init_mswin.c
87 src/mswin/fg_internal_mswin.h
88 src/mswin/fg_input_devices_mswin.c
89 src/mswin/fg_joystick_mswin.c
90 src/mswin/fg_main_mswin.c
91 src/mswin/fg_menu_mswin.c
92 src/mswin/fg_spaceball_mswin.c
93 src/mswin/fg_state_mswin.c
94 src/mswin/fg_structure_mswin.c
95 src/mswin/fg_window_mswin.c
96 ${CMAKE_BINARY_DIR}/freeglut.rc # generated below from freeglut.rc.in
98 IF (MSVC AND NOT CMAKE_CL_64)
99 # .def file only for 32bit Windows builds
100 LIST(APPEND FREEGLUT_SRCS
101 ${CMAKE_BINARY_DIR}/freeglutdll.def # generated below from src/freeglutdll.def.in
106 LIST(APPEND FREEGLUT_SRCS
107 src/android/native_app_glue/android_native_app_glue.c
108 src/android/native_app_glue/android_native_app_glue.h
109 src/android/fg_internal_android.h
110 src/android/fg_cursor_android.c
111 src/android/fg_ext_android.c
112 src/android/fg_gamemode_android.c
113 src/android/fg_init_android.c
114 src/android/fg_input_devices_android.c
115 src/android/fg_joystick_android.c
116 src/android/fg_main_android.c
117 src/android/fg_main_android.h
118 src/android/fg_runtime_android.c
119 src/android/fg_spaceball_android.c
120 src/android/fg_state_android.c
121 src/android/fg_structure_android.c
122 src/android/fg_window_android.c
125 LIST(APPEND FREEGLUT_SRCS
126 src/x11/fg_cursor_x11.c
128 src/x11/fg_gamemode_x11.c
129 src/x11/fg_glutfont_definitions_x11.c
130 src/x11/fg_init_x11.c
131 src/x11/fg_internal_x11.h
132 src/x11/fg_input_devices_x11.c
133 src/x11/fg_joystick_x11.c
134 src/x11/fg_main_x11.c
135 src/x11/fg_menu_x11.c
136 src/x11/fg_spaceball_x11.c
137 src/x11/fg_state_x11.c
138 src/x11/fg_structure_x11.c
139 src/x11/fg_window_x11.c
140 src/x11/fg_xinput_x11.c
142 IF(!(FREEGLUT_GLES2 OR FREEGLUT_GLES1))
143 LIST(APPEND FREEGLUT_SRCS
144 src/x11/fg_internal_x11_glx.h
145 src/x11/fg_display_x11_glx.c
146 src/x11/fg_state_x11_glx.c
147 src/x11/fg_window_x11_glx.c
148 src/x11/fg_window_x11_glx.h
152 IF(FREEGLUT_GLES2 OR FREEGLUT_GLES1)
153 LIST(APPEND FREEGLUT_SRCS
154 src/egl/fg_internal_egl.h
155 src/egl/fg_display_egl.c
157 src/egl/fg_init_egl.c
158 src/egl/fg_init_egl.h
159 src/egl/fg_state_egl.c
160 src/egl/fg_state_egl.h
161 src/egl/fg_structure_egl.c
162 src/egl/fg_structure_egl.h
163 src/egl/fg_window_egl.c
164 src/egl/fg_window_egl.h
168 # For OpenGL ES (GLES):
169 # - compile with -DFREEGLUT_GLES1 and -DFREEGLUT_GLES2 to cleanly
170 # bootstrap headers inclusion in freeglut_std.h; these constants
171 # also need to be defined in client applications (e.g through
172 # pkg-config), but use GLES constants directly for all other needs
173 # - define GLES version-specific library
175 ADD_DEFINITIONS(-DFREEGLUT_GLES2)
176 LIST(APPEND LIBS GLESv2 EGL)
177 ELSEIF(FREEGLUT_GLES1)
178 ADD_DEFINITIONS(-DFREEGLUT_GLES1)
179 LIST(APPEND LIBS GLESv1_CM EGL)
181 FIND_PACKAGE(OpenGL REQUIRED)
182 LIST(APPEND LIBS ${OPENGL_gl_LIBRARY})
183 INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
186 # lib m for math, not needed on windows
192 # hide insecure CRT warnings, common practice
193 ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
196 IF(CMAKE_COMPILER_IS_GNUCC)
197 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pedantic")
199 # not setting -ansi as EGL/KHR headers doesn't support it
200 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ansi")
202 ENDIF(CMAKE_COMPILER_IS_GNUCC)
204 if(UNIX AND NOT ANDROID)
205 FIND_PACKAGE(X11 REQUIRED)
206 LIST(APPEND LIBS ${X11_LIBRARIES})
208 SET(HAVE_X11_EXTENSIONS_XRANDR_H TRUE)
209 LIST(APPEND LIBS ${X11_Xrandr_LIB})
211 IF(X11_xf86vmode_FOUND)
212 SET(HAVE_X11_EXTENSIONS_XF86VMODE_H TRUE)
213 # Work-around http://www.cmake.org/Bug/bug_view_page.php?bug_id=6976
214 IF(NOT "${X11_Xxf86vm_LIB}")
215 SET(X11_Xxf86vm_LIB "Xxf86vm")
217 LIST(APPEND LIBS ${X11_Xxf86vm_LIB})
221 INCLUDE(CheckIncludeFiles)
222 INCLUDE(CheckFunctionExists)
223 INCLUDE(CheckTypeSize)
224 CHECK_INCLUDE_FILES(sys/types.h HAVE_SYS_TYPES_H)
225 CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H)
226 CHECK_INCLUDE_FILES(sys/time.h HAVE_SYS_TIME_H)
227 CHECK_INCLUDE_FILES(stdbool.h HAVE_STDBOOL_H)
228 CHECK_INCLUDE_FILES(sys/param.h HAVE_SYS_PARAM_H)
229 CHECK_INCLUDE_FILES(sys/ioctl.h HAVE_SYS_IOCTL_H)
230 CHECK_INCLUDE_FILES(fcntl.h HAVE_FCNTL_H)
231 CHECK_INCLUDE_FILES(errno.h HAVE_ERRNO_H)
232 CHECK_INCLUDE_FILES(usbhid.h HAVE_USBHID_H)
233 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
234 CHECK_FUNCTION_EXISTS(vfprintf HAVE_VFPRINTF)
235 CHECK_FUNCTION_EXISTS(_doprnt HAVE_DOPRNT)
236 CHECK_FUNCTION_EXISTS(XParseGeometry HAVE_XPARSEGEOMETRY)
237 IF (NOT HAVE_XPARSEGEOMETRY)
238 LIST(APPEND FREEGLUT_SRCS
239 src/util/xparsegeometry_repl.c
240 src/util/xparsegeometry_repl.h)
241 SET(NEED_XPARSEGEOMETRY_IMPL TRUE)
243 # decide on suitable type for internal time keeping, 64-bit if possible
244 CHECK_INCLUDE_FILES(stdint.h HAVE_STDINT_H)
245 CHECK_INCLUDE_FILES(inttypes.h HAVE_INTTYPES_H)
246 IF (NOT (HAVE_STDINT_H OR HAVE_INTTYPES_H))
248 # Some old Microsoft VC don't support unsigned long long, but all we
249 # care about support unsigned __int64, so test for presence of that
251 CHECK_TYPE_SIZE("unsigned __int64" U__INT64 BUILTIN_TYPES_ONLY)
253 CHECK_TYPE_SIZE("unsigned long long" ULONG_LONG BUILTIN_TYPES_ONLY)
258 # The generated config.h is placed in the project's build directory, just to
259 # ensure that all CMake-generated files are kept away from the main source tree.
260 # As a result, the build directory must to be added to the include path list.
261 CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/config.h.in ${CMAKE_BINARY_DIR}/config.h)
262 INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src)
263 ADD_DEFINITIONS(-DHAVE_CONFIG_H)
265 # we also have to generate freeglut.rc, which contains the version
267 CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/freeglut.rc.in ${CMAKE_BINARY_DIR}/freeglut.rc)
268 IF (MSVC AND NOT CMAKE_CL_64)
269 # .def file only for 32bit Windows builds with Visual Studio
270 CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/src/freeglutdll.def.in ${CMAKE_BINARY_DIR}/freeglutdll.def)
274 IF(BUILD_SHARED_LIBS)
275 ADD_LIBRARY(freeglut SHARED ${FREEGLUT_SRCS})
277 IF(BUILD_STATIC_LIBS)
278 ADD_LIBRARY(freeglut_static STATIC ${FREEGLUT_SRCS})
283 LIST(APPEND LIBS winmm)
284 IF(BUILD_SHARED_LIBS)
285 SET_TARGET_PROPERTIES(freeglut PROPERTIES COMPILE_FLAGS -DFREEGLUT_EXPORTS)
287 IF(BUILD_STATIC_LIBS)
288 SET_TARGET_PROPERTIES(freeglut_static PROPERTIES COMPILE_FLAGS -DFREEGLUT_STATIC)
289 # need to set machine:x64 for linker, at least for VC10, and
290 # doesn't hurt for older compilers:
291 # http://public.kitware.com/Bug/view.php?id=11240#c22768
293 SET_TARGET_PROPERTIES(freeglut_static PROPERTIES STATIC_LIBRARY_FLAGS "/machine:x64")
297 # on UNIX we need to make sure:
298 # - all shared libraries must have a soname/version, see :
299 # http://sourceware.org/autobook/autobook/autobook_91.html#SEC91
300 # http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
301 # Current: -version-info 12:0:9 -> 3.9.0
302 # - the output library should be named glut so it'll be linkable with -lglut
303 # - the shared library should link to the dependency libraries so that the user
304 # won't have to link them explicitly (they shouldn't have to know that we depend
305 # on Xrandr or Xxf86vm)
307 SET(LIBNAME freeglut-gles2)
308 ELSEIF(FREEGLUT_GLES1)
309 SET(LIBNAME freeglut-gles1)
314 SET_TARGET_PROPERTIES(freeglut PROPERTIES VERSION 3.9.0 SOVERSION 3 OUTPUT_NAME ${LIBNAME})
315 SET_TARGET_PROPERTIES(freeglut_static PROPERTIES OUTPUT_NAME ${LIBNAME})
317 # Not in CMake toolchain file, because the toolchain
318 # file is called several times and generally doesn't
319 # seem to be meant for modifying CFLAGS:
320 # '-mandroid' is not mandatory but doesn't hurt
321 # '-O0 -gstabs+' helps the currently buggy GDB port
322 # Too late to manipulate ENV: SET(ENV{CFLAGS} "$ENV{CFLAGS} -mandroid")
323 # Not using _INIT variables, they seem to be used internally only
324 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mandroid")
325 SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -gstabs+")
328 IF(BUILD_SHARED_LIBS)
329 TARGET_LINK_LIBRARIES(freeglut ${LIBS})
331 IF(BUILD_STATIC_LIBS)
332 TARGET_LINK_LIBRARIES(freeglut_static ${LIBS})
335 IF(BUILD_SHARED_LIBS)
336 INSTALL(TARGETS freeglut DESTINATION lib)
338 IF(BUILD_STATIC_LIBS)
339 INSTALL(TARGETS freeglut_static DESTINATION lib)
341 INSTALL(FILES ${FREEGLUT_HEADERS} DESTINATION include/GL)
345 # Optionally build demos, on by default.
346 option( FREEGLUT_BUILD_DEMOS "Build FreeGLUT demos." ON )
348 SET(DEMO_LIBS ${OPENGL_glu_LIBRARY} ${LIBS})
349 # lib m for math, not needed on windows
351 LIST(APPEND DEMO_LIBS m)
355 IF( FREEGLUT_BUILD_DEMOS )
356 IF(BUILD_SHARED_LIBS)
357 ADD_EXECUTABLE(${name} ${ARGN})
358 TARGET_LINK_LIBRARIES(${name} ${DEMO_LIBS} freeglut)
360 IF(BUILD_STATIC_LIBS)
361 ADD_EXECUTABLE(${name}_static ${ARGN})
362 TARGET_LINK_LIBRARIES(${name}_static ${DEMO_LIBS} freeglut_static)
363 SET_TARGET_PROPERTIES(${name}_static PROPERTIES COMPILE_FLAGS -DFREEGLUT_STATIC)
368 ADD_DEMO(CallbackMaker progs/demos/CallbackMaker/CallbackMaker.c)
369 ADD_DEMO(Fractals progs/demos/Fractals/fractals.c)
370 ADD_DEMO(Fractals_random progs/demos/Fractals_random/fractals_random.c)
371 ADD_DEMO(Lorenz progs/demos/Lorenz/lorenz.c)
372 ADD_DEMO(One progs/demos/One/one.c)
373 ADD_DEMO(Resizer progs/demos/Resizer/Resizer.cpp)
374 ADD_DEMO(shapes progs/demos/shapes/shapes.c)
375 ADD_DEMO(smooth_opengl3 progs/demos/smooth_opengl3/smooth_opengl3.c)
376 ADD_DEMO(spaceball progs/demos/spaceball/spaceball.c
377 progs/demos/spaceball/vmath.c
378 progs/demos/spaceball/vmath.h)
379 ADD_DEMO(subwin progs/demos/subwin/subwin.c)
380 ADD_DEMO(timer progs/demos/timer/timer.c)
382 # finally, if any demos are built, copy needed files to output directory
383 # (currently, thats just the input file for the Fractals demo)
384 IF(FREEGLUT_BUILD_DEMOS)
385 # 1) copy fractals.dat from freeglut/progs/demos/Fractals
386 IF(BUILD_SHARED_LIBS)
387 SET(Frac_target Fractals)
389 SET(Frac_target Fractals_static)
391 GET_TARGET_PROPERTY(DEMO_OUTPUT_DIRECTORY ${Frac_target} RUNTIME_OUTPUT_DIRECTORY)
393 TARGET ${Frac_target}
395 COMMAND ${CMAKE_COMMAND} -E copy
396 ${PROJECT_SOURCE_DIR}/progs/demos/Fractals/fractals.dat
397 ${DEMO_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}
401 # pkg-config support, to install at $(libdir)/pkgconfig
402 # Define static build dependencies
404 SET(PC_LIBS_PRIVATE "-lopengl32 -lwinmm -lgdi32 -lm")
405 ELSEIF(FREEGLUT_GLES2)
407 SET(PC_LIBS_PRIVATE "-llog -landroid -lGLESv2 -lEGL -lm")
409 SET(PC_LIBS_PRIVATE "-lX11 -lXxf86vm -lXrandr -lGLESv2 -lEGL -lm")
411 ELSEIF(FREEGLUT_GLES1)
413 SET(PC_LIBS_PRIVATE "-llog -landroid -lGLESv1_CM -lEGL -lm")
415 SET(PC_LIBS_PRIVATE "-lX11 -lXxf86vm -lXrandr -lGLESv1_CM -lEGL -lm")
418 SET(PC_LIBS_PRIVATE "-lX11 -lXxf86vm -lXrandr -lGL -lm")
420 # Client applications need to define FreeGLUT GLES version to
421 # bootstrap headers inclusion in freeglut_std.h:
422 SET(PC_LIBNAME "glut")
423 SET(PC_FILENAME "freeglut.pc")
425 SET(PC_CFLAGS "-DFREEGLUT_GLES2")
426 SET(PC_LIBNAME "freeglut-gles2")
427 SET(PC_FILENAME "freeglut-gles2.pc")
428 ELSEIF(FREEGLUT_GLES1)
429 SET(PC_CFLAGS "-DFREEGLUT_GLES1")
430 SET(PC_LIBNAME "freeglut-gles1")
431 SET(PC_FILENAME "freeglut-gles1.pc")
433 CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/freeglut.pc.in ${CMAKE_BINARY_DIR}/freeglut.pc @ONLY)
434 INSTALL(FILES ${CMAKE_BINARY_DIR}/freeglut.pc DESTINATION share/pkgconfig/ RENAME ${PC_FILENAME})
435 # TODO: change the library and .pc name when building for GLES,