2016-02-16 14:07:55 +00:00
# Copyright(c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of NVIDIA CORPORATION nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cmake_minimum_required ( VERSION 3.2 )
2016-06-21 08:35:47 +00:00
project ( VulkanHppGenerator )
2016-02-16 14:07:55 +00:00
2016-06-06 08:39:56 +00:00
# If you wish to target a specific version of the spec, override this value like so
# cmake -DVK_SPEC_URL:STRING=https://example.com/some/other/url/vk.xml
set ( VK_SPEC_URL "https://raw.githubusercontent.com/KhronosGroup/Vulkan-Docs/1.0/src/spec/vk.xml" CACHE STRING "URL from which to fetch the Vulkan Spec XML" )
2016-04-12 09:36:14 +00:00
2016-06-06 08:39:56 +00:00
# Download the request URL specification
file ( DOWNLOAD ${ VK_SPEC_URL } ${ CMAKE_CURRENT_BINARY_DIR } /vk.xml )
2016-02-16 14:07:55 +00:00
2016-06-06 08:39:56 +00:00
# Populate a preprocessor define with the location of the spec
file ( TO_NATIVE_PATH ${ CMAKE_CURRENT_BINARY_DIR } /vk.xml VK_SPEC )
string ( REPLACE "\\" "\\\\" VK_SPEC ${ VK_SPEC } )
add_definitions ( -DVK_SPEC= "${VK_SPEC}" )
2016-02-16 14:07:55 +00:00
2016-06-06 08:39:56 +00:00
# Populate a preprocessor define with the desire output location
file ( TO_NATIVE_PATH ${ CMAKE_CURRENT_BINARY_DIR } /vulkan.hpp vulkan_hpp )
string ( REPLACE "\\" "\\\\" vulkan_hpp ${ vulkan_hpp } )
add_definitions ( -DVULKAN_HPP= "${vulkan_hpp}" )
2016-02-16 14:07:55 +00:00
2016-06-06 08:39:56 +00:00
# Create the executable project
set ( SOURCES VulkanHppGenerator.cpp )
2016-02-16 14:07:55 +00:00
source_group ( sources FILES ${ SOURCES } )
2016-06-06 08:39:56 +00:00
add_executable ( VulkanHppGenerator ${ SOURCES } )
set_property ( TARGET VulkanHppGenerator PROPERTY CXX_STANDARD 11 )
2016-02-16 14:07:55 +00:00
2016-06-06 08:39:56 +00:00
if ( WIN32 )
include ( ExternalProject )
# Fetch and build tinyxml in order to parse the specification
ExternalProject_Add (
t i n y x m l 2
D O W N L O A D _ N A M E t i n y x m l 2 - c 8 d a d 9 5 d 4 4 8 8 6 6 3 c 0 3 8 1 d 5 0 2 b 3 2 7 4 d f 7 d b f 2 f c 5 5 . z i p
U R L h t t p s : / / c o d e l o a d . g i t h u b . c o m / l e e t h o m a s o n / t i n y x m l 2 / z i p / c 8 d a d 9 5 d 4 4 8 8 6 6 3 c 0 3 8 1 d 5 0 2 b 3 2 7 4 d f 7 d b f 2 f c 5 5
U R L _ M D 5 6 9 8 4 b 6 5 5 c a e 1 c d 4 b 5 4 f c c a e b f e 2 3 b 3 5 c
C M A K E _ A R G S - D C M A K E _ I N S T A L L _ P R E F I X : P A T H = < I N S T A L L _ D I R > - D B U I L D _ S H A R E D _ L I B S : B O O L = O F F - D B U I L D _ S T A T I C _ L I B S : B O O L = O N
L O G _ D O W N L O A D 1
)
# Grab the include path and library and store them
ExternalProject_Get_Property ( tinyxml2 INSTALL_DIR )
# Make sure tinyxml build first, and is available to the generator
add_dependencies ( VulkanHppGenerator tinyxml2 )
target_include_directories ( VulkanHppGenerator PRIVATE ${ INSTALL_DIR } /include )
target_link_libraries ( VulkanHppGenerator ${ INSTALL_DIR } /lib/tinyxml2.lib )
else ( )
include ( FindPkgConfig )
pkg_check_modules ( TINYXML2 REQUIRED tinyxml2 )
link_directories ( ${ TINYXML2_LIBDIR } )
target_include_directories ( VulkanHppGenerator PRIVATE ${ TINYXML2_INCLUDEDIR } )
target_link_libraries ( VulkanHppGenerator ${ TINYXML2_LIBRARIES } )
endif ( )
2016-02-16 14:07:55 +00:00
2016-06-06 08:39:56 +00:00
# Execute the generator
add_custom_command ( TARGET VulkanHppGenerator POST_BUILD COMMAND VulkanHppGenerator )
2016-02-16 14:07:55 +00:00
2016-06-06 08:39:56 +00:00
# Install the output file to the destination
install ( FILES "${CMAKE_CURRENT_BINARY_DIR}/vulkan.hpp" DESTINATION "include/vulkan" )