blob: a45ddcca5c9501c2990596bf3f288d8b99cfe58e [file] [log] [blame]
# The name of our project is "VULKAN". CMakeLists files in this project can
# refer to the root source directory of the project as ${VULKAN_SOURCE_DIR} and
# to the root binary directory of the project as ${VULKAN_BINARY_DIR}.
cmake_minimum_required(VERSION 2.8.11)
# This must come before the project command.
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.12" CACHE STRING "Minimum OS X deployment version")
project (Vulkan-ValidationLayers)
# set (CMAKE_VERBOSE_MAKEFILE 1)
# The API_NAME allows renaming builds to avoid conflicts with installed SDKs
# The MAJOR number of the version we're building, used in naming
# <api-name>-<major>.dll (and other files).
set(API_NAME "Vulkan" CACHE STRING "API name to use when building")
set(MAJOR "1")
string(TOLOWER ${API_NAME} API_LOWERCASE)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# if CMAKE 3.7+, use FindVulkan
if (NOT CMAKE_VERSION VERSION_LESS 3.7.0)
message(STATUS "Using find_package to locate Vulkan")
find_package(Vulkan)
endif()
find_package(PythonInterp 3 REQUIRED)
option(USE_CCACHE "Use ccache" OFF)
if (USE_CCACHE)
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)
endif()
if(APPLE)
# CMake versions 3 or later need CMAKE_MACOSX_RPATH defined.
# This avoids the CMP0042 policy message.
set(CMAKE_MACOSX_RPATH 1)
# The "install" target for MacOS fixes up bundles in place.
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR})
endif()
# Enable cmake folders
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(LVL_TARGET_FOLDER lvl_cmake_targets)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
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.")
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
include(FindPkgConfig)
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_MIR_SUPPORT "Build Mir WSI support" OFF)
set(DEMOS_WSI_SELECTION "XCB" CACHE STRING "Select WSI target for demos (XCB, XLIB, WAYLAND, MIR, DISPLAY)")
if (BUILD_WSI_XCB_SUPPORT)
find_package(XCB REQUIRED)
endif()
if (BUILD_WSI_XLIB_SUPPORT)
find_package(X11 REQUIRED)
endif()
if (BUILD_WSI_WAYLAND_SUPPORT)
find_package(Wayland REQUIRED)
include_directories(${WAYLAND_CLIENT_INCLUDE_DIR})
endif()
if (BUILD_WSI_MIR_SUPPORT)
find_package(Mir REQUIRED)
endif()
# This option can be used to suppress the installation of artifacts from the
# Vulkan-LoaderAndValidationLayers repo while running "make install" for the
# VulkanTools and VulkanSamples repos. This can be used to prevent the
# overwriting of LVL artifacts when installing these downstream repos.
option(INSTALL_LVL_FILES "Install content from LoaderAndValidationLayers repo" ON)
endif()
# TODO: Add option to override this with env var, or even to use SDK
set(VULKAN_HEADERS_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/Vulkan-Headers")
if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
set(COMMON_COMPILE_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers")
set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -fno-strict-aliasing -fno-builtin-memcmp")
# 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
if (CMAKE_COMPILER_IS_GNUCC AND NOT (CMAKE_CXX_COMPILER_VERSION LESS 7.1))
set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -Wimplicit-fallthrough=0")
endif()
if (APPLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_COMPILE_FLAGS}")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 ${COMMON_COMPILE_FLAGS}")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_COMPILE_FLAGS} -std=c++11 -fno-rtti")
if (UNIX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
endif()
endif()
if(WIN32)
# Treat warnings as errors
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/WX>")
# Disable RTTI
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/GR->")
# Warn about nested declarations
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/w34456>")
# Warn about potentially uninitialized variables
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/w34701>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/w34703>")
# Warn about different indirection types.
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/w34057>")
# Warn about signed/unsigned mismatch.
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/w34245>")
endif()
if(NOT WIN32)
set (BUILDTGT_DIR build)
set (BINDATA_DIR Bin)
set (LIBSOURCE_DIR Lib)
else()
# is WIN32
option(ENABLE_WIN10_ONECORE "Link the loader with OneCore umbrella libraries" OFF)
# For Windows, since 32-bit and 64-bit items can co-exist, we build each in its own build directory.
# 32-bit target data goes in build32, and 64-bit target data goes into build. So, include/link the
# appropriate data at build time.
if (DISABLE_BUILDTGT_DIR_DECORATION)
set (BUILDTGT_DIR "")
set (BINDATA_DIR "")
set (LIBSOURCE_DIR "")
elseif (CMAKE_CL_64)
set (BUILDTGT_DIR build)
set (BINDATA_DIR Bin)
set (LIBSOURCE_DIR Lib)
else()
set (BUILDTGT_DIR build32)
set (BINDATA_DIR Bin32)
set (LIBSOURCE_DIR Lib32)
endif()
endif()
option(BUILD_TESTS "Build tests" ON)
option(BUILD_LAYERS "Build layers" ON)
set(VULKAN_SDK $ENV{VULKAN_SDK})
find_program(GLSLANG_VALIDATOR NAMES glslangValidator
HINTS "${EXTERNAL_SOURCE_ROOT}/glslang/${BUILDTGT_DIR}/install/bin"
"${VULKAN_SDK}/${BINDATA_DIR}"
"${GLSLANG_BINARY_ROOT}/StandAlone"
"${PROJECT_SOURCE_DIR}/external/${BINDATA_DIR}")
find_path(GLSLANG_SPIRV_INCLUDE_DIR SPIRV/spirv.hpp
HINTS "${EXTERNAL_SOURCE_ROOT}/glslang"
"${CMAKE_SOURCE_DIR}/../glslang"
"${VULKAN_SDK}/include/vulkan"
DOC "Path to SPIRV/spirv.hpp")
message("XXXXXXXXXXXXXX vksdkpath = ${VULKAN_SDK}")
find_path(SPIRV_TOOLS_INCLUDE_DIR spirv-tools/libspirv.h
HINTS "${EXTERNAL_SOURCE_ROOT}/glslang/External/spirv-tools/include"
"${CMAKE_SOURCE_DIR}/../glslang/External/spirv-tools/include"
"${VULKAN_SDK}/spirv-tools/include"
DOC "Path to spirv-tools/libspirv.h")
set (PYTHON_CMD ${PYTHON_EXECUTABLE})
if(NOT WIN32)
include(GNUInstallDirs)
add_definitions(-DFALLBACK_CONFIG_DIRS="${FALLBACK_CONFIG_DIRS}")
add_definitions(-DFALLBACK_DATA_DIRS="${FALLBACK_DATA_DIRS}")
add_definitions(-DSYSCONFDIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}")
# Make sure /etc is searched by the loader
if(NOT (CMAKE_INSTALL_FULL_SYSCONFDIR STREQUAL "/etc"))
add_definitions(-DEXTRASYSCONFDIR="/etc")
endif()
endif()
if(UNIX)
if(INSTALL_LVL_FILES)
install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/vulkan" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/vk_layer_dispatch_table.h" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/vulkan")
endif()
# uninstall target
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()
add_definitions(-DAPI_NAME="${API_NAME}")
if(BUILD_TESTS)
add_subdirectory(tests)
endif()
if(BUILD_LAYERS)
add_subdirectory(layers)
endif()