2 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
4 SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
5 SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
10 include/GL/freeglut_ext.h
11 include/GL/freeglut_std.h
24 src/fg_input_devices.c
31 src/fg_stroke_mono_roman.c
37 # Android port requires adding a version of these compatible with
40 LIST(APPEND FREEGLUT_SRCS
49 LIST(APPEND FREEGLUT_SRCS
50 src/mswin/fg_cursor_mswin.c
51 src/mswin/fg_display_mswin.c
52 src/mswin/fg_ext_mswin.c
53 src/mswin/fg_gamemode_mswin.c
54 src/mswin/fg_init_mswin.c
55 src/mswin/fg_internal_mswin.h
56 src/mswin/fg_input_devices_mswin.c
57 src/mswin/fg_joystick_mswin.c
58 src/mswin/fg_main_mswin.c
59 src/mswin/fg_menu_mswin.c
60 src/mswin/fg_spaceball_mswin.c
61 src/mswin/fg_state_mswin.c
62 src/mswin/fg_structure_mswin.c
63 src/mswin/fg_window_mswin.c
67 # .def file only for 32bit Windows builds
68 LIST(APPEND FREEGLUT_SRCS
74 LIST(APPEND FREEGLUT_SRCS
75 src/egl/fg_internal_egl.h
76 src/egl/fg_display_egl.c
78 src/egl/fg_structure_egl.c
79 src/egl/fg_window_egl.c
80 src/android/native_app_glue/android_native_app_glue.c
81 src/android/native_app_glue/android_native_app_glue.h
82 src/android/fg_runtime_android.c
83 src/android/fg_gamemode_android.c
84 src/android/fg_input_devices_android.c
85 src/android/fg_joystick_android.c
86 src/android/fg_main_android.c
87 src/android/fg_spaceball_android.c
88 src/android/fg_state_android.c
89 src/android/fg_window_android.c
90 src/android/opengles_stubs.c
91 src/android/fg_internal_android.h
94 LIST(APPEND FREEGLUT_SRCS
95 src/x11/fg_cursor_x11.c
96 src/x11/fg_display_x11.c
98 src/x11/fg_gamemode_x11.c
99 src/x11/fg_glutfont_definitions_x11.c
100 src/x11/fg_init_x11.c
101 src/x11/fg_internal_x11.h
102 src/x11/fg_input_devices_x11.c
103 src/x11/fg_joystick_x11.c
104 src/x11/fg_main_x11.c
105 src/x11/fg_menu_x11.c
106 src/x11/fg_spaceball_x11.c
107 src/x11/fg_state_x11.c
108 src/x11/fg_structure_x11.c
109 src/x11/fg_window_x11.c
110 src/x11/fg_xinput_x11.c
114 # Neatly organize all of the output files in the build directory
115 SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
116 SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
118 # BUILD_SHARED_LIBS is already a standard CMake variable, but we need to
119 # re-declare it here so it will show up in the GUI.
120 OPTION(BUILD_SHARED_LIBS "Build FreeGLUT shared library." ON)
121 OPTION(BUILD_STATIC_LIBS "Build FreeGLUT static library." ON)
124 OPTION(FREEGLUT_GLES1 "Use OpenGL ES 1.x (requires EGL)" OFF)
125 OPTION(FREEGLUT_GLES2 "Use OpenGL ES 2.x (requires EGL) (overrides BUILD_GLES1)" OFF)
128 ADD_DEFINITIONS(-DGLESv2)
129 LIST(APPEND LIBS GLESv2 EGL)
130 ELSEIF(FREEGLUT_GLES1)
131 ADD_DEFINITIONS(-DGLESv1)
132 LIST(APPEND LIBS GLESv1 EGL)
134 FIND_PACKAGE(OpenGL REQUIRED)
135 LIST(APPEND LIBS ${OPENGL_gl_LIBRARY})
136 INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
139 # lib m for math, not needed on windows
145 MESSAGE(WARNING "Insecure CRT warnings hidden (might want to fix these)")
146 ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
149 if(UNIX AND NOT ANDROID)
150 FIND_PACKAGE(X11 REQUIRED)
151 LIST(APPEND LIBS ${X11_LIBRARIES})
153 SET(HAVE_X11_EXTENSIONS_XRANDR_H TRUE)
154 LIST(APPEND LIBS ${X11_Xrandr_LIB})
156 IF(X11_xf86vmode_FOUND)
157 SET(HAVE_X11_EXTENSIONS_XF86VMODE_H TRUE)
158 # Work-around http://www.cmake.org/Bug/bug_view_page.php?bug_id=6976
159 IF(NOT "${X11_Xxf86vm_LIB}")
160 SET(X11_Xxf86vm_LIB "Xxf86vm")
162 LIST(APPEND LIBS ${X11_Xxf86vm_LIB})
166 INCLUDE(CheckIncludeFiles)
167 INCLUDE(CheckFunctionExists)
168 INCLUDE(CheckTypeSize)
169 CHECK_INCLUDE_FILES(sys/types.h HAVE_SYS_TYPES_H)
170 CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H)
171 CHECK_INCLUDE_FILES(sys/time.h HAVE_SYS_TIME_H)
172 CHECK_INCLUDE_FILES(stdbool.h HAVE_STDBOOL_H)
173 CHECK_INCLUDE_FILES(sys/param.h HAVE_SYS_PARAM_H)
174 CHECK_INCLUDE_FILES(sys/ioctl.h HAVE_SYS_IOCTL_H)
175 CHECK_INCLUDE_FILES(fcntl.h HAVE_FCNTL_H)
176 CHECK_INCLUDE_FILES(errno.h HAVE_ERRNO_H)
177 CHECK_INCLUDE_FILES(usbhid.h HAVE_USBHID_H)
178 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
179 CHECK_FUNCTION_EXISTS(vfprintf HAVE_VFPRINTF)
180 CHECK_FUNCTION_EXISTS(_doprnt HAVE_DOPRNT)
181 CHECK_FUNCTION_EXISTS(XParseGeometry HAVE_XPARSEGEOMETRY)
182 IF (NOT HAVE_XPARSEGEOMETRY)
183 LIST(APPEND FREEGLUT_SRCS
184 src/util/xparsegeometry_repl.c
185 src/util/xparsegeometry_repl.h)
186 SET(NEED_XPARSEGEOMETRY_IMPL TRUE)
188 # decide on suitable type for internal time keeping, 64-bit if possible
189 CHECK_INCLUDE_FILES(stdint.h HAVE_STDINT_H)
190 CHECK_INCLUDE_FILES(inttypes.h HAVE_INTTYPES_H)
191 IF (NOT (HAVE_STDINT_H OR HAVE_INTTYPES_H))
193 # Some old Microsoft VC don't support unsigned long long, but all we
194 # care about support unsigned __int64, so test for presence of that
196 CHECK_TYPE_SIZE("unsigned __int64" U__INT64 BUILTIN_TYPES_ONLY)
198 CHECK_TYPE_SIZE("unsigned long long" ULONG_LONG BUILTIN_TYPES_ONLY)
203 # The generated config.h is placed in the project's build directory, just to
204 # ensure that all CMake-generated files are kept away from the main source tree.
205 # As a result, the build directory must to be added to the include path list.
206 CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/config.h.in ${CMAKE_BINARY_DIR}/config.h)
207 INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src)
208 ADD_DEFINITIONS(-DHAVE_CONFIG_H)
210 # by default, at least on UNIX, we want to build both
211 IF(BUILD_SHARED_LIBS)
212 ADD_LIBRARY(freeglut SHARED ${FREEGLUT_SRCS})
214 IF(BUILD_STATIC_LIBS)
215 ADD_LIBRARY(freeglut_static STATIC ${FREEGLUT_SRCS})
220 LIST(APPEND LIBS winmm)
221 IF(BUILD_SHARED_LIBS)
222 SET_TARGET_PROPERTIES(freeglut PROPERTIES COMPILE_FLAGS -DFREEGLUT_EXPORTS)
224 IF(BUILD_STATIC_LIBS)
225 SET_TARGET_PROPERTIES(freeglut_static PROPERTIES COMPILE_FLAGS -DFREEGLUT_STATIC)
226 # need to set machine:x64 for linker, at least for VC10, and
227 # doesn't hurt for older compilers:
228 # http://public.kitware.com/Bug/view.php?id=11240#c22768
230 SET_TARGET_PROPERTIES(freeglut_static PROPERTIES STATIC_LIBRARY_FLAGS "/machine:x64")
234 # on UNIX we need to make sure:
235 # - all shared libraries must have a soname/version, see :
236 # http://sourceware.org/autobook/autobook/autobook_91.html#SEC91
237 # http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
238 # Current: -version-info 12:0:9 -> 3.9.0
239 # - the output library should be named glut so it'll be linkable with -lglut
240 # - the shared library should link to the dependency libraries so that the user
241 # won't have to link them explicitly (they shouldn't have to know that we depend
242 # on Xrandr or Xxf86vm)
243 SET_TARGET_PROPERTIES(freeglut PROPERTIES VERSION 3.9.0 SOVERSION 3 OUTPUT_NAME glut)
244 SET_TARGET_PROPERTIES(freeglut_static PROPERTIES OUTPUT_NAME glut)
246 # Not in CMake toolchain file, because the toolchain
247 # file is called several times and generally doesn't
248 # seem to be meant for it:
249 # '-mandroid' is not mandatory but doesn't hurt
250 # '-O0 -gstabs+' helps the currently buggy GDB port
251 # '-DANDROID' is the Android build system convention
252 # Too late to manipulate ENV: SET(ENV{CFLAGS} "$ENV{CFLAGS} -mandroid")
253 # Not using _INIT variables, they seem to be used internally only
254 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mandroid")
255 SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -gstabs+")
256 ADD_DEFINITIONS(-DANDROID)
259 IF(BUILD_SHARED_LIBS)
260 TARGET_LINK_LIBRARIES(freeglut ${LIBS})
262 IF(BUILD_STATIC_LIBS)
263 TARGET_LINK_LIBRARIES(freeglut_static ${LIBS})
266 IF(BUILD_SHARED_LIBS)
267 INSTALL(TARGETS freeglut DESTINATION lib)
269 IF(BUILD_STATIC_LIBS)
270 INSTALL(TARGETS freeglut_static DESTINATION lib)
272 INSTALL(FILES ${FREEGLUT_HEADERS} DESTINATION include/GL)
276 # Optionally build demos, on by default.
277 option( FREEGLUT_BUILD_DEMOS "Build FreeGLUT demos." ON )
279 SET(DEMO_LIBS ${OPENGL_glu_LIBRARY} ${LIBS})
280 # lib m for math, not needed on windows
282 LIST(APPEND DEMO_LIBS m)
286 IF( FREEGLUT_BUILD_DEMOS )
287 IF(BUILD_SHARED_LIBS)
288 ADD_EXECUTABLE(${name} ${ARGN})
289 TARGET_LINK_LIBRARIES(${name} ${DEMO_LIBS} freeglut)
291 IF(BUILD_STATIC_LIBS)
292 ADD_EXECUTABLE(${name}_static ${ARGN})
293 TARGET_LINK_LIBRARIES(${name}_static ${DEMO_LIBS} freeglut_static)
294 SET_TARGET_PROPERTIES(${name}_static PROPERTIES COMPILE_FLAGS -DFREEGLUT_STATIC)
299 ADD_DEMO(CallbackMaker progs/demos/CallbackMaker/CallbackMaker.c)
300 ADD_DEMO(Fractals progs/demos/Fractals/fractals.c)
301 ADD_DEMO(Fractals_random progs/demos/Fractals_random/fractals_random.c)
302 ADD_DEMO(Lorenz progs/demos/Lorenz/lorenz.c)
303 ADD_DEMO(One progs/demos/One/one.c)
304 ADD_DEMO(Resizer progs/demos/Resizer/Resizer.cpp)
305 ADD_DEMO(shapes progs/demos/shapes/shapes.c)
306 ADD_DEMO(smooth_opengl3 progs/demos/smooth_opengl3/smooth_opengl3.c)
307 ADD_DEMO(spaceball progs/demos/spaceball/spaceball.c
308 progs/demos/spaceball/vmath.c
309 progs/demos/spaceball/vmath.h)
310 ADD_DEMO(subwin progs/demos/subwin/subwin.c)
311 ADD_DEMO(timer progs/demos/timer/timer.c)
313 # finally, if any demos are built, copy needed files to output directory
314 # (currently, 1) dll, and 2) input for Fractals demo)
315 IF(FREEGLUT_BUILD_DEMOS)
316 # 1) copy dll. Make it an action to occur after freeglut dll is
317 # built, otherwise we'd have to hijack one of the demos above to do
318 # it. Not sure whats cleaner really... MSVC only for now...
319 GET_TARGET_PROPERTY(DEMO_OUTPUT_DIRECTORY CallbackMaker RUNTIME_OUTPUT_DIRECTORY)
320 GET_TARGET_PROPERTY(LIB_OUTPUT_DIRECTORY freeglut LIBRARY_OUTPUT_DIRECTORY)
321 if(MSVC AND BUILD_SHARED_LIBS)
322 # $(Configuration) gets replaced by MSBuild (not by CMake) with
323 # Debug, Release or whatever the current build is.
327 COMMAND ${CMAKE_COMMAND} -E copy
328 ${LIB_OUTPUT_DIRECTORY}/$(Configuration)/freeglut${CMAKE_SHARED_LIBRARY_SUFFIX}
329 ${DEMO_OUTPUT_DIRECTORY}/$(Configuration)
333 # 2) copy fractals.dat from freeglut/progs/demos/Fractals
337 COMMAND ${CMAKE_COMMAND} -E copy
338 ${PROJECT_SOURCE_DIR}/progs/demos/Fractals/fractals.dat
339 ${DEMO_OUTPUT_DIRECTORY}/$(Configuration)