From 72715369dda902ae2ae7407693603cbc6e23e5d8 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 6 Jun 2016 01:39:56 -0700 Subject: [PATCH] Make inclusion into external projects easier --- CMakeLists.txt | 78 +++++++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7685410..5a210b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,42 +28,56 @@ cmake_minimum_required(VERSION 3.2) project(VulkanHppGenerator) -file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/Vulkan-Docs/src/spec/vk.xml vk_spec) -string(REPLACE "\\" "\\\\" vk_spec ${vk_spec}) -add_definitions(-DVK_SPEC="${vk_spec}") +# 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") -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}) add_definitions(-DVULKAN_HPP="${vulkan_hpp}") -set(HEADERS -) - -set(SOURCES - VulkanHppGenerator.cpp -) - -set(TINYXML2_SOURCES - tinyxml2/tinyxml2.cpp -) - -set(TINYXML2_HEADERS - tinyxml2/tinyxml2.h -) - -source_group(headers FILES ${HEADERS}) +# Create the executable project +set(SOURCES VulkanHppGenerator.cpp) source_group(sources FILES ${SOURCES}) - -source_group(TinyXML2\\headers FILES ${TINYXML2_HEADERS}) -source_group(TinyXML2\\sources FILES ${TINYXML2_SOURCES}) - -add_executable(VulkanHppGenerator - ${HEADERS} - ${SOURCES} - ${TINYXML2_SOURCES} - ${TINYXML2_HEADERS} -) - +add_executable(VulkanHppGenerator ${SOURCES} ) 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= -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")