From a742ab929263959909cc54503c6453914a87c693 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Sat, 14 Apr 2012 17:24:14 +0100 Subject: [PATCH] Don't link against d3d9 in runtime. --- retrace/CMakeLists.txt | 3 +- retrace/d3dretrace.py | 2 +- retrace/dllretrace.py | 64 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 retrace/dllretrace.py diff --git a/retrace/CMakeLists.txt b/retrace/CMakeLists.txt index c45b33f..358361e 100644 --- a/retrace/CMakeLists.txt +++ b/retrace/CMakeLists.txt @@ -115,7 +115,7 @@ if (ENABLE_EGL AND X11_FOUND AND NOT WIN32 AND NOT APPLE) install (TARGETS eglretrace RUNTIME DESTINATION bin) endif () -if (WIN32 AND DirectX_D3DX9_FOUND) +if (WIN32 AND DirectX_D3DX9_INCLUDE_DIR) add_custom_command ( OUTPUT d3dretrace_d3d9.cpp COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3dretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3dretrace_d3d9.cpp @@ -140,7 +140,6 @@ if (WIN32 AND DirectX_D3DX9_FOUND) common ${ZLIB_LIBRARIES} ${SNAPPY_LIBRARIES} - ${DirectX_D3D9_LIBRARY} ) endif () diff --git a/retrace/d3dretrace.py b/retrace/d3dretrace.py index f472a0a..ca936f2 100644 --- a/retrace/d3dretrace.py +++ b/retrace/d3dretrace.py @@ -27,7 +27,7 @@ """GL retracer generator.""" -from retrace import Retracer +from dllretrace import DllRetracer as Retracer import specs.stdapi as stdapi from specs.d3d9 import d3d9 diff --git a/retrace/dllretrace.py b/retrace/dllretrace.py new file mode 100644 index 0000000..51e2c68 --- /dev/null +++ b/retrace/dllretrace.py @@ -0,0 +1,64 @@ +########################################################################## +# +# Copyright 2008-2010 VMware, Inc. +# All Rights Reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +##########################################################################/ + + +from retrace import Retracer +from dispatch import Dispatcher + + +class DllRetracer(Retracer): + + def retraceApi(self, api): + print ''' +static HINSTANCE g_hDll = NULL; + +static PROC +__getPublicProcAddress(LPCSTR lpProcName) +{ + if (!g_hDll) { + char szDll[MAX_PATH] = {0}; + + if (!GetSystemDirectoryA(szDll, MAX_PATH)) { + return NULL; + } + + strcat(szDll, "\\\\%s"); + + g_hDll = LoadLibraryA(szDll); + if (!g_hDll) { + return NULL; + } + } + + return GetProcAddress(g_hDll, lpProcName); +} + +''' % api.name + + dispatcher = Dispatcher() + dispatcher.dispatch_api(api) + + Retracer.retraceApi(self, api) + -- 2.43.0