2018-06-26 20:36:20 +00:00
# ~~~
2024-05-13 07:01:37 +00:00
# Copyright (c) 2014-2023 Valve Corporation
# Copyright (c) 2014-2023 LunarG, Inc.
# Copyright (c) 2021-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# Copyright (c) 2023-2023 RasterGrid Kft.
2018-06-26 20:36:20 +00:00
#
# 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.
# ~~~
2024-05-13 07:01:37 +00:00
cmake_minimum_required ( VERSION 3.17.2 )
2018-06-26 20:36:20 +00:00
2024-05-13 07:01:37 +00:00
project ( VULKAN_LOADER VERSION 1.3.275 LANGUAGES C )
2018-04-18 17:46:21 +00:00
2024-05-13 07:01:37 +00:00
# This variable enables downstream users to customize the target API
# variant (e.g. Vulkan SC)
set ( API_TYPE "vulkan" )
2018-04-18 17:46:21 +00:00
2024-05-13 07:01:37 +00:00
add_subdirectory ( scripts )
2021-09-21 17:37:14 +00:00
2024-05-13 07:01:37 +00:00
set ( CMAKE_C_STANDARD 99 )
set ( CMAKE_C_STANDARD_REQUIRED ON )
set ( CMAKE_C_EXTENSIONS OFF )
set ( CMAKE_C_VISIBILITY_PRESET "hidden" )
set ( CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" )
2018-09-20 18:12:14 +00:00
2024-05-13 07:01:37 +00:00
# By default, loader & tests are built without sanitizers
# Use these options to force a specific sanitizer on the loader and test executables
if ( UNIX )
option ( LOADER_ENABLE_ADDRESS_SANITIZER "Linux & macOS only: Advanced memory checking" OFF )
option ( LOADER_ENABLE_THREAD_SANITIZER "Linux & macOS only: Advanced thread checking" OFF )
2020-04-01 19:26:02 +00:00
endif ( )
2021-09-18 00:00:18 +00:00
if ( WIN32 )
# Optional: Allow specify the exact version used in the loader dll
# Format is major.minor.patch.build
set ( BUILD_DLL_VERSIONINFO "" CACHE STRING "Set the version to be used in the loader.rc file. Default value is the currently generated header version" )
endif ( )
2024-05-13 07:01:37 +00:00
find_package ( VulkanHeaders CONFIG QUIET )
2017-10-31 23:05:03 +00:00
2018-05-25 17:37:20 +00:00
include ( GNUInstallDirs )
2018-09-20 18:12:14 +00:00
2022-05-03 19:53:07 +00:00
set ( GIT_BRANCH_NAME "--unknown--" )
set ( GIT_TAG_INFO "--unknown--" )
2021-08-17 02:01:25 +00:00
find_package ( Git )
2022-05-03 19:53:07 +00:00
if ( GIT_FOUND AND EXISTS "${CMAKE_CURRENT_LIST_DIR}/.git/HEAD" )
2021-08-17 02:01:25 +00:00
execute_process (
C O M M A N D $ { G I T _ E X E C U T A B L E } d e s c r i b e - - t a g s - - a l w a y s
2022-05-03 19:53:07 +00:00
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ C U R R E N T _ L I S T _ D I R }
2021-08-17 02:01:25 +00:00
O U T P U T _ V A R I A B L E G I T _ T A G _ I N F O )
string ( REGEX REPLACE "\n$" "" GIT_TAG_INFO "${GIT_TAG_INFO}" )
2022-05-03 19:53:07 +00:00
file ( READ "${CMAKE_CURRENT_LIST_DIR}/.git/HEAD" GIT_HEAD_REF_INFO )
2021-08-17 02:01:25 +00:00
if ( GIT_HEAD_REF_INFO )
string ( REGEX MATCH "ref: refs/heads/(.*)" _ ${ GIT_HEAD_REF_INFO } )
if ( CMAKE_MATCH_1 )
set ( GIT_BRANCH_NAME ${ CMAKE_MATCH_1 } )
else ( )
set ( GIT_BRANCH_NAME ${ GIT_HEAD_REF_INFO } )
endif ( )
string ( REGEX REPLACE "\n$" "" GIT_BRANCH_NAME "${GIT_BRANCH_NAME}" )
endif ( )
endif ( )
2018-09-20 18:12:14 +00:00
# Enable IDE GUI folders. "Helper targets" that don't have interesting source code should set their FOLDER property to this
2018-02-01 16:27:03 +00:00
set_property ( GLOBAL PROPERTY USE_FOLDERS ON )
2018-06-14 22:53:01 +00:00
set ( LOADER_HELPER_FOLDER "Helper Targets" )
2018-02-01 16:27:03 +00:00
2018-09-20 18:12:14 +00:00
if ( UNIX )
2022-02-16 19:27:13 +00:00
set ( FALLBACK_CONFIG_DIRS "/etc/xdg" CACHE STRING
" S e a r c h p a t h t o u s e w h e n X D G _ C O N F I G _ D I R S i s u n s e t o r e m p t y o r t h e c u r r e n t p r o c e s s i s S U I D / S G I D . D e f a u l t i s f r e e d e s k t o p c o m p l i a n t . " )
set ( FALLBACK_DATA_DIRS "/usr/local/share:/usr/share" CACHE STRING
" S e a r c h p a t h t o u s e w h e n X D G _ D A T A _ D I R S i s u n s e t o r e m p t y o r t h e c u r r e n t p r o c e s s i s S U I D / S G I D . D e f a u l t i s f r e e d e s k t o p c o m p l i a n t . " )
set ( SYSCONFDIR "" CACHE STRING
" S y s t e m - w i d e s e a r c h d i r e c t o r y . I f n o t s e t o r e m p t y , C M A K E _ I N S T A L L _ F U L L _ S Y S C O N F D I R a n d / e t c a r e u s e d . " )
2017-12-12 15:33:01 +00:00
endif ( )
2017-02-19 19:14:24 +00:00
2018-05-09 20:07:11 +00:00
if ( WIN32 )
option ( ENABLE_WIN10_ONECORE "Link the loader with OneCore umbrella libraries" OFF )
2016-12-07 23:13:35 +00:00
endif ( )
2015-01-10 15:15:51 +00:00
2024-05-13 07:01:37 +00:00
add_library ( platform_wsi INTERFACE )
2021-11-03 19:51:03 +00:00
if ( WIN32 )
2024-05-13 07:01:37 +00:00
target_compile_definitions ( platform_wsi INTERFACE VK_USE_PLATFORM_WIN32_KHR )
2021-11-03 19:51:03 +00:00
elseif ( ANDROID )
2024-05-13 07:01:37 +00:00
message ( FATAL_ERROR "Android build not supported!" )
2021-11-03 19:51:03 +00:00
elseif ( APPLE )
2024-05-13 07:01:37 +00:00
target_compile_definitions ( platform_wsi INTERFACE VK_USE_PLATFORM_METAL_EXT )
if ( IOS )
target_compile_definitions ( platform_wsi INTERFACE VK_USE_PLATFORM_IOS_MVK )
endif ( )
if ( CMAKE_SYSTEM_NAME STREQUAL "Darwin" )
target_compile_definitions ( platform_wsi INTERFACE VK_USE_PLATFORM_MACOS_MVK )
endif ( )
elseif ( CMAKE_SYSTEM_NAME MATCHES "Linux|BSD|DragonFly|GNU" )
option ( BUILD_WSI_XCB_SUPPORT "Build XCB WSI support" ON )
option ( BUILD_WSI_XLIB_SUPPORT "Build Xlib WSI support" ON )
option ( BUILD_WSI_WAYLAND_SUPPORT "Build Wayland WSI support" ON )
option ( BUILD_WSI_DIRECTFB_SUPPORT "Build DirectFB WSI support" OFF )
find_package ( PkgConfig REQUIRED QUIET ) # Use PkgConfig to find Linux system libraries
2021-11-03 19:51:03 +00:00
if ( BUILD_WSI_XCB_SUPPORT )
2024-05-13 07:01:37 +00:00
pkg_check_modules ( XCB REQUIRED QUIET IMPORTED_TARGET xcb )
target_compile_definitions ( platform_wsi INTERFACE VK_USE_PLATFORM_XCB_KHR )
target_link_libraries ( platform_wsi INTERFACE PkgConfig::XCB )
2021-11-03 19:51:03 +00:00
endif ( )
if ( BUILD_WSI_XLIB_SUPPORT )
2024-05-13 07:01:37 +00:00
pkg_check_modules ( X11 REQUIRED QUIET IMPORTED_TARGET x11 )
target_compile_definitions ( platform_wsi INTERFACE VK_USE_PLATFORM_XLIB_KHR VK_USE_PLATFORM_XLIB_XRANDR_EXT )
target_link_libraries ( platform_wsi INTERFACE PkgConfig::X11 )
2021-11-03 19:51:03 +00:00
endif ( )
if ( BUILD_WSI_WAYLAND_SUPPORT )
2024-05-13 07:01:37 +00:00
target_compile_definitions ( platform_wsi INTERFACE VK_USE_PLATFORM_WAYLAND_KHR )
2021-11-03 19:51:03 +00:00
endif ( )
if ( BUILD_WSI_DIRECTFB_SUPPORT )
2024-05-13 07:01:37 +00:00
pkg_check_modules ( DirectFB QUIET REQUIRED IMPORTED_TARGET directfb )
target_compile_definitions ( platform_wsi INTERFACE VK_USE_PLATFORM_DIRECTFB_EXT )
target_link_libraries ( platform_wsi INTERFACE PkgConfig::DirectFB )
endif ( )
elseif ( CMAKE_SYSTEM_NAME MATCHES "QNX" )
message ( FATAL_ERROR "See BUILD.md for QNX build" )
elseif ( CMAKE_SYSTEM_NAME MATCHES "Fuchsia" )
message ( FATAL_ERROR "Fuchsia uses Chromium build. See BUILD.gn" )
2021-11-03 19:51:03 +00:00
else ( )
message ( FATAL_ERROR "Unsupported Platform!" )
endif ( )
2021-11-03 19:55:29 +00:00
add_library ( loader_common_options INTERFACE )
2024-05-13 07:01:37 +00:00
target_link_libraries ( loader_common_options INTERFACE platform_wsi )
2021-11-03 19:55:29 +00:00
# Enable beta Vulkan extensions
target_compile_definitions ( loader_common_options INTERFACE VK_ENABLE_BETA_EXTENSIONS )
2024-05-13 07:01:37 +00:00
option ( BUILD_WERROR "Enable warnings as errors" )
2022-03-30 16:25:58 +00:00
2022-03-29 05:50:33 +00:00
# Set warnings as errors and the main diagnostic flags
# Must be set first so the warning silencing later on works properly
# Note that clang-cl.exe should use MSVC flavor flags, not GNU
2024-05-13 07:01:37 +00:00
if ( CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR ( CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "MSVC" ) )
if ( BUILD_WERROR )
2022-03-30 16:25:58 +00:00
target_compile_options ( loader_common_options INTERFACE /WX )
endif ( )
target_compile_options ( loader_common_options INTERFACE /W4 )
2024-05-13 07:01:37 +00:00
elseif ( CMAKE_C_COMPILER_ID MATCHES "GNU|Clang" )
2022-03-29 05:50:33 +00:00
# using GCC or Clang with the regular front end
2024-05-13 07:01:37 +00:00
if ( BUILD_WERROR )
2022-03-30 16:25:58 +00:00
target_compile_options ( loader_common_options INTERFACE -Werror )
endif ( )
target_compile_options ( loader_common_options INTERFACE -Wall -Wextra )
2022-03-29 05:50:33 +00:00
endif ( )
2024-05-13 07:01:37 +00:00
if ( CMAKE_C_COMPILER_ID MATCHES "GNU|Clang" )
target_compile_options ( loader_common_options INTERFACE -Wno-missing-field-initializers )
2017-07-12 16:06:19 +00:00
2024-05-13 07:01:37 +00:00
if ( CMAKE_C_COMPILER_ID STREQUAL "GNU" )
2021-11-03 19:55:29 +00:00
target_compile_options ( loader_common_options INTERFACE -Wno-stringop-truncation -Wno-stringop-overflow )
2024-05-13 07:01:37 +00:00
if ( CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 7.1 )
target_compile_options ( loader_common_options INTERFACE -Wshadow=local ) #only added in GCC 7
2019-09-18 21:39:34 +00:00
endif ( )
2017-07-12 16:06:19 +00:00
endif ( )
2021-11-03 19:55:29 +00:00
target_compile_options ( loader_common_options INTERFACE -Wpointer-arith )
2014-08-04 00:03:57 +00:00
endif ( )
2014-08-02 01:14:28 +00:00
2024-05-13 07:01:37 +00:00
if ( CMAKE_C_COMPILER_ID MATCHES "MSVC" OR ( CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "MSVC" ) )
# /sdl: Enable additional security checks
2018-10-29 21:57:54 +00:00
# /GR-: Disable RTTI
2022-02-16 20:24:26 +00:00
# /guard:cf: Enable control flow guard
2022-03-29 05:50:33 +00:00
# /wd4152: Disable warning on conversion of a function pointer to a data pointer
# /wd4201: Disable warning on anonymous struct/unions
2024-05-13 07:01:37 +00:00
target_compile_options ( loader_common_options INTERFACE /sdl /GR- /guard:cf /wd4152 /wd4201 )
2022-02-16 20:24:26 +00:00
# Enable control flow guard
2024-05-13 07:01:37 +00:00
target_link_options ( loader_common_options INTERFACE "LINKER:/guard:cf" )
2021-11-03 19:55:29 +00:00
# Prevent <windows.h> from polluting the code. guards against things like MIN and MAX
target_compile_definitions ( loader_common_options INTERFACE WIN32_LEAN_AND_MEAN )
2016-05-12 16:28:57 +00:00
endif ( )
2021-11-03 20:09:50 +00:00
# DEBUG enables runtime loader ICD verification
# Add git branch and tag info in debug mode
2022-05-03 19:53:07 +00:00
target_compile_definitions ( loader_common_options INTERFACE $< $<CONFIG:DEBUG > :DEBUG;GIT_BRANCH_NAME= "${GIT_BRANCH_NAME}" ;GIT_TAG_INFO= "${GIT_TAG_INFO}" > )
2021-11-03 20:09:50 +00:00
2024-05-13 07:01:37 +00:00
if ( NOT ( WIN32 OR APPLE ) )
# Check for the existance of the secure_getenv or __secure_getenv commands
include ( CheckFunctionExists )
2022-03-09 21:54:58 +00:00
2024-05-13 07:01:37 +00:00
check_function_exists ( secure_getenv HAVE_SECURE_GETENV )
check_function_exists ( __secure_getenv HAVE___SECURE_GETENV )
2022-03-09 21:54:58 +00:00
2024-05-13 07:01:37 +00:00
if ( HAVE_SECURE_GETENV )
target_compile_definitions ( loader_common_options INTERFACE HAVE_SECURE_GETENV )
endif ( )
if ( HAVE___SECURE_GETENV )
target_compile_definitions ( loader_common_options INTERFACE HAVE___SECURE_GETENV )
endif ( )
if ( NOT ( HAVE_SECURE_GETENV OR HAVE___SECURE_GETENV ) )
message ( WARNING "Using non-secure environmental lookups. This loader will not properly disable environent variables when run with elevated permissions." )
endif ( )
2022-03-09 21:54:58 +00:00
endif ( )
2024-05-13 07:01:37 +00:00
option ( LOADER_CODEGEN "Enable vulkan loader code generation" )
if ( LOADER_CODEGEN )
find_package ( Python3 REQUIRED )
add_custom_target ( loader_codegen
C O M M A N D P y t h o n 3 : : I n t e r p r e t e r $ { P R O J E C T _ S O U R C E _ D I R } / s c r i p t s / g e n e r a t e _ s o u r c e . p y
" $ { V U L K A N _ H E A D E R S _ I N S T A L L _ D I R } / $ { C M A K E _ I N S T A L L _ D A T A D I R } / v u l k a n / r e g i s t r y "
- - g e n e r a t e d - v e r s i o n $ { V u l k a n H e a d e r s _ V E R S I O N } - - i n c r e m e n t a l - - a p i $ { A P I _ T Y P E }
)
2019-07-19 00:17:34 +00:00
endif ( )
2018-09-20 18:12:14 +00:00
if ( UNIX )
2022-02-17 04:44:09 +00:00
target_compile_definitions ( loader_common_options INTERFACE FALLBACK_CONFIG_DIRS= "${FALLBACK_CONFIG_DIRS}" FALLBACK_DATA_DIRS= "${FALLBACK_DATA_DIRS}" )
2017-02-19 19:14:24 +00:00
2019-06-25 08:53:21 +00:00
if ( NOT ( SYSCONFDIR STREQUAL "" ) )
# SYSCONFDIR is specified, use it and do not force /etc.
2022-02-17 04:44:09 +00:00
target_compile_definitions ( loader_common_options INTERFACE SYSCONFDIR= "${SYSCONFDIR}" )
2019-06-25 08:53:21 +00:00
else ( )
2022-02-17 04:44:09 +00:00
target_compile_definitions ( loader_common_options INTERFACE SYSCONFDIR= "${CMAKE_INSTALL_FULL_SYSCONFDIR}" )
2019-06-25 08:53:21 +00:00
# Make sure /etc is searched by the loader
if ( NOT ( CMAKE_INSTALL_FULL_SYSCONFDIR STREQUAL "/etc" ) )
2022-02-17 04:44:09 +00:00
target_compile_definitions ( loader_common_options INTERFACE EXTRASYSCONFDIR= "/etc" )
2019-06-25 08:53:21 +00:00
endif ( )
2016-10-22 19:20:29 +00:00
endif ( )
2014-10-03 21:34:53 +00:00
endif ( )
2022-02-16 19:26:07 +00:00
add_subdirectory ( loader )
2015-10-10 15:43:07 +00:00
2024-05-13 07:01:37 +00:00
option ( BUILD_TESTS "Build Tests" )
if ( BUILD_TESTS )
enable_testing ( )
add_subdirectory ( tests )
2017-10-13 15:26:20 +00:00
endif ( )