diff options
author | Juan Ramos <[email protected]> | 2022-11-04 12:33:15 -0600 |
---|---|---|
committer | Juan Ramos <[email protected]> | 2022-11-07 10:54:57 -0700 |
commit | 91388ba10409c3a3bf5517de5fed7f2d989930f9 (patch) | |
tree | aa631d25b10c083d7d8505339c6562d18c83eaf2 | |
parent | 52b7c620a5403241aa62c0cd3388384245a8b094 (diff) | |
download | Vulkan-Headers-91388ba10409c3a3bf5517de5fed7f2d989930f9.tar.gz Vulkan-Headers-91388ba10409c3a3bf5517de5fed7f2d989930f9.zip |
cmake: Get Vulkan Version
Extract the vulkan header version for CMake usage
-rw-r--r-- | CMakeLists.txt | 8 | ||||
-rw-r--r-- | cmake/version.cmake | 44 |
2 files changed, 49 insertions, 3 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 50b5d89..92b195c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ # ~~~ -# Copyright (c) 2018 Valve Corporation -# Copyright (c) 2018 LunarG, Inc. +# Copyright (c) 2018-2022 Valve Corporation +# Copyright (c) 2018-2022 LunarG, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,8 +19,10 @@ # This section contains pre-project() initialization, and ends with the project() command. cmake_minimum_required(VERSION 3.10.2) +include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.cmake) -project(Vulkan-Headers LANGUAGES C) +project(Vulkan-Headers LANGUAGES C VERSION ${VK_VERSION_STRING}) +message(STATUS "${PROJECT_NAME} = ${PROJECT_VERSION}") # User-interface declarations ---------------------------------------------------------------------------------------------------- # This section contains variables that affect development GUIs (e.g. CMake GUI and IDEs), such as option(), folders, and variables diff --git a/cmake/version.cmake b/cmake/version.cmake new file mode 100644 index 0000000..6bf1eb3 --- /dev/null +++ b/cmake/version.cmake @@ -0,0 +1,44 @@ +# ~~~ +# Copyright (c) 2022 LunarG, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ~~~ + +# Written as a function to minimize variable scope +# Only VK_VERSION_STRING will be returned to the PARENT_SCOPE +function(vlk_get_header_version) + set(vulkan_core_header_file "${CMAKE_CURRENT_SOURCE_DIR}/include/vulkan/vulkan_core.h") + if (NOT EXISTS ${vulkan_core_header_file}) + message(FATAL_ERROR "Couldn't find vulkan_core.h!") + endif() + + file(READ ${vulkan_core_header_file} ver) + + # Get the major/minor version + if (ver MATCHES "#define[ ]+VK_HEADER_VERSION_COMPLETE[ ]+VK_MAKE_API_VERSION\\([ ]*[0-9]+,[ ]*([0-9]+),[ ]*([0-9]+),[ ]*VK_HEADER_VERSION[ ]*\\)") + set(VK_VERSION_MAJOR "${CMAKE_MATCH_1}") + set(VK_VERSION_MINOR "${CMAKE_MATCH_2}") + else() + message(FATAL_ERROR "Couldn't get major/minor version") + endif() + + # Get the patch version + if (ver MATCHES "#define[ ]+VK_HEADER_VERSION[ ]+([0-9]+)") + set(VK_HEADER_VERSION "${CMAKE_MATCH_1}") + else() + message(FATAL_ERROR "Couldn't get the patch version") + endif() + + set(VK_VERSION_STRING "${VK_VERSION_MAJOR}.${VK_VERSION_MINOR}.${VK_HEADER_VERSION}" PARENT_SCOPE) +endfunction() +vlk_get_header_version() |