Make inclusion into external projects easier

This commit is contained in:
Brad Davis 2016-06-06 01:39:56 -07:00
parent 1599d46930
commit 72715369dd

View File

@ -28,42 +28,56 @@ cmake_minimum_required(VERSION 3.2)
project(VulkanHppGenerator) project(VulkanHppGenerator)
file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/Vulkan-Docs/src/spec/vk.xml vk_spec) # If you wish to target a specific version of the spec, override this value like so
string(REPLACE "\\" "\\\\" vk_spec ${vk_spec}) # cmake -DVK_SPEC_URL:STRING=https://example.com/some/other/url/vk.xml
add_definitions(-DVK_SPEC="${vk_spec}") 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")
file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/vulkan/vulkan.hpp vulkan_hpp) # Download the request URL specification
file(DOWNLOAD ${VK_SPEC_URL} ${CMAKE_CURRENT_BINARY_DIR}/vk.xml )
# 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}")
# 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}) string(REPLACE "\\" "\\\\" vulkan_hpp ${vulkan_hpp})
add_definitions(-DVULKAN_HPP="${vulkan_hpp}") add_definitions(-DVULKAN_HPP="${vulkan_hpp}")
set(HEADERS # Create the executable project
) set(SOURCES VulkanHppGenerator.cpp)
set(SOURCES
VulkanHppGenerator.cpp
)
set(TINYXML2_SOURCES
tinyxml2/tinyxml2.cpp
)
set(TINYXML2_HEADERS
tinyxml2/tinyxml2.h
)
source_group(headers FILES ${HEADERS})
source_group(sources FILES ${SOURCES}) source_group(sources FILES ${SOURCES})
add_executable(VulkanHppGenerator ${SOURCES} )
source_group(TinyXML2\\headers FILES ${TINYXML2_HEADERS})
source_group(TinyXML2\\sources FILES ${TINYXML2_SOURCES})
add_executable(VulkanHppGenerator
${HEADERS}
${SOURCES}
${TINYXML2_SOURCES}
${TINYXML2_HEADERS}
)
set_property(TARGET VulkanHppGenerator PROPERTY CXX_STANDARD 11) set_property(TARGET VulkanHppGenerator PROPERTY CXX_STANDARD 11)
target_include_directories(VulkanHppGenerator PRIVATE "${CMAKE_SOURCE_DIR}/tinyxml2") if (WIN32)
include(ExternalProject)
# Fetch and build tinyxml in order to parse the specification
ExternalProject_Add(
tinyxml2
DOWNLOAD_NAME tinyxml2-c8dad95d4488663c0381d502b3274df7dbf2fc55.zip
URL https://codeload.github.com/leethomason/tinyxml2/zip/c8dad95d4488663c0381d502b3274df7dbf2fc55
URL_MD5 6984b655cae1cd4b54fccaebfe23b35c
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> -DBUILD_SHARED_LIBS:BOOL=OFF -DBUILD_STATIC_LIBS:BOOL=ON
LOG_DOWNLOAD 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()
# Execute the generator
add_custom_command(TARGET VulkanHppGenerator POST_BUILD COMMAND VulkanHppGenerator)
# Install the output file to the destination
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/vulkan.hpp" DESTINATION "include/vulkan")