]> git.cworth.org Git - apitrace/blobdiff - CMakeLists.txt
Portability fixes.
[apitrace] / CMakeLists.txt
index 27df9f84a4cd6356dd917e6c811543d4d80c2f09..78a6f2d6b34650b9bf436ce5a216e9e02eb5d294 100644 (file)
@@ -1,9 +1,17 @@
-cmake_minimum_required (VERSION 2.6)
+cmake_minimum_required (VERSION 2.8)
 
 project (apitrace)
 
 set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
 
+# Set default built type
+if (NOT CMAKE_BUILD_TYPE)
+       set (CMAKE_BUILD_TYPE Debug
+               CACHE
+               STRING "Choose the build type, options are: None, Debug, Release, RelWithDebInfo, or MinSizeRel."
+               FORCE)
+endif (NOT CMAKE_BUILD_TYPE)
+
 find_package (PythonInterp REQUIRED)
 find_package (OpenGL REQUIRED)
 find_package (ZLIB)
@@ -12,35 +20,9 @@ find_package (DirectX)
 
 find_package (GLUT)
 
-find_library (GLEW_glew_LIBRARY GLEW
-       /usr/lib
-)
-
-find_path (GLEW_INCLUDE_DIR GL/glew.h
-      /usr/include/GL
-)
-
 if (WIN32)
-       # Nobody likes to include windows.h:
-       # - Microsoft's GL/gl.h header depends on windows.h but doesn't include it;
-       # - GLEW temporarily defines the necessary defines but undefines them later
-       # - certain GLUT distributions don't include it;
-       # - most of our programs are meant to be portable so don't include it.
-       #
-       # We could try to replicate the windows.h definitions required by
-       # GL/gl.h, but the build time savings don't compensate the constant
-       # headaches that brings, so instead we force windows.h to be included
-       # on every file.
-       if (MSVC)
-               add_definitions (-FIwindows.h)
-       else (MSVC)
-               add_definitions (--include windows.h)
-       endif (MSVC)
-
        # MSVC & MinGW only define & use APIENTRY
        add_definitions (-DGLAPIENTRY=__stdcall)
-
-       link_libraries (winmm)
 endif (WIN32)
 
 if (MSVC)
@@ -54,6 +36,8 @@ if (MSVC)
        add_definitions (-wd4244) # conversion from 'type1' to 'type2', possible loss of data
        add_definitions (-wd4505) # unreferenced local function has been removed
        add_definitions (-wd4800) # forcing value to bool 'true' or 'false' (performance warning)
+       # XXX: it's safer to use ssize_t everywhere instead of disabling warning
+       add_definitions (-wd4018) # signed/unsigned mismatch
        
        # Use static runtime
        # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
@@ -65,8 +49,14 @@ if (MSVC)
                        string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
                endif (${flag_var} MATCHES "/MD")
        endforeach (flag_var)
+    
+    # C99 headers
+    include_directories (c99)
 else ()
+       # Adjust warnings
        add_definitions (-Wall)
+       # XXX: it's safer to use ssize_t everywhere instead of disabling warning
+       add_definitions (-Wno-sign-compare) # comparison between signed and unsigned integer expressions
 endif ()
 
 # Use bundled ZLIB if system one can't be found
@@ -100,48 +90,48 @@ if (WIN32)
        set (LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/wrappers)
 
        # d3d8.dll
-       if (DirectX_D3D8_FOUND)
-               include_directories (${DirectX_D3D8_INCLUDE_DIR})
-               add_custom_command (
-                       OUTPUT d3d8.cpp
-                       COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8.cpp
-                       DEPENDS d3d8.py d3d8types.py d3d8caps.py windows.py base.py
-               )
-               add_library (d3d8 SHARED d3d8.def d3d8.cpp log.cpp os_win32.cpp)
-               set_target_properties (d3d8 PROPERTIES PREFIX "")
-       endif (DirectX_D3D8_FOUND)
+    #if (DirectX_D3D8_FOUND)
+       #       include_directories (${DirectX_D3D8_INCLUDE_DIR})
+       #       add_custom_command (
+       #               OUTPUT d3d8.cpp
+       #               COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d8.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d8.cpp
+       #               DEPENDS d3d8.py d3d8types.py d3d8caps.py winapi.py stdapi.py
+       #       )
+       #       add_library (d3d8 SHARED d3d8.def d3d8.cpp trace_write.cpp os_win32.cpp)
+       #       set_target_properties (d3d8 PROPERTIES PREFIX "")
+       #endif (DirectX_D3D8_FOUND)
 
        # d3d9.dll
-       if (DirectX_D3DX9_FOUND)
-               include_directories (${DirectX_D3DX9_INCLUDE_DIR})
-               add_custom_command (
-                       OUTPUT d3d9.cpp
-                       COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9.cpp
-                       DEPENDS d3d9.py d3d9types.py d3d9caps.py d3dshader.py windows.py base.py
-               )
-               add_library (d3d9 SHARED d3d9.def d3d9.cpp log.cpp os_win32.cpp)
-               set_target_properties (d3d9 PROPERTIES PREFIX "")
-       endif (DirectX_D3DX9_FOUND)
+    #if (DirectX_D3DX9_FOUND)
+       #       include_directories (${DirectX_D3DX9_INCLUDE_DIR})
+       #       add_custom_command (
+       #               OUTPUT d3d9.cpp
+       #               COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d9.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d9.cpp
+       #               DEPENDS d3d9.py d3d9types.py d3d9caps.py d3dshader.py winapi.py stdapi.py
+       #       )
+       #       add_library (d3d9 SHARED d3d9.def d3d9.cpp trace_write.cpp os_win32.cpp)
+       #       set_target_properties (d3d9 PROPERTIES PREFIX "")
+       #endif (DirectX_D3DX9_FOUND)
 
        # d3d10.dll
-       if (DirectX_D3D10_FOUND)
-               include_directories (${DirectX_D3D10_INCLUDE_DIR})
-               add_custom_command (
-                       OUTPUT d3d10.cpp
-                       COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10misc.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10.cpp
-                       DEPENDS d3d10misc.py windows.py base.py
-               )
-               add_library (d3d10 SHARED d3d10.def d3d10.cpp log.cpp os_win32.cpp)
-               set_target_properties (d3d10 PROPERTIES PREFIX "")
-       endif (DirectX_D3D10_FOUND)
+       #if (DirectX_D3D10_FOUND)
+       #       include_directories (${DirectX_D3D10_INCLUDE_DIR})
+       #       add_custom_command (
+       #               OUTPUT d3d10.cpp
+       #               COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10misc.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10.cpp
+       #               DEPENDS d3d10misc.py winapi.py stdapi.py
+       #       )
+       #       add_library (d3d10 SHARED d3d10.def d3d10.cpp trace_write.cpp os_win32.cpp)
+       #       set_target_properties (d3d10 PROPERTIES PREFIX "")
+       #endif (DirectX_D3D10_FOUND)
 
        # opengl32.dll
        add_custom_command (
                OUTPUT opengl32.cpp
-               COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/opengl32.py > ${CMAKE_CURRENT_BINARY_DIR}/opengl32.cpp
-               DEPENDS opengl32.py gl.py windows.py base.py
+               COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/wgltrace.py > ${CMAKE_CURRENT_BINARY_DIR}/opengl32.cpp
+               DEPENDS wgltrace.py trace.py wglapi.py glapi.py glenum.py winapi.py stdapi.py
        )
-       add_library (opengl SHARED opengl32.def opengl32.cpp log.cpp os_win32.cpp)
+       add_library (opengl SHARED opengl32.def opengl32.cpp trace_write.cpp os_win32.cpp)
        set_target_properties (opengl PROPERTIES
                PREFIX ""
                OUTPUT_NAME opengl32)
@@ -153,39 +143,50 @@ else ()
 
        # libGL.so
        add_custom_command (
-               OUTPUT glx.cpp
-               COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glx.py > ${CMAKE_CURRENT_BINARY_DIR}/glx.cpp
-               DEPENDS glx.py gl.py dl.py base.py
+               OUTPUT glxtrace.cpp
+               COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glxtrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glxtrace.cpp
+               DEPENDS glxtrace.py trace.py glxapi.py glapi.py glenum.py stdapi.py
        )
-       add_library (glxtrace SHARED glx.cpp log.cpp os_posix.cpp)
+
+       add_library (glxtrace SHARED glxtrace.cpp trace_write.cpp os_posix.cpp)
        set_target_properties (glxtrace PROPERTIES PREFIX "")
        target_link_libraries (glxtrace dl)
 endif ()
 
 add_executable (dump dump.cpp trace_model.cpp)
 
+if (WIN32)
+    set (os os_win32.cpp)
+else (WIN32)
+    set (os os_posix.cpp)
+endif (WIN32)
+
+if (GLUT_INCLUDE_DIR)
+       add_custom_command (
+               OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
+               COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glproc.py > ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
+               DEPENDS glproc.py wglapi.py glxapi.py glapi.py glenum.py stdapi.py
+       )
 
-if (GLEW_INCLUDE_DIR)
        add_custom_command (
                OUTPUT glretrace.cpp
                COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace.cpp
-               DEPENDS glretrace.py glx.py gl.py dl.py base.py
+               DEPENDS glretrace.py retrace.py codegen.py glapi.py glenum.py stdapi.py
        )
 
        include_directories (
+               ${CMAKE_CURRENT_BINARY_DIR}
                ${OPENGL_INCLUDE_PATH}
                ${GLUT_INCLUDE_DIR}
-               ${GLEW_INCLUDE_DIR}
        )
 
-       add_executable (glretrace glretrace.cpp trace_model.cpp)
+       add_executable (glretrace glretrace.cpp trace_model.cpp ${os} ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp)
 
        target_link_libraries (glretrace
                ${OPENGL_gl_LIBRARY}
                ${OPENGL_glu_LIBRARY}
                ${GLUT_glut_LIBRARY}
-               ${GLEW_glew_LIBRARY}
        )
-endif (GLEW_INCLUDE_DIR)
+endif (GLUT_INCLUDE_DIR)