tools/spec: specify target platforms via command line argument

This commit is contained in:
Danny Robson 2018-08-23 13:56:12 +10:00
parent 0a15b518b1
commit 4bd6cc648e
2 changed files with 25 additions and 9 deletions

View File

@ -18,6 +18,15 @@ endif ()
include_directories ("${CMAKE_CURRENT_BINARY_DIR}") include_directories ("${CMAKE_CURRENT_BINARY_DIR}")
if (WIN32)
set(VK_PLATFORM "win32")
elseif(LINUX)
set(VK_PLATFORM "xcb")
else()
message(FATAL_ERROR "unhandled platform")
endif()
##----------------------------------------------------------------------------- ##-----------------------------------------------------------------------------
add_custom_command ( add_custom_command (
OUTPUT OUTPUT
@ -27,8 +36,9 @@ COMMENT
COMMAND COMMAND
"${PYTHON_EXECUTABLE}" "${PYTHON_EXECUTABLE}"
"${CMAKE_CURRENT_SOURCE_DIR}/tools/spec.py" "${CMAKE_CURRENT_SOURCE_DIR}/tools/spec.py"
"${CMAKE_CURRENT_SOURCE_DIR}/specs/xml/vk.xml" "--src" "${CMAKE_CURRENT_SOURCE_DIR}/specs/xml/vk.xml"
"${CMAKE_CURRENT_BINARY_DIR}/vk.hpp" "--dst" "${CMAKE_CURRENT_BINARY_DIR}/vk.hpp"
"--platform" "${VK_PLATFORM}"
DEPENDS DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/tools/spec.py" "${CMAKE_CURRENT_SOURCE_DIR}/tools/spec.py"
"${CMAKE_CURRENT_SOURCE_DIR}/specs/xml/vk.xml" "${CMAKE_CURRENT_SOURCE_DIR}/specs/xml/vk.xml"

View File

@ -42,7 +42,7 @@ class registry:
return result return result
def serialise(self, platform:str): def serialise(self, platform:Set[str]):
required = [] required = []
for (_,f) in self.features.items(): for (_,f) in self.features.items():
@ -490,18 +490,18 @@ class extension(type):
else: else:
raise "Unknown extension node" raise "Unknown extension node"
def apply(self, reg:registry, platform:str): def apply(self, reg:registry, platform:Set[str]):
if self.name in reg.applied: if self.name in reg.applied:
return [] return []
reg.applied.add(self.name) reg.applied.add(self.name)
if self.platform and self.platform != platform: if self.platform and self.platform not in platform:
return [] return []
required = [] required = []
for dep in self.depends: for dep in self.depends:
required = reg.extensions[dep].apply (reg, platform) required = reg.extensions[dep].apply(reg, platform)
logging.info("Applying extension:", self.name, file=sys.stderr) logging.info("Applying extension:", self.name, file=sys.stderr)
for node in self.requires: for node in self.requires:
@ -650,8 +650,14 @@ if __name__ == '__main__':
logging.getLogger().setLevel(logging.WARNING) logging.getLogger().setLevel(logging.WARNING)
parser = argparse.ArgumentParser(description='Transform XML API specification into C++ headers') parser = argparse.ArgumentParser(description='Transform XML API specification into C++ headers')
parser.add_argument('src', type=str, help='the path to the XML file to transform') parser.add_argument('--src', type=str, help='the path to the XML file to transform')
parser.add_argument('dst', type=str, help='the output path for the result') parser.add_argument('--dst', type=str, help='the output path for the result')
parser.add_argument(
'--platform',
type=str,
action='append',
help='a platform to generate output for. may be specific multiple times"'
)
args = parser.parse_args() args = parser.parse_args()
@ -681,7 +687,7 @@ if __name__ == '__main__':
#reg.extensions['VK_KHR_surface'].apply(reg, platform='xcb') #reg.extensions['VK_KHR_surface'].apply(reg, platform='xcb')
extensions = ["VK_KHR_swapchain", "VK_EXT_debug_report", "VK_KHR_external_memory"] extensions = ["VK_KHR_swapchain", "VK_EXT_debug_report", "VK_KHR_external_memory"]
q = reg.serialise(platform='xcb') q = reg.serialise(args.platform)
dst.write("#pragma once\n") dst.write("#pragma once\n")