added to CMake a setup to copy shared lib (MSVC only right now) and
[freeglut] / CMakeLists.txt
index 08ef46a..e06a45c 100644 (file)
@@ -1,6 +1,10 @@
 PROJECT(freeglut)
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 
+SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
+SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
+
+
 SET(FREEGLUT_HEADERS
        include/GL/freeglut.h
        include/GL/freeglut_ext.h
@@ -33,18 +37,16 @@ SET(FREEGLUT_SRCS
 # Android port requires adding a version of these compatible with
 # OpenGL ES (TODO):
 IF(NOT ANDROID)
-       LIST(APPEND FREEGLUT_SRCS
-               src/fg_font.c
-               src/fg_geometry.c
-               src/fg_menu.c
-               src/fg_teapot.c
-)
+    LIST(APPEND FREEGLUT_SRCS
+        src/fg_font.c
+        src/fg_geometry.c
+        src/fg_menu.c
+        src/fg_teapot.c
+    )
 ENDIF()
 
-IF(WIN32)   # TODO: is this true for 64 bit as well? Chaneg to WINDOWS?
+IF(WIN32)
        LIST(APPEND FREEGLUT_SRCS
-               src/util/xparsegeometry_repl.c  # TODO: instead of this, detect if function is available and include if not
-               src/util/xparsegeometry_repl.h
                src/mswin/fg_cursor_mswin.c
                src/mswin/fg_display_mswin.c
                src/mswin/fg_ext_mswin.c
@@ -59,29 +61,35 @@ IF(WIN32)   # TODO: is this true for 64 bit as well? Chaneg to WINDOWS?
                src/mswin/fg_state_mswin.c
                src/mswin/fg_structure_mswin.c
                src/mswin/fg_window_mswin.c
-)
+        freeglut.rc
+    )
+    IF (NOT CMAKE_CL_64)
+        # .def file only for 32bit Windows builds
+        LIST(APPEND FREEGLUT_SRCS
+            src/freeglutdll.def
+        )
+    ENDIF()
+
 ELSEIF(ANDROID)
-       LIST(APPEND FREEGLUT_SRCS
-               src/util/xparsegeometry_repl.c
-               src/util/xparsegeometry_repl.h
-               src/egl/fg_internal_egl.h
-               src/egl/fg_display_egl.c
-               src/egl/fg_init_egl.c
-               src/egl/fg_structure_egl.c
-               src/egl/fg_window_egl.c
-               src/android/native_app_glue/android_native_app_glue.c
-               src/android/native_app_glue/android_native_app_glue.h
-               src/android/fg_runtime_android.c
-               src/android/fg_gamemode_android.c
-               src/android/fg_input_devices_android.c
-               src/android/fg_joystick_android.c
-               src/android/fg_main_android.c
-               src/android/fg_spaceball_android.c
-               src/android/fg_state_android.c
-               src/android/fg_window_android.c
-               src/android/opengles_stubs.c
-               src/android/fg_internal_android.h
-)
+    LIST(APPEND FREEGLUT_SRCS
+        src/egl/fg_internal_egl.h
+        src/egl/fg_display_egl.c
+        src/egl/fg_init_egl.c
+        src/egl/fg_structure_egl.c
+        src/egl/fg_window_egl.c
+        src/android/native_app_glue/android_native_app_glue.c
+        src/android/native_app_glue/android_native_app_glue.h
+        src/android/fg_runtime_android.c
+        src/android/fg_gamemode_android.c
+        src/android/fg_input_devices_android.c
+        src/android/fg_joystick_android.c
+        src/android/fg_main_android.c
+        src/android/fg_spaceball_android.c
+        src/android/fg_state_android.c
+        src/android/fg_window_android.c
+        src/android/opengles_stubs.c
+        src/android/fg_internal_android.h
+    )
 ELSE()
        LIST(APPEND FREEGLUT_SRCS
                src/x11/fg_cursor_x11.c
@@ -100,9 +108,7 @@ ELSE()
                src/x11/fg_structure_x11.c
                src/x11/fg_window_x11.c
                src/x11/fg_xinput_x11.c
-)
-
-
+    )
 ENDIF()
 
 # Neatly organize all of the output files in the build directory
@@ -172,10 +178,26 @@ CHECK_INCLUDE_FILES(usbhid.h      HAVE_USBHID_H)
 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
 CHECK_FUNCTION_EXISTS(vfprintf  HAVE_VFPRINTF)
 CHECK_FUNCTION_EXISTS(_doprnt   HAVE_DOPRNT)
+CHECK_FUNCTION_EXISTS(XParseGeometry   HAVE_XPARSEGEOMETRY)
+IF (NOT HAVE_XPARSEGEOMETRY)
+   LIST(APPEND FREEGLUT_SRCS
+               src/util/xparsegeometry_repl.c
+               src/util/xparsegeometry_repl.h)
+   SET(NEED_XPARSEGEOMETRY_IMPL TRUE)
+ENDIF()
 # decide on suitable type for internal time keeping, 64-bit if possible
 CHECK_INCLUDE_FILES(stdint.h    HAVE_STDINT_H)
 CHECK_INCLUDE_FILES(inttypes.h  HAVE_INTTYPES_H)
-CHECK_TYPE_SIZE("unsigned long long" ULONG_LONG BUILTIN_TYPES_ONLY)
+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
+        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
@@ -197,11 +219,16 @@ ENDIF()
 IF(WIN32)
        LIST(APPEND LIBS winmm)
        IF(BUILD_SHARED_LIBS)
-               LIST(APPEND FREEGLUT_SRCS src/Common/freeglutdll.def freeglut.rc)
-               # XXX I assume that if we want both shared and static this one is appropriate
-               ADD_DEFINITIONS(-DFREEGLUT_EXPORTS)
-       ELSE()
-               ADD_DEFINITIONS(-DFREEGLUT_STATIC)
+               SET_TARGET_PROPERTIES(freeglut PROPERTIES COMPILE_FLAGS -DFREEGLUT_EXPORTS)
+       ENDIF()
+    IF(BUILD_STATIC_LIBS)
+       SET_TARGET_PROPERTIES(freeglut_static PROPERTIES COMPILE_FLAGS -DFREEGLUT_STATIC)
+        # need to set machine:x64 for linker, at least for VC10, and
+        # doesn't hurt for older compilers:
+        # http://public.kitware.com/Bug/view.php?id=11240#c22768
+        IF (CMAKE_CL_64)
+            SET_TARGET_PROPERTIES(freeglut_static PROPERTIES STATIC_LIBRARY_FLAGS "/machine:x64")
+        ENDIF()
        ENDIF()
 ELSE()
        # on UNIX we need to make sure:
@@ -264,6 +291,7 @@ MACRO(ADD_DEMO name)
         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)
         ENDIF()
     ENDIF()
 ENDMACRO()
@@ -281,3 +309,33 @@ ADD_DEMO(spaceball       progs/demos/spaceball/spaceball.c
                          progs/demos/spaceball/vmath.h)
 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, 1) dll, and 2) input for Fractals demo)
+IF(FREEGLUT_BUILD_DEMOS)
+    # 1) copy dll. Make it an action to occur after freeglut dll is
+    # built, otherwise we'd have to hijack one of the demos above to do
+    # it. Not sure whats cleaner really... MSVC only for now...
+    GET_TARGET_PROPERTY(DEMO_OUTPUT_DIRECTORY CallbackMaker RUNTIME_OUTPUT_DIRECTORY)
+    GET_TARGET_PROPERTY(LIB_OUTPUT_DIRECTORY freeglut LIBRARY_OUTPUT_DIRECTORY)
+    if(MSVC AND BUILD_SHARED_LIBS)
+        # $(Configuration) gets replaced by MSBuild (not by CMake) with
+        # Debug, Release or whatever the current build is.
+        ADD_CUSTOM_COMMAND(
+            TARGET freeglut
+            POST_BUILD
+            COMMAND ${CMAKE_COMMAND} -E copy
+            ${LIB_OUTPUT_DIRECTORY}/$(Configuration)/freeglut${CMAKE_SHARED_LIBRARY_SUFFIX}
+            ${DEMO_OUTPUT_DIRECTORY}/$(Configuration)
+        )
+    ENDIF()
+
+    # 2) copy fractals.dat from freeglut/progs/demos/Fractals
+    ADD_CUSTOM_COMMAND(
+        TARGET freeglut
+        POST_BUILD
+        COMMAND ${CMAKE_COMMAND} -E copy
+        ${PROJECT_SOURCE_DIR}/progs/demos/Fractals/fractals.dat
+        ${DEMO_OUTPUT_DIRECTORY}/$(Configuration)
+    )
+ENDIF()