]> git.cworth.org Git - apitrace/blobdiff - CMakeLists.txt
tracedump: Add tri-state --color option (auto, always, or never)
[apitrace] / CMakeLists.txt
index 21b46dfebef8b745fda5c835d8512a2ff4939d47..db3d9ab9e67693829783661fd4606d6ebf9b5c19 100755 (executable)
@@ -5,12 +5,16 @@ project (apitrace)
 
 ##############################################################################
 # Options
-#
+
+# On Mac OS X build fat binaries with i386 and x86_64 architectures by default.
+if (APPLE AND NOT CMAKE_OSX_ARCHITECTURES)
+    set (CMAKE_OSX_ARCHITECTURES "i386;x86_64" CACHE STRING "Build architectures for OSX" FORCE)
+endif ()
+
 # We use a cached string variable instead of the standard (boolean) OPTION
 # command so that we can default to auto-detecting optional depencies, while
 # still providing a mechanism to force/disable these optional dependencies, as
 # prescribed in http://www.gentoo.org/proj/en/qa/automagic.xml
-
 set (ENABLE_GUI "AUTO" CACHE STRING "Enable Qt GUI.")
 
 
@@ -32,34 +36,17 @@ if (ENABLE_GUI)
     find_package (QJSON ${REQUIRE_GUI})
 endif ()
 
-if (NOT WIN32)
+if (WIN32)
+    find_package (DirectX)
+elseif (APPLE)
+else ()
     find_package (X11 REQUIRED)
 
-    # On Mac OS X, GLX is provided as a separate OpenGL implementation, different
-    # from the standard OpenGL framework which provides support for native Mac OS X
-    # applications.
-    if (APPLE)
-        find_path (X11_GL_INCLUDE_PATH GL/glx.h ${X11_INC_SEARCH_PATH})
-        if (NOT X11_GL_INCLUDE_PATH)
-            message (SEND_ERROR "Could not find GL/glx.h")
-        endif (NOT X11_GL_INCLUDE_PATH)
-        set (X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${X11_GL_INCLUDE_PATH})
-
-        find_library (X11_GL_LIB GL ${X11_LIB_SEARCH_PATH})
-        if (NOT X11_GL_LIB)
-            message (SEND_ERROR "Could not find libGL.dylib")
-        endif (NOT X11_GL_LIB)
-    else ()
-        set (X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR})
-        set (X11_GL_LIB ${OPENGL_gl_LIBRARY})
-    endif ()
+    set (X11_INCLUDE_DIR ${X11_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR})
+    set (X11_GL_LIB ${OPENGL_gl_LIBRARY})
 
     include_directories (${X11_INCLUDE_DIR})
-endif (NOT WIN32)
-
-if (WIN32)
-    find_package (DirectX)
-endif (WIN32)
+endif ()
 
 
 ##############################################################################
@@ -119,6 +106,22 @@ else ()
     add_definitions (-Wno-sign-compare) # comparison between signed and unsigned integer expressions
 endif ()
 
+if (MINGW)
+    # Avoid depending on MinGW runtime DLLs
+    check_cxx_compiler_flag (-static-libgcc HAVE_STATIC_LIBGCC_FLAG)
+    if (HAVE_STATIC_LIBGCC_FLAG)
+        set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc")
+        set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
+        set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libgcc")
+    endif ()
+    check_cxx_compiler_flag (-static-libstdc++ HAVE_STATIC_LIBSTDCXX_FLAG)
+    if (HAVE_STATIC_LIBSTDCXX_FLAG)
+        set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
+        set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++")
+        set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libstdc++")
+    endif ()
+endif ()
+
 
 # Put all executables into the same top level build directory, regardless of
 # which subdirectory they are declared
@@ -193,13 +196,17 @@ add_custom_command (
 
 if (WIN32)
     set (os os_win32.cpp)
-    set (glws glws_wgl.cpp)
-else (WIN32)
+    set (glws_os glws_wgl.cpp)
+else ()
     set (os os_posix.cpp)
-    set (glws glws_glx.cpp)
-endif (WIN32)
+    if (APPLE)
+        set (glws_os glws_cocoa.mm)
+    else ()
+        set (glws_os glws_glx.cpp)
+    endif ()
+endif ()
 
-add_library (common
+add_library (common STATIC
     common/trace_file.cpp
     common/trace_snappyfile.cpp
     common/trace_model.cpp
@@ -217,7 +224,7 @@ add_library (common
 
 set_target_properties (common PROPERTIES
     # Ensure it can be statically linked in shared libraries
-    COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS}"
+    COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}"
 )
 
 link_libraries (common)
@@ -230,6 +237,11 @@ install (TARGETS tracedump RUNTIME DESTINATION bin)
 # API tracers
 
 if (WIN32)
+    if (MINGW)
+        # Silence warnings about @nn suffix mismatch
+        set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--enable-stdcall-fixup")
+    endif (MINGW)
+
     # ddraw.dll
     if (DirectX_D3D_INCLUDE_DIR)
         include_directories (SYSTEM ${DirectX_D3D_INCLUDE_DIR})
@@ -287,10 +299,14 @@ if (WIN32)
         add_custom_command (
             OUTPUT d3d10trace.cpp
             COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3d10trace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3d10trace.cpp
-            DEPENDS d3d10trace.py trace.py d3d10misc.py specs/d3d10.py specs/dxgi.py specs/winapi.py specs/stdapi.py
+            DEPENDS d3d10trace.py trace.py specs/d3d10misc.py specs/d3d10.py specs/dxgi.py specs/dxgitype.py specs/dxgiformat.py specs/winapi.py specs/stdapi.py
         )
         add_library (d3d10 MODULE specs/d3d10.def d3d10trace.cpp)
-        set_target_properties (d3d10 PROPERTIES PREFIX "")
+        set_target_properties (d3d10
+            PROPERTIES PREFIX ""
+            RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
+            LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
+        )
         install (TARGETS d3d10 LIBRARY DESTINATION wrappers)
     endif (DirectX_D3D10_INCLUDE_DIR)
 
@@ -311,9 +327,6 @@ if (WIN32)
         RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
         LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/wrappers
     )
-    if (MINGW)
-        set_target_properties(wgltrace PROPERTIES LINK_FLAGS "-Wl,--enable-stdcall-fixup")
-    endif (MINGW)
     install (TARGETS wgltrace LIBRARY DESTINATION wrappers)
 
 elseif (APPLE)
@@ -380,7 +393,7 @@ endif ()
 add_custom_command (
     OUTPUT glretrace_gl.cpp
     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/glretrace_gl.cpp
-    DEPENDS glretrace.py retrace.py codegen.py specs/glapi.py specs/gltypes.py specs/stdapi.py
+    DEPENDS glretrace.py retrace.py specs/glapi.py specs/gltypes.py specs/stdapi.py
 )
 
 add_custom_command (
@@ -403,7 +416,9 @@ add_executable (glretrace
     glstate.cpp
     glstate_params.cpp
     retrace.cpp
-    ${glws}
+    retrace_stdc.cpp
+    glws.cpp
+    ${glws_os}
     ${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
 )
 
@@ -420,10 +435,8 @@ target_link_libraries (glretrace
 if (WIN32)
     target_link_libraries (glretrace ${OPENGL_gl_LIBRARY})
 elseif (APPLE)
-    # XXX: We use GLX on MacOSX, which is in a separate library.
     target_link_libraries (glretrace
-        ${X11_GL_LIB}
-        ${X11_X11_LIB}
+        "-framework Cocoa"
         "-framework ApplicationServices" # CGS*
         ${OPENGL_gl_LIBRARY} # CGL*
     )
@@ -454,7 +467,7 @@ install (
         TODO.markdown
     DESTINATION doc)
 
-set (CPACK_PACKAGE_VERSION_MAJOR "1")
+set (CPACK_PACKAGE_VERSION_MAJOR "2")
 set (CPACK_PACKAGE_VERSION_MINOR "0")
 
 # Use current date in YYYYMMDD format as patch number