2018-06-26 20:36:20 +00:00
|
|
|
# ~~~
|
2019-07-19 00:17:34 +00:00
|
|
|
# Copyright (c) 2014-2019 Valve Corporation
|
|
|
|
# Copyright (c) 2014-2019 LunarG, Inc.
|
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.
|
|
|
|
# ~~~
|
|
|
|
|
2019-07-16 21:11:25 +00:00
|
|
|
cmake_minimum_required(VERSION 3.10.2)
|
2018-04-18 17:46:21 +00:00
|
|
|
|
2018-09-20 18:12:14 +00:00
|
|
|
# Apple: Must be set before enable_language() or project() as it may influence configuration of the toolchain and flags.
|
2018-04-18 17:46:21 +00:00
|
|
|
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.12" CACHE STRING "Minimum OS X deployment version")
|
|
|
|
|
2018-05-13 16:59:16 +00:00
|
|
|
project(Vulkan-Loader)
|
2018-09-20 18:12:14 +00:00
|
|
|
|
2019-06-06 17:19:15 +00:00
|
|
|
enable_testing()
|
|
|
|
|
2019-09-18 21:39:34 +00:00
|
|
|
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS API_NAME="Vulkan")
|
2014-07-24 14:36:15 +00:00
|
|
|
|
2020-03-17 18:11:59 +00:00
|
|
|
# Enable beta Vulkan extensions
|
|
|
|
add_definitions(-DVK_ENABLE_BETA_EXTENSIONS)
|
|
|
|
|
2016-12-07 23:13:35 +00:00
|
|
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
2019-07-19 00:17:34 +00:00
|
|
|
find_package(PythonInterp 3 QUIET)
|
2015-12-15 16:25:29 +00:00
|
|
|
|
2020-02-19 02:40:29 +00:00
|
|
|
if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/external/googletest)
|
|
|
|
option(BUILD_TESTS "Build Tests" ON)
|
|
|
|
else()
|
|
|
|
option(BUILD_TESTS "Build Tests" OFF)
|
2020-04-01 19:26:02 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(APPLE)
|
|
|
|
option(BUILD_STATIC_LOADER "Build a loader that can be statically linked" OFF)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(BUILD_STATIC_LOADER)
|
2020-10-05 22:58:04 +00:00
|
|
|
message(WARNING "The BUILD_STATIC_LOADER option has been set. Note that this will only work on MacOS and is not supported "
|
2020-04-01 19:26:02 +00:00
|
|
|
"or tested as part of the loader. Use it at your own risk.")
|
2020-02-19 02:40:29 +00:00
|
|
|
endif()
|
|
|
|
|
2019-02-08 04:53:48 +00:00
|
|
|
if (TARGET Vulkan::Headers)
|
|
|
|
message(STATUS "Using Vulkan headers from Vulkan::Headers target")
|
2019-07-27 17:13:37 +00:00
|
|
|
get_target_property(VulkanHeaders_INCLUDE_DIRS Vulkan::Headers INTERFACE_INCLUDE_DIRECTORIES)
|
2019-02-08 04:53:48 +00:00
|
|
|
get_target_property(VulkanRegistry_DIR Vulkan::Registry INTERFACE_INCLUDE_DIRECTORIES)
|
|
|
|
else()
|
|
|
|
find_package(VulkanHeaders)
|
|
|
|
if(NOT ${VulkanHeaders_FOUND})
|
|
|
|
message(FATAL_ERROR "Could not find Vulkan headers path. This can be fixed by setting VULKAN_HEADERS_INSTALL_DIR to an "
|
|
|
|
"installation of the Vulkan-Headers repository.")
|
|
|
|
endif()
|
|
|
|
if(NOT ${VulkanRegistry_FOUND})
|
|
|
|
message(FATAL_ERROR "Could not find Vulkan registry path. This can be fixed by setting VULKAN_HEADERS_INSTALL_DIR to an "
|
|
|
|
"installation of the Vulkan-Headers repository.")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# set up the Vulkan::Headers target for consistency
|
|
|
|
add_library(vulkan-headers INTERFACE)
|
2020-06-19 10:19:08 +00:00
|
|
|
target_include_directories(vulkan-headers SYSTEM INTERFACE "${VulkanHeaders_INCLUDE_DIRS}")
|
2019-02-08 04:53:48 +00:00
|
|
|
add_library(Vulkan::Headers ALIAS vulkan-headers)
|
2018-09-20 18:12:14 +00:00
|
|
|
endif()
|
2018-05-31 20:18:40 +00:00
|
|
|
|
2017-10-31 23:05:03 +00:00
|
|
|
option(USE_CCACHE "Use ccache" OFF)
|
2018-06-30 18:07:29 +00:00
|
|
|
if(USE_CCACHE)
|
2017-10-31 23:05:03 +00:00
|
|
|
find_program(CCACHE_FOUND ccache)
|
|
|
|
if(CCACHE_FOUND)
|
|
|
|
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
|
2018-09-20 18:12:14 +00:00
|
|
|
endif()
|
2017-10-31 23:05:03 +00:00
|
|
|
endif()
|
|
|
|
|
2018-05-25 17:37:20 +00:00
|
|
|
include(GNUInstallDirs)
|
2018-09-20 18:12:14 +00:00
|
|
|
|
|
|
|
if(UNIX AND NOT APPLE) # i.e.: Linux
|
|
|
|
include(FindPkgConfig)
|
2018-05-25 17:37:20 +00:00
|
|
|
endif()
|
|
|
|
|
2017-12-12 15:33:01 +00:00
|
|
|
if(APPLE)
|
2018-06-30 18:07:29 +00:00
|
|
|
# CMake versions 3 or later need CMAKE_MACOSX_RPATH defined. This avoids the CMP0042 policy message.
|
2017-12-12 15:33:01 +00:00
|
|
|
set(CMAKE_MACOSX_RPATH 1)
|
|
|
|
endif()
|
|
|
|
|
2018-09-20 18:12:14 +00:00
|
|
|
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_BINARY_DIR}/install" CACHE PATH "default install path" FORCE)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# 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)
|
2018-06-30 18:07:29 +00:00
|
|
|
set(
|
|
|
|
FALLBACK_CONFIG_DIRS "/etc/xdg"
|
|
|
|
CACHE
|
|
|
|
STRING
|
|
|
|
"Search path to use when XDG_CONFIG_DIRS is unset or empty or the current process is SUID/SGID. Default is freedesktop compliant."
|
|
|
|
)
|
|
|
|
set(
|
|
|
|
FALLBACK_DATA_DIRS "/usr/local/share:/usr/share"
|
|
|
|
CACHE
|
|
|
|
STRING
|
|
|
|
"Search path to use when XDG_DATA_DIRS is unset or empty or the current process is SUID/SGID. Default is freedesktop compliant."
|
|
|
|
)
|
2019-06-25 08:53:21 +00:00
|
|
|
set(
|
|
|
|
SYSCONFDIR ""
|
|
|
|
CACHE
|
|
|
|
STRING
|
|
|
|
"System-wide search directory. If not set or empty, CMAKE_INSTALL_FULL_SYSCONFDIR and /etc are used."
|
|
|
|
)
|
2017-12-12 15:33:01 +00:00
|
|
|
endif()
|
2017-02-19 19:14:24 +00:00
|
|
|
|
2018-09-20 18:12:14 +00:00
|
|
|
if(UNIX AND NOT APPLE) # i.e.: Linux
|
2016-02-20 16:13:28 +00:00
|
|
|
option(BUILD_WSI_XCB_SUPPORT "Build XCB WSI support" ON)
|
2016-04-12 19:35:51 +00:00
|
|
|
option(BUILD_WSI_XLIB_SUPPORT "Build Xlib WSI support" ON)
|
2016-12-07 17:19:21 +00:00
|
|
|
option(BUILD_WSI_WAYLAND_SUPPORT "Build Wayland WSI support" ON)
|
2020-07-04 20:53:59 +00:00
|
|
|
option(BUILD_WSI_DIRECTFB_SUPPORT "Build DirectFB WSI support" OFF)
|
2021-03-13 00:17:03 +00:00
|
|
|
option(BUILD_WSI_SCREEN_QNX_SUPPORT "Build QNX Screen WSI support" OFF)
|
2015-11-25 20:26:15 +00:00
|
|
|
|
2018-06-30 18:07:29 +00:00
|
|
|
if(BUILD_WSI_XCB_SUPPORT)
|
2016-12-07 23:13:35 +00:00
|
|
|
find_package(XCB REQUIRED)
|
|
|
|
endif()
|
|
|
|
|
2018-06-30 18:07:29 +00:00
|
|
|
if(BUILD_WSI_XLIB_SUPPORT)
|
2016-12-07 23:13:35 +00:00
|
|
|
find_package(X11 REQUIRED)
|
|
|
|
endif()
|
|
|
|
|
2018-06-30 18:07:29 +00:00
|
|
|
if(BUILD_WSI_WAYLAND_SUPPORT)
|
2016-12-07 23:13:35 +00:00
|
|
|
find_package(Wayland REQUIRED)
|
2020-06-19 10:19:08 +00:00
|
|
|
include_directories(SYSTEM ${WAYLAND_CLIENT_INCLUDE_DIR})
|
2016-12-07 23:13:35 +00:00
|
|
|
endif()
|
2020-07-04 20:53:59 +00:00
|
|
|
|
|
|
|
if(BUILD_WSI_DIRECTFB_SUPPORT)
|
|
|
|
find_package(DirectFB REQUIRED)
|
|
|
|
include_directories(SYSTEM ${DIRECTFB_INCLUDE_DIR})
|
|
|
|
endif()
|
2021-03-11 03:17:20 +00:00
|
|
|
|
2021-03-13 00:17:03 +00:00
|
|
|
if(BUILD_WSI_SCREEN_QNX_SUPPORT)
|
2021-03-11 03:17:20 +00:00
|
|
|
# Part of OS, no additional include directories are required
|
|
|
|
endif()
|
2018-05-09 20:07:11 +00:00
|
|
|
endif()
|
2017-06-12 17:23:57 +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
|
|
|
|
2018-09-20 18:12:14 +00:00
|
|
|
option(BUILD_LOADER "Build loader" ON)
|
|
|
|
|
2018-06-30 18:07:29 +00:00
|
|
|
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
|
2019-09-18 21:39:34 +00:00
|
|
|
set(COMMON_COMPILE_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers")
|
2015-02-05 21:14:33 +00:00
|
|
|
set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -fno-strict-aliasing -fno-builtin-memcmp")
|
2017-07-12 16:06:19 +00:00
|
|
|
|
2018-06-30 18:07:29 +00:00
|
|
|
# For GCC version 7.1 or greater, we need to disable the implicit fallthrough warning since there's no consistent way to satisfy
|
|
|
|
# all compilers until they all accept the C++17 standard
|
2019-09-18 21:39:34 +00:00
|
|
|
if(CMAKE_COMPILER_IS_GNUCC)
|
|
|
|
set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -Wno-stringop-truncation -Wno-stringop-overflow")
|
|
|
|
if(CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL 7.1)
|
|
|
|
set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -Wimplicit-fallthrough=0")
|
|
|
|
endif()
|
2017-07-12 16:06:19 +00:00
|
|
|
endif()
|
|
|
|
|
2018-06-30 18:07:29 +00:00
|
|
|
if(APPLE)
|
2017-12-12 15:33:01 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_COMPILE_FLAGS}")
|
2019-09-18 21:39:34 +00:00
|
|
|
#clang-cl on Windows
|
|
|
|
elseif((CMAKE_C_COMPILER_ID MATCHES "Clang") AND (CMAKE_CXX_SIMULATE_ID MATCHES "MSVC"))
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Xclang -std=c99 ${COMMON_COMPILE_FLAGS}")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xclang -std=c++11 -fno-rtti")
|
|
|
|
# clang (not clang-cl) or gcc
|
2017-12-12 15:33:01 +00:00
|
|
|
else()
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 ${COMMON_COMPILE_FLAGS}")
|
2019-09-18 21:39:34 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-rtti")
|
2017-12-12 15:33:01 +00:00
|
|
|
endif()
|
2019-09-18 21:39:34 +00:00
|
|
|
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_COMPILE_FLAGS}")
|
|
|
|
|
2018-06-30 18:07:29 +00:00
|
|
|
if(UNIX)
|
2014-08-04 00:03:57 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
|
2015-01-18 03:09:29 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
|
2014-08-04 00:03:57 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
2014-08-02 01:14:28 +00:00
|
|
|
|
2018-09-20 18:12:14 +00:00
|
|
|
if(MSVC)
|
2018-10-29 21:57:54 +00:00
|
|
|
# /WX: Treat warnings as errors
|
|
|
|
# /GR-: Disable RTTI
|
|
|
|
# /w34456: Warn about nested declarations
|
|
|
|
# /w34701, /w34703: Warn about potentially uninitialized variables
|
|
|
|
# /w34057: Warn about different indirection types.
|
|
|
|
# /w34245: Warn about signed/unsigned mismatch.
|
|
|
|
set(MSVC_LOADER_COMPILE_OPTIONS /WX /GR- /w34456 /w34701 /w34703 /w34057 /w34245)
|
2016-05-12 16:28:57 +00:00
|
|
|
endif()
|
|
|
|
|
2019-07-19 00:17:34 +00:00
|
|
|
# Optional codegen target
|
|
|
|
if(PYTHONINTERP_FOUND)
|
|
|
|
add_custom_target(VulkanLoader_generated_source
|
|
|
|
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/scripts/generate_source.py
|
|
|
|
${VulkanRegistry_DIR} --incremental
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
message("WARNING: VulkanLoader_generated_source target requires python 3")
|
|
|
|
endif()
|
|
|
|
|
2017-01-23 16:08:20 +00:00
|
|
|
|
2018-09-20 18:12:14 +00:00
|
|
|
if(UNIX)
|
2019-09-18 21:39:34 +00:00
|
|
|
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS 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.
|
2019-09-18 21:39:34 +00:00
|
|
|
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS SYSCONFDIR="${SYSCONFDIR}")
|
2019-06-25 08:53:21 +00:00
|
|
|
else()
|
2019-09-18 21:39:34 +00:00
|
|
|
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS 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"))
|
2019-09-18 21:39:34 +00:00
|
|
|
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS 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()
|
|
|
|
|
2017-03-14 23:11:24 +00:00
|
|
|
# uninstall target
|
2018-06-12 21:10:23 +00:00
|
|
|
if(NOT TARGET uninstall)
|
2018-09-20 18:12:14 +00:00
|
|
|
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
|
2018-06-30 18:07:29 +00:00
|
|
|
IMMEDIATE
|
|
|
|
@ONLY)
|
|
|
|
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
|
2018-06-14 22:53:01 +00:00
|
|
|
set_target_properties(uninstall PROPERTIES FOLDER ${LOADER_HELPER_FOLDER})
|
2018-06-12 21:10:23 +00:00
|
|
|
endif()
|
2016-10-12 23:36:35 +00:00
|
|
|
|
2015-10-10 15:43:07 +00:00
|
|
|
if(BUILD_LOADER)
|
|
|
|
add_subdirectory(loader)
|
|
|
|
endif()
|
|
|
|
|
2020-04-08 21:28:22 +00:00
|
|
|
add_subdirectory(external)
|
2015-07-09 23:31:46 +00:00
|
|
|
if(BUILD_TESTS)
|
2018-05-09 23:40:36 +00:00
|
|
|
add_subdirectory(tests)
|
2017-10-13 15:26:20 +00:00
|
|
|
endif()
|