cmake: Cleanup CMake code

Remove version.cmake / install.cmake / cmake_uninstall.cmake

Remove as much maintenace burden / custom code as possible
This commit is contained in:
Juan Ramos 2022-12-09 11:18:29 -07:00 committed by Juan Ramos
parent bf3b3fb14e
commit d14ccf951f
5 changed files with 69 additions and 142 deletions

View file

@ -44,9 +44,6 @@ indicated by *install_dir*:
- *install_dir*`/share/vulkan/registry` : The registry files found in the
`registry` directory of this repository
The `uninstall` target can be used to remove the above files from the install
directory.
### Usage in CMake
The library provides a Config file for CMake, once installed it can be found via `find_package`.
@ -183,22 +180,12 @@ While still in the build directory:
to build the install target.
Build the `uninstall` target to remove the files from the install directory.
cmake --build . --target uninstall
#### Build the Solution With Visual Studio
Launch Visual Studio and open the "Vulkan-Headers.sln" solution file in the
build directory. Build the `INSTALL` target from the Visual Studio solution
explorer.
Build the `uninstall` target to remove the files from the install directory.
> Note: Since there are only the `INSTALL` and `uninstall` projects in the
> solution, building the solution from the command line may be more efficient
> than starting Visual Studio for these simple operations.
## Building On Linux
### Linux Development Environment Requirements
@ -273,14 +260,6 @@ or
cmake --build . --target install
To uninstall the files from the install directories, you can execute:
make uninstall
or
cmake --build . --target uninstall
## Building on MacOS
The instructions for building this repository on MacOS are similar to those for Linux.

View file

@ -15,7 +15,35 @@
# limitations under the License.
# ~~~
cmake_minimum_required(VERSION 3.10.2)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.cmake)
# 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()
project(Vulkan-Headers LANGUAGES C VERSION ${VK_VERSION_STRING})
message(STATUS "${PROJECT_NAME} = ${PROJECT_VERSION}")
@ -34,5 +62,44 @@ string(COMPARE EQUAL ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR} PROJECT_IS_
option(VULKAN_HEADERS_INSTALL "Install Vulkan Headers" ${PROJECT_IS_TOP_LEVEL})
if (VULKAN_HEADERS_INSTALL)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/install.cmake)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
# Location registry files will be installed to
set(VLK_REGISTRY_DIR "${CMAKE_INSTALL_DATADIR}/vulkan")
# Install header files
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/vk_video" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/vulkan" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# Install registry files
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/registry" DESTINATION ${VLK_REGISTRY_DIR})
set(export_name "VulkanHeadersConfig")
set(namespace "Vulkan::")
set(cmake_files_install_dir ${CMAKE_INSTALL_DATADIR}/cmake/VulkanHeaders/)
# Set EXPORT_NAME for consistency with established names. The CMake generated ones won't work.
set_target_properties(Vulkan-Headers PROPERTIES EXPORT_NAME "Headers")
set_target_properties(Vulkan-Registry PROPERTIES EXPORT_NAME "Registry")
# Add find_package() support
target_include_directories(Vulkan-Headers INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
install(TARGETS Vulkan-Headers EXPORT ${export_name})
target_include_directories(Vulkan-Registry INTERFACE $<INSTALL_INTERFACE:${VLK_REGISTRY_DIR}/registry>)
install(TARGETS Vulkan-Registry EXPORT ${export_name})
install(EXPORT ${export_name} NAMESPACE ${namespace} DESTINATION ${cmake_files_install_dir})
export(TARGETS Vulkan-Headers NAMESPACE ${namespace} FILE ${export_name}.cmake)
set(config_version "${CMAKE_CURRENT_BINARY_DIR}/${export_name}Version.cmake")
# Add find_package() versioning support
if(${CMAKE_VERSION} VERSION_LESS "3.14.0")
write_basic_package_version_file(${config_version} COMPATIBILITY SameMajorVersion)
else()
write_basic_package_version_file(${config_version} COMPATIBILITY SameMajorVersion ARCH_INDEPENDENT)
endif()
install(FILES ${config_version} DESTINATION ${cmake_files_install_dir})
endif()

View file

@ -1,21 +0,0 @@
if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
string(REGEX REPLACE "\n" ";" files "${files}")
foreach(file ${files})
message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
exec_program(
"@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
OUTPUT_VARIABLE rm_out
RETURN_VALUE rm_retval
)
if(NOT "${rm_retval}" STREQUAL 0)
message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
endif(NOT "${rm_retval}" STREQUAL 0)
else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
endforeach(file)

View file

@ -1,54 +0,0 @@
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
if(WIN32 AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
# Windows: if install locations not set by user, set install prefix to "<build_dir>\install".
set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/install" CACHE PATH "default install path" FORCE)
endif()
# uninstall target
if(NOT TARGET uninstall)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE
@ONLY)
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()
# Location registry files will be installed to
set(VLK_REGISTRY_DIR "${CMAKE_INSTALL_DATADIR}/vulkan")
# Install header files
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/vk_video" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/vulkan" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# Install registry files
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/registry" DESTINATION ${VLK_REGISTRY_DIR})
set(export_name "VulkanHeadersConfig")
set(namespace "Vulkan::")
set(cmake_files_install_dir ${CMAKE_INSTALL_DATADIR}/cmake/VulkanHeaders/)
# Set EXPORT_NAME for consistency with established names. The CMake generated ones won't work.
set_target_properties(Vulkan-Headers PROPERTIES EXPORT_NAME "Headers")
set_target_properties(Vulkan-Registry PROPERTIES EXPORT_NAME "Registry")
# Add find_package() support
target_include_directories(Vulkan-Headers INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
install(TARGETS Vulkan-Headers EXPORT ${export_name})
target_include_directories(Vulkan-Registry INTERFACE $<INSTALL_INTERFACE:${VLK_REGISTRY_DIR}/registry>)
install(TARGETS Vulkan-Registry EXPORT ${export_name})
install(EXPORT ${export_name} NAMESPACE ${namespace} DESTINATION ${cmake_files_install_dir})
export(TARGETS Vulkan-Headers NAMESPACE ${namespace} FILE ${export_name}.cmake)
set(config_version "${CMAKE_CURRENT_BINARY_DIR}/${export_name}Version.cmake")
# Add find_package() versioning support
if(${CMAKE_VERSION} VERSION_LESS "3.14.0")
write_basic_package_version_file(${config_version} COMPATIBILITY SameMajorVersion)
else()
write_basic_package_version_file(${config_version} COMPATIBILITY SameMajorVersion ARCH_INDEPENDENT)
endif()
install(FILES ${config_version} DESTINATION ${cmake_files_install_dir})

View file

@ -1,44 +0,0 @@
# ~~~
# 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()