comment on timer checking, are timers always sorted by triggertime? Else the code...
[freeglut] / CMakeLists.txt
index 39febb2..6f6130e 100644 (file)
@@ -1,5 +1,5 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
 PROJECT(freeglut)
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 
 # NOTE: On Windows and Cygwin, the dll's are placed in the
 # CMAKE_RUNTIME_OUTPUT_DIRECTORY, while their corresponding import
@@ -7,8 +7,9 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 # platforms, such as Linux, the shared libraries are put in
 # CMAKE_ARCHIVE_OUTPUT_DIRECTORY instead.
 # Static libraries end up in CMAKE_ARCHIVE_OUTPUT_DIRECTORY on all
-# platforms (unless 
+# platforms.
 SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
+SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
 SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
 
 # setup version numbers
@@ -24,11 +25,26 @@ set(VERSION_PATCH 0)
 OPTION(BUILD_SHARED_LIBS "Build FreeGLUT shared library." ON)
 OPTION(BUILD_STATIC_LIBS "Build FreeGLUT static library." ON)
 
+# option for whether warnings and errors should be printed
+OPTION(FREEGLUT_ERRORS "Lib prints errors to stderr" ON)
+#MARK_AS_ADVANCED(FREEGLUT_ERRORS)
+OPTION(FREEGLUT_WARNINGS "Lib prints warnings to stderr" ON)
+#MARK_AS_ADVANCED(FREEGLUT_WARNINGS)
+
+# option to also copy .pdb files to install directory when executing
+# INSTALL target
+IF(MSVC)
+    OPTION(INSTALL_PDB "Also install .pdb files" ON)
+ELSE()
+    SET(INSTALL_PDB OFF)
+ENDIF()
+
 # OpenGL ES support
 OPTION(FREEGLUT_GLES1 "Use OpenGL ES 1.x (requires EGL)" OFF)
 OPTION(FREEGLUT_GLES2 "Use OpenGL ES 2.x (requires EGL) (overrides BUILD_GLES1)" OFF)
 
 
+
 SET(FREEGLUT_HEADERS
     include/GL/freeglut.h
     include/GL/freeglut_ext.h
@@ -51,7 +67,6 @@ SET(FREEGLUT_SRCS
     src/fg_input_devices.c
     src/fg_joystick.c
     src/fg_main.c
-    src/fg_main.h
     src/fg_misc.c
     src/fg_overlay.c
     src/fg_spaceball.c
@@ -97,7 +112,8 @@ IF(WIN32)
         ${CMAKE_BINARY_DIR}/freeglut.rc # generated below from freeglut.rc.in
     )
     IF (MSVC AND NOT CMAKE_CL_64)
-        # .def file only for 32bit Windows builds
+        # .def file only for 32bit Windows builds (TODO: MSVC only right
+        # now, needed for any other Windows platform?)
         LIST(APPEND FREEGLUT_SRCS
             ${CMAKE_BINARY_DIR}/freeglutdll.def # generated below from src/freeglutdll.def.in
         )
@@ -145,6 +161,7 @@ ELSE()
             src/x11/fg_internal_x11_glx.h
             src/x11/fg_display_x11_glx.c
             src/x11/fg_state_x11_glx.c
+            src/x11/fg_state_x11_glx.h
             src/x11/fg_window_x11_glx.c
             src/x11/fg_window_x11_glx.h
         )
@@ -169,7 +186,7 @@ ENDIF()
 # For OpenGL ES (GLES):
 # - compile with -DFREEGLUT_GLES1 and -DFREEGLUT_GLES2 to cleanly
 #   bootstrap headers inclusion in freeglut_std.h; these constants
-#   also need to be defined in client applications (e.g through
+#   also need to be defined in client applications (e.g. through
 #   pkg-config), but use GLES constants directly for all other needs
 # - define GLES version-specific library
 IF(FREEGLUT_GLES2)
@@ -186,12 +203,19 @@ ENDIF()
 
 # lib m for math, not needed on windows
 IF (NOT WIN32)
+    # For compilation:
     LIST(APPEND LIBS m)
+    # For CHECK_FUNCTION_EXISTS:
+    LIST(APPEND CMAKE_REQUIRED_LIBRARIES m)
 ENDIF()
 
 IF(WIN32)
     # hide insecure CRT warnings, common practice
     ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
+    IF(MSVC)
+        SET( CMAKE_DEBUG_POSTFIX "d" )
+    ENDIF(MSVC)
+    
 ENDIF()
 
 IF(CMAKE_COMPILER_IS_GNUCC)
@@ -202,7 +226,8 @@ IF(CMAKE_COMPILER_IS_GNUCC)
   ENDIF()
 ENDIF(CMAKE_COMPILER_IS_GNUCC)
 
-if(UNIX AND NOT ANDROID)
+INCLUDE(CheckIncludeFiles)
+IF(UNIX AND NOT ANDROID)
     FIND_PACKAGE(X11 REQUIRED)
     LIST(APPEND LIBS ${X11_LIBRARIES})
     IF(X11_Xrandr_FOUND)
@@ -217,9 +242,18 @@ if(UNIX AND NOT ANDROID)
         ENDIF()
         LIST(APPEND LIBS ${X11_Xxf86vm_LIB})
     ENDIF()
+    IF(X11_Xinput_FOUND)
+        # Needed for multi-touch:
+        CHECK_INCLUDE_FILES("${X11_Xinput_INCLUDE_PATH}/X11/extensions/XInput2.h" HAVE_X11_EXTENSIONS_XINPUT2_H)
+        LIST(APPEND LIBS ${X11_Xinput_LIB})
+    ENDIF()
+ENDIF()
+IF(ANDROID)
+    # -landroid for ANativeWindow
+    # -llog for native Android logging
+    LIST(APPEND LIBS android log)
 ENDIF()
 
-INCLUDE(CheckIncludeFiles)
 INCLUDE(CheckFunctionExists)
 INCLUDE(CheckTypeSize)
 CHECK_INCLUDE_FILES(sys/types.h HAVE_SYS_TYPES_H)
@@ -246,16 +280,15 @@ CHECK_INCLUDE_FILES(stdint.h    HAVE_STDINT_H)
 CHECK_INCLUDE_FILES(inttypes.h  HAVE_INTTYPES_H)
 IF (NOT (HAVE_STDINT_H OR HAVE_INTTYPES_H))
     IF (MSVC)
-        # Some old Microsoft VC don't support unsigned long long, but all we
-        # care about support unsigned __int64, so test for presence of that
-        # type
+        # Some old Microsoft VC releases don't support unsigned long
+        # long, but all we care about is support for unsigned __int64 on
+        # MSVC, so test for presence of that type
         CHECK_TYPE_SIZE("unsigned __int64" U__INT64 BUILTIN_TYPES_ONLY)
     ELSEIF()
         CHECK_TYPE_SIZE("unsigned long long" ULONG_LONG BUILTIN_TYPES_ONLY)
     ENDIF()
 ENDIF()
 
-
 # The generated config.h is placed in the project's build directory, just to
 # ensure that all CMake-generated files are kept away from the main source tree.
 # As a result, the build directory must to be added to the include path list.
@@ -300,6 +333,11 @@ ELSE()
     #   http://sourceware.org/autobook/autobook/autobook_91.html#SEC91
     #   http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
     #   Current: -version-info 12:0:9 -> 3.9.0
+    #   Note: most platforms now prefer the latter major.minor.revision form
+    #   (e.g. FreeBSD, cf. http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8765),
+    #   or special-cased FreeGLUT long ago (e.g. .so.4 on OpenBSD), so
+    #   the lack of support for current:revision:age in CMake should
+    #   not be a problem.
     # - the output library should be named glut so it'll be linkable with -lglut
     # - the shared library should link to the dependency libraries so that the user
     #   won't have to link them explicitly (they shouldn't have to know that we depend
@@ -334,10 +372,28 @@ IF(BUILD_STATIC_LIBS)
 ENDIF()
 
 IF(BUILD_SHARED_LIBS)
-    INSTALL(TARGETS freeglut DESTINATION lib)
+    INSTALL(TARGETS freeglut
+            RUNTIME DESTINATION bin
+            LIBRARY DESTINATION lib
+            ARCHIVE DESTINATION lib
+    )
+    IF(INSTALL_PDB)
+        INSTALL(FILES ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Debug/freeglut${CMAKE_DEBUG_POSTFIX}.pdb
+            DESTINATION bin
+                       CONFIGURATIONS Debug)
+    ENDIF()
 ENDIF()
 IF(BUILD_STATIC_LIBS)
-    INSTALL(TARGETS freeglut_static DESTINATION lib)
+    INSTALL(TARGETS freeglut_static
+            RUNTIME DESTINATION bin
+            LIBRARY DESTINATION lib
+            ARCHIVE DESTINATION lib
+    )
+    IF(INSTALL_PDB)
+        INSTALL(FILES ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/Debug/freeglut_static${CMAKE_DEBUG_POSTFIX}.pdb
+            DESTINATION lib
+                       CONFIGURATIONS Debug)
+    ENDIF()
 ENDIF()
 INSTALL(FILES ${FREEGLUT_HEADERS} DESTINATION include/GL)
 
@@ -357,11 +413,17 @@ MACRO(ADD_DEMO name)
         IF(BUILD_SHARED_LIBS)
             ADD_EXECUTABLE(${name} ${ARGN})
             TARGET_LINK_LIBRARIES(${name} ${DEMO_LIBS} freeglut)
+            IF(WIN32 AND MSVC)
+                SET_TARGET_PROPERTIES(${name} PROPERTIES DEBUG_POSTFIX d)
+            ENDIF()
         ENDIF()
         IF(BUILD_STATIC_LIBS)
             ADD_EXECUTABLE(${name}_static ${ARGN})
             TARGET_LINK_LIBRARIES(${name}_static ${DEMO_LIBS} freeglut_static)
             SET_TARGET_PROPERTIES(${name}_static PROPERTIES COMPILE_FLAGS -DFREEGLUT_STATIC)
+            IF(WIN32 AND MSVC)
+                SET_TARGET_PROPERTIES(${name}_static PROPERTIES DEBUG_POSTFIX d)
+            ENDIF()
         ENDIF()
     ENDIF()
 ENDMACRO()
@@ -370,34 +432,27 @@ ADD_DEMO(CallbackMaker   progs/demos/CallbackMaker/CallbackMaker.c)
 ADD_DEMO(Fractals        progs/demos/Fractals/fractals.c)
 ADD_DEMO(Fractals_random progs/demos/Fractals_random/fractals_random.c)
 ADD_DEMO(Lorenz          progs/demos/Lorenz/lorenz.c)
-ADD_DEMO(One             progs/demos/One/one.c)
+IF (NOT WIN32)
+    ADD_DEMO(One             progs/demos/One/one.c)
+ELSE()
+    ADD_DEMO(One             progs/demos/One/one.c
+                             progs/demos/One/one.rc)
+ENDIF()
 ADD_DEMO(Resizer         progs/demos/Resizer/Resizer.cpp)
-ADD_DEMO(shapes          progs/demos/shapes/shapes.c)
+ADD_DEMO(multi-touch     progs/demos/multi-touch/multi-touch.c)
+ADD_DEMO(shapes          progs/demos/shapes/shapes.c
+                         progs/demos/shapes/glmatrix.h
+                         progs/demos/shapes/glmatrix.c)
 ADD_DEMO(smooth_opengl3  progs/demos/smooth_opengl3/smooth_opengl3.c)
-ADD_DEMO(spaceball       progs/demos/spaceball/spaceball.c
-                         progs/demos/spaceball/vmath.c
-                         progs/demos/spaceball/vmath.h)
+IF(UNIX)
+    ADD_DEMO(spaceball       progs/demos/spaceball/spaceball.c
+                             progs/demos/spaceball/vmath.c
+                             progs/demos/spaceball/vmath.h)
+ENDIF()
 ADD_DEMO(subwin          progs/demos/subwin/subwin.c)
 ADD_DEMO(timer           progs/demos/timer/timer.c)
 
-# finally, if any demos are built, copy needed files to output directory
-# (currently, thats just the input file for the Fractals demo)
-IF(FREEGLUT_BUILD_DEMOS)
-    # 1) copy fractals.dat from freeglut/progs/demos/Fractals
-    IF(BUILD_SHARED_LIBS)
-        SET(Frac_target Fractals)
-    ELSE()
-        SET(Frac_target Fractals_static)
-    ENDIF()
-    GET_TARGET_PROPERTY(DEMO_OUTPUT_DIRECTORY ${Frac_target} RUNTIME_OUTPUT_DIRECTORY)
-    ADD_CUSTOM_COMMAND(
-        TARGET ${Frac_target}
-        POST_BUILD
-        COMMAND ${CMAKE_COMMAND} -E copy
-        ${PROJECT_SOURCE_DIR}/progs/demos/Fractals/fractals.dat
-        ${DEMO_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}
-    )
-ENDIF()
+
 
 # pkg-config support, to install at $(libdir)/pkgconfig
 # Define static build dependencies