CMake: Add DirectX 9 support

This commit is contained in:
Sam Edwards 2018-11-01 21:51:26 -06:00
parent f7b59f6e55
commit 5b973ed837
6 changed files with 175 additions and 12 deletions

View File

@ -0,0 +1,104 @@
# Filename: FindDirect3D9.cmake
# Authors: CFSworks (26 Oct, 2018)
#
# Usage:
# find_package(Direct3D9 [REQUIRED] [QUIET])
#
# This supports the following components:
# d3dx9
# dxerr
# dxguid
#
# Once done this will define:
# DIRECT3D9_FOUND - system has Direct3D 9.x
# DIRECT3D9_INCLUDE_DIR - the include directory containing d3d9.h - note that
# this will be empty if it's part of the Windows SDK.
# DIRECT3D9_LIBRARY - the path to d3d9.lib
# DIRECT3D9_LIBRARIES - the path to d3d9.lib and all extra component
# libraries
#
include(CheckIncludeFile)
if(Direct3D9_FIND_QUIETLY)
if(DEFINED CMAKE_REQUIRED_QUIET)
set(_OLD_CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET})
endif()
# Suppress check_include_file messages
set(CMAKE_REQUIRED_QUIET ON)
endif()
check_include_file("d3d9.h" SYSTEM_INCLUDE_D3D9_H)
mark_as_advanced(SYSTEM_INCLUDE_D3D9_H)
if(Direct3D9_FIND_QUIETLY)
if(DEFINED _OLD_CMAKE_REQUIRED_QUIET)
set(CMAKE_REQUIRED_QUIET ${_OLD_CMAKE_REQUIRED_QUIET})
unset(_OLD_CMAKE_REQUIRED_QUIET)
else()
unset(CMAKE_REQUIRED_QUIET)
endif()
endif()
if(SYSTEM_INCLUDE_D3D9_H
AND NOT Direct3D9_FIND_REQUIRED_d3dx9
AND NOT Direct3D9_FIND_REQUIRED_dxerr)
# It's available as #include <d3d9.h> - easy enough. We'll use "." as a way
# of saying "We found it, but please erase this variable later."
set(DIRECT3D9_INCLUDE_DIR ".")
# Since d3d9.h is on the search path, we can pretty much assume d3d9.lib is
# as well.
set(DIRECT3D9_LIBRARY "d3d9.lib")
# And dxguid.lib, why not
set(DIRECT3D9_dxguid_LIBRARY "dxguid.lib")
else()
# We could not find it easily - maybe it's installed separately as part of
# the DirectX SDK?
find_path(DIRECT3D9_INCLUDE_DIR
NAMES d3d9.h
PATHS "$ENV{DXSDK_DIR}/Include")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(dx_lib_path "$ENV{DXSDK_DIR}/Lib/x64/")
else()
set(dx_lib_path "$ENV{DXSDK_DIR}/Lib/x86/")
endif()
find_library(DIRECT3D9_LIBRARY d3d9 "${dx_lib_path}" NO_DEFAULT_PATH)
find_library(DIRECT3D9_d3dx9_LIBRARY d3dx9 "${dx_lib_path}" NO_DEFAULT_PATH)
find_library(DIRECT3D9_dxerr_LIBRARY dxerr "${dx_lib_path}" NO_DEFAULT_PATH)
find_library(DIRECT3D9_dxguid_LIBRARY dxguid "${dx_lib_path}" NO_DEFAULT_PATH)
unset(dx_lib_path)
endif()
mark_as_advanced(DIRECT3D9_INCLUDE_DIR DIRECT3D9_LIBRARY)
set(DIRECT3D9_LIBRARIES "${DIRECT3D9_LIBRARY}")
foreach(_component d3dx9 dxerr dxguid)
if(DIRECT3D9_${_component}_LIBRARY)
set(Direct3D9_${_component}_FOUND ON)
list(FIND Direct3D9_FIND_COMPONENTS "${_component}" _index)
if(${_index} GREATER -1)
list(APPEND DIRECT3D9_LIBRARIES "${DIRECT3D9_${_component}_LIBRARY}")
endif()
unset(_index)
endif()
endforeach(_component)
unset(_component)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Direct3D9 HANDLE_COMPONENTS
REQUIRED_VARS DIRECT3D9_INCLUDE_DIR DIRECT3D9_LIBRARY DIRECT3D9_LIBRARIES)
# See above - if we found the include as part of the system path, we don't want
# to actually modify the include search path, but we need a non-empty string to
# satisfy find_package_handle_standard_args()
if(DIRECT3D9_INCLUDE_DIR STREQUAL ".")
set(DIRECT3D9_INCLUDE_DIR "")
endif()

View File

@ -155,12 +155,6 @@ endif()
# Now go through all the packages and report whether we have them.
show_packages()
if(HAVE_DX9)
message("+ DirectX9")
else()
message("- Did not find DirectX9")
endif()
if(HAVE_TINYDISPLAY)
message("+ Tinydisplay")
else()

View File

@ -427,9 +427,9 @@ if(HAVE_GLX AND NOT HAVE_GLX_AVAILABLE)
endif()
if(HAVE_GLX)
config_package(X11 "X11 (with GLX)")
config_package(X11 "X11" "with GLX")
else()
config_package(X11 "X11 (without GLX)")
config_package(X11 "X11" "without GLX")
endif()
# EGL
@ -441,14 +441,20 @@ package_option(EGL
config_package(EGL "EGL")
# Direct3D 9
find_package(Direct3D9 QUIET COMPONENTS dxguid dxerr d3dx9)
package_option(DX9
"Enable support for DirectX 9. This is typically only viable on Windows."
FOUND_AS DIRECT3D9)
config_package(DX9 "Direct3D 9.x")
########
# TODO #
########
# Find and configure DirectX 9
#find_package(DX9)
#config_package(DX9 COMMENT "DirectX9")
# Find and configure OpenCV
#find_package(OpenCV)
#config_package(OPENCV COMMENT "OpenCV")

View File

@ -16,6 +16,7 @@ add_subdirectory(src/dgraph)
add_subdirectory(src/display)
add_subdirectory(src/downloader)
add_subdirectory(src/downloadertools)
add_subdirectory(src/dxgsg9)
add_subdirectory(src/dxml)
add_subdirectory(src/egg)
add_subdirectory(src/egg2pg)
@ -68,6 +69,7 @@ add_subdirectory(src/physics)
# Include panda metalibs
add_subdirectory(metalibs/panda)
add_subdirectory(metalibs/pandadx9)
add_subdirectory(metalibs/pandaegg)
add_subdirectory(metalibs/pandaexpress)
add_subdirectory(metalibs/pandagl)

View File

@ -0,0 +1,9 @@
if(NOT HAVE_DX9)
return()
endif()
add_metalib(pandadx9 ${MODULE_TYPE} pandadx9.cxx
COMPONENTS p3dxgsg9)
set_target_properties(pandadx9 PROPERTIES DEFINE_SYMBOL BUILDING_PANDADX)
install(TARGETS pandadx9 DESTINATION ${MODULE_DESTINATION})

View File

@ -0,0 +1,48 @@
if(NOT HAVE_DX9)
return()
endif()
set(P3DXGSG9_HEADERS
config_dxgsg9.h
dxGeomMunger9.h dxGeomMunger9.I
dxGraphicsDevice9.h
dxGraphicsStateGuardian9.h dxGraphicsStateGuardian9.I
dxgsg9base.h
dxIndexBufferContext9.h dxIndexBufferContext9.I
dxOcclusionQueryContext9.h dxOcclusionQueryContext9.I
dxShaderContext9.h dxShaderContext9.I
dxTextureContext9.h dxTextureContext9.I
dxVertexBufferContext9.h dxVertexBufferContext9.I
vertexElementArray.h
wdxGraphicsBuffer9.h wdxGraphicsBuffer9.I
wdxGraphicsPipe9.h wdxGraphicsPipe9.I
wdxGraphicsWindow9.h wdxGraphicsWindow9.I
)
set(P3DXGSG9_SOURCES
config_dxgsg9.cxx
dxGeomMunger9.cxx
dxGraphicsDevice9.cxx
dxGraphicsStateGuardian9.cxx
dxIndexBufferContext9.cxx
dxOcclusionQueryContext9.cxx
dxShaderContext9.cxx
dxTextureContext9.cxx
dxVertexBufferContext9.cxx
vertexElementArray.cxx
wdxGraphicsBuffer9.cxx
wdxGraphicsPipe9.cxx
wdxGraphicsWindow9.cxx
)
composite_sources(p3dxgsg9 P3DXGSG9_SOURCES)
add_component_library(p3dxgsg9 SYMBOL BUILDING_PANDADX
${P3DXGSG9_HEADERS} ${P3DXGSG9_SOURCES})
target_link_libraries(p3dxgsg9 p3windisplay panda
PKG::CG PKG::DX9)
target_compile_definitions(p3dxgsg9 PRIVATE USE_GENERIC_DXERR_LIBRARY) # FIXME
if(NOT BUILD_METALIBS)
install(TARGETS p3dxgsg9 DESTINATION lib RUNTIME DESTINATION bin)
endif()
install(FILES ${P3DXGSG9_HEADERS} DESTINATION include/panda3d)