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)
17 include/GL/freeglut_ext.h
18 include/GL/freeglut_std.h
31 src/fg_input_devices.c
38 src/fg_stroke_mono_roman.c
44 # Android port requires adding a version of these compatible with
47 LIST(APPEND FREEGLUT_SRCS
56 LIST(APPEND FREEGLUT_SRCS
57 src/mswin/fg_cursor_mswin.c
58 src/mswin/fg_display_mswin.c
59 src/mswin/fg_ext_mswin.c
60 src/mswin/fg_gamemode_mswin.c
61 src/mswin/fg_init_mswin.c
62 src/mswin/fg_internal_mswin.h
63 src/mswin/fg_input_devices_mswin.c
64 src/mswin/fg_joystick_mswin.c
65 src/mswin/fg_main_mswin.c
66 src/mswin/fg_menu_mswin.c
67 src/mswin/fg_spaceball_mswin.c
68 src/mswin/fg_state_mswin.c
69 src/mswin/fg_structure_mswin.c
70 src/mswin/fg_window_mswin.c
74 # .def file only for 32bit Windows builds
75 LIST(APPEND FREEGLUT_SRCS
81 LIST(APPEND FREEGLUT_SRCS
82 src/egl/fg_internal_egl.h
83 src/egl/fg_display_egl.c
85 src/egl/fg_structure_egl.c
86 src/egl/fg_window_egl.c
87 src/android/native_app_glue/android_native_app_glue.c
88 src/android/native_app_glue/android_native_app_glue.h
89 src/android/fg_runtime_android.c
90 src/android/fg_gamemode_android.c
91 src/android/fg_input_devices_android.c
92 src/android/fg_joystick_android.c
93 src/android/fg_main_android.c
94 src/android/fg_spaceball_android.c
95 src/android/fg_state_android.c
96 src/android/fg_window_android.c
97 src/android/opengles_stubs.c
98 src/android/fg_internal_android.h
101 LIST(APPEND FREEGLUT_SRCS
102 src/x11/fg_cursor_x11.c
103 src/x11/fg_display_x11.c
105 src/x11/fg_gamemode_x11.c
106 src/x11/fg_glutfont_definitions_x11.c
107 src/x11/fg_init_x11.c
108 src/x11/fg_internal_x11.h
109 src/x11/fg_input_devices_x11.c
110 src/x11/fg_joystick_x11.c
111 src/x11/fg_main_x11.c
112 src/x11/fg_menu_x11.c
113 src/x11/fg_spaceball_x11.c
114 src/x11/fg_state_x11.c
115 src/x11/fg_structure_x11.c
116 src/x11/fg_window_x11.c
117 src/x11/fg_xinput_x11.c
121 # BUILD_SHARED_LIBS is already a standard CMake variable, but we need to
122 # re-declare it here so it will show up in the GUI.
123 # by default, we want to build both
124 OPTION(BUILD_SHARED_LIBS "Build FreeGLUT shared library." ON)
125 OPTION(BUILD_STATIC_LIBS "Build FreeGLUT static library." ON)
128 OPTION(FREEGLUT_GLES1 "Use OpenGL ES 1.x (requires EGL)" OFF)
129 OPTION(FREEGLUT_GLES2 "Use OpenGL ES 2.x (requires EGL) (overrides BUILD_GLES1)" OFF)
132 ADD_DEFINITIONS(-DGLESv2)
133 LIST(APPEND LIBS GLESv2 EGL)
134 ELSEIF(FREEGLUT_GLES1)
135 ADD_DEFINITIONS(-DGLESv1)
136 LIST(APPEND LIBS GLESv1 EGL)
138 FIND_PACKAGE(OpenGL REQUIRED)
139 LIST(APPEND LIBS ${OPENGL_gl_LIBRARY})
140 INCLUDE_DIRECTORIES(${OPENGL_INCLUDE_DIR})
143 # lib m for math, not needed on windows
149 MESSAGE(WARNING "Insecure CRT warnings hidden (might want to fix these)")
150 ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
153 if(UNIX AND NOT ANDROID)
154 FIND_PACKAGE(X11 REQUIRED)
155 LIST(APPEND LIBS ${X11_LIBRARIES})
157 SET(HAVE_X11_EXTENSIONS_XRANDR_H TRUE)
158 LIST(APPEND LIBS ${X11_Xrandr_LIB})
160 IF(X11_xf86vmode_FOUND)
161 SET(HAVE_X11_EXTENSIONS_XF86VMODE_H TRUE)
162 # Work-around http://www.cmake.org/Bug/bug_view_page.php?bug_id=6976
163 IF(NOT "${X11_Xxf86vm_LIB}")
164 SET(X11_Xxf86vm_LIB "Xxf86vm")
166 LIST(APPEND LIBS ${X11_Xxf86vm_LIB})
170 INCLUDE(CheckIncludeFiles)
171 INCLUDE(CheckFunctionExists)
172 INCLUDE(CheckTypeSize)
173 CHECK_INCLUDE_FILES(sys/types.h HAVE_SYS_TYPES_H)
174 CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H)
175 CHECK_INCLUDE_FILES(sys/time.h HAVE_SYS_TIME_H)
176 CHECK_INCLUDE_FILES(stdbool.h HAVE_STDBOOL_H)
177 CHECK_INCLUDE_FILES(sys/param.h HAVE_SYS_PARAM_H)
178 CHECK_INCLUDE_FILES(sys/ioctl.h HAVE_SYS_IOCTL_H)
179 CHECK_INCLUDE_FILES(fcntl.h HAVE_FCNTL_H)
180 CHECK_INCLUDE_FILES(errno.h HAVE_ERRNO_H)
181 CHECK_INCLUDE_FILES(usbhid.h HAVE_USBHID_H)
182 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
183 CHECK_FUNCTION_EXISTS(vfprintf HAVE_VFPRINTF)
184 CHECK_FUNCTION_EXISTS(_doprnt HAVE_DOPRNT)
185 CHECK_FUNCTION_EXISTS(XParseGeometry HAVE_XPARSEGEOMETRY)
186 IF (NOT HAVE_XPARSEGEOMETRY)
187 LIST(APPEND FREEGLUT_SRCS
188 src/util/xparsegeometry_repl.c
189 src/util/xparsegeometry_repl.h)
190 SET(NEED_XPARSEGEOMETRY_IMPL TRUE)
192 # decide on suitable type for internal time keeping, 64-bit if possible
193 CHECK_INCLUDE_FILES(stdint.h HAVE_STDINT_H)
194 CHECK_INCLUDE_FILES(inttypes.h HAVE_INTTYPES_H)
195 IF (NOT (HAVE_STDINT_H OR HAVE_INTTYPES_H))
197 # Some old Microsoft VC don't support unsigned long long, but all we
198 # care about support unsigned __int64, so test for presence of that
200 CHECK_TYPE_SIZE("unsigned __int64" U__INT64 BUILTIN_TYPES_ONLY)
202 CHECK_TYPE_SIZE("unsigned long long" ULONG_LONG BUILTIN_TYPES_ONLY)
207 # The generated config.h is placed in the project's build directory, just to
208 # ensure that all CMake-generated files are kept away from the main source tree.
209 # As a result, the build directory must to be added to the include path list.
210 CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/config.h.in ${CMAKE_BINARY_DIR}/config.h)
211 INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src)
212 ADD_DEFINITIONS(-DHAVE_CONFIG_H)
214 IF(BUILD_SHARED_LIBS)
215 ADD_LIBRARY(freeglut SHARED ${FREEGLUT_SRCS})
217 IF(BUILD_STATIC_LIBS)
218 ADD_LIBRARY(freeglut_static STATIC ${FREEGLUT_SRCS})
223 LIST(APPEND LIBS winmm)
224 IF(BUILD_SHARED_LIBS)
225 SET_TARGET_PROPERTIES(freeglut PROPERTIES COMPILE_FLAGS -DFREEGLUT_EXPORTS)
227 IF(BUILD_STATIC_LIBS)
228 SET_TARGET_PROPERTIES(freeglut_static PROPERTIES COMPILE_FLAGS -DFREEGLUT_STATIC)
229 # need to set machine:x64 for linker, at least for VC10, and
230 # doesn't hurt for older compilers:
231 # http://public.kitware.com/Bug/view.php?id=11240#c22768
233 SET_TARGET_PROPERTIES(freeglut_static PROPERTIES STATIC_LIBRARY_FLAGS "/machine:x64")
237 # on UNIX we need to make sure:
238 # - all shared libraries must have a soname/version, see :
239 # http://sourceware.org/autobook/autobook/autobook_91.html#SEC91
240 # http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
241 # Current: -version-info 12:0:9 -> 3.9.0
242 # - the output library should be named glut so it'll be linkable with -lglut
243 # - the shared library should link to the dependency libraries so that the user
244 # won't have to link them explicitly (they shouldn't have to know that we depend
245 # on Xrandr or Xxf86vm)
246 SET_TARGET_PROPERTIES(freeglut PROPERTIES VERSION 3.9.0 SOVERSION 3 OUTPUT_NAME glut)
247 SET_TARGET_PROPERTIES(freeglut_static PROPERTIES OUTPUT_NAME glut)
249 # Not in CMake toolchain file, because the toolchain
250 # file is called several times and generally doesn't
251 # seem to be meant for it:
252 # '-mandroid' is not mandatory but doesn't hurt
253 # '-O0 -gstabs+' helps the currently buggy GDB port
254 # '-DANDROID' is the Android build system convention
255 # Too late to manipulate ENV: SET(ENV{CFLAGS} "$ENV{CFLAGS} -mandroid")
256 # Not using _INIT variables, they seem to be used internally only
257 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mandroid")
258 SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -gstabs+")
259 ADD_DEFINITIONS(-DANDROID)
262 IF(BUILD_SHARED_LIBS)
263 TARGET_LINK_LIBRARIES(freeglut ${LIBS})
265 IF(BUILD_STATIC_LIBS)
266 TARGET_LINK_LIBRARIES(freeglut_static ${LIBS})
269 IF(BUILD_SHARED_LIBS)
270 INSTALL(TARGETS freeglut DESTINATION lib)
272 IF(BUILD_STATIC_LIBS)
273 INSTALL(TARGETS freeglut_static DESTINATION lib)
275 INSTALL(FILES ${FREEGLUT_HEADERS} DESTINATION include/GL)
279 # Optionally build demos, on by default.
280 option( FREEGLUT_BUILD_DEMOS "Build FreeGLUT demos." ON )
282 SET(DEMO_LIBS ${OPENGL_glu_LIBRARY} ${LIBS})
283 # lib m for math, not needed on windows
285 LIST(APPEND DEMO_LIBS m)
289 IF( FREEGLUT_BUILD_DEMOS )
290 IF(BUILD_SHARED_LIBS)
291 ADD_EXECUTABLE(${name} ${ARGN})
292 TARGET_LINK_LIBRARIES(${name} ${DEMO_LIBS} freeglut)
294 IF(BUILD_STATIC_LIBS)
295 ADD_EXECUTABLE(${name}_static ${ARGN})
296 TARGET_LINK_LIBRARIES(${name}_static ${DEMO_LIBS} freeglut_static)
297 SET_TARGET_PROPERTIES(${name}_static PROPERTIES COMPILE_FLAGS -DFREEGLUT_STATIC)
302 ADD_DEMO(CallbackMaker progs/demos/CallbackMaker/CallbackMaker.c)
303 ADD_DEMO(Fractals progs/demos/Fractals/fractals.c)
304 ADD_DEMO(Fractals_random progs/demos/Fractals_random/fractals_random.c)
305 ADD_DEMO(Lorenz progs/demos/Lorenz/lorenz.c)
306 ADD_DEMO(One progs/demos/One/one.c)
307 ADD_DEMO(Resizer progs/demos/Resizer/Resizer.cpp)
308 ADD_DEMO(shapes progs/demos/shapes/shapes.c)
309 ADD_DEMO(smooth_opengl3 progs/demos/smooth_opengl3/smooth_opengl3.c)
310 ADD_DEMO(spaceball progs/demos/spaceball/spaceball.c
311 progs/demos/spaceball/vmath.c
312 progs/demos/spaceball/vmath.h)
313 ADD_DEMO(subwin progs/demos/subwin/subwin.c)
314 ADD_DEMO(timer progs/demos/timer/timer.c)
316 # finally, if any demos are built, copy needed files to output directory
317 # (currently, thats just the input file for the Fractals demo)
318 IF(FREEGLUT_BUILD_DEMOS)
319 # 1) copy fractals.dat from freeglut/progs/demos/Fractals
320 IF(BUILD_SHARED_LIBS)
321 SET(Frac_target Fractals)
323 SET(Frac_target Fractals_static)
325 GET_TARGET_PROPERTY(DEMO_OUTPUT_DIRECTORY ${Frac_target} RUNTIME_OUTPUT_DIRECTORY)
327 TARGET ${Frac_target}
329 COMMAND ${CMAKE_COMMAND} -E copy
330 ${PROJECT_SOURCE_DIR}/progs/demos/Fractals/fractals.dat
331 ${DEMO_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}