-# 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.
+# ~~~
+# Copyright (c) 2014-2018 Valve Corporation
+# Copyright (c) 2014-2018 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.
+# ~~~
+
+# CMake project initialization ---------------------------------------------------------------------------------------------------
+# This section contains pre-project() initialization, and ends with the project() command.
+
+cmake_minimum_required(VERSION 3.10.2)
+
+# Apple: Must be set before enable_language() or project() as it may influence configuration of the toolchain and flags.
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.12" CACHE STRING "Minimum OS X deployment version")
-project (VULKAN)
-# set (CMAKE_VERBOSE_MAKEFILE 1)
+project(Vulkan-Tools)
+
+# find_package(), include() and global project settings --------------------------------------------------------------------------
+
+find_package(PythonInterp 3 QUIET)
-# 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)
+# User-interface declarations ----------------------------------------------------------------------------------------------------
+# This section contains variables that affect development GUIs (e.g. CMake GUI and IDEs), such as option(), folders, and variables
+# with the CACHE property.
+
+# Enable beta Vulkan extensions
+add_definitions(-DVK_ENABLE_BETA_EXTENSIONS)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
-find_package(PythonInterp 3 REQUIRED)
-# 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()
+option(BUILD_CUBE "Build cube" ON)
+option(BUILD_VULKANINFO "Build vulkaninfo" ON)
+option(BUILD_ICD "Build icd" ON)
+# Installing the Mock ICD to system directories is probably not desired since this ICD is not a very complete implementation.
+# Require the user to ask that it be installed if they really want it.
+option(INSTALL_ICD "Install icd" OFF)
+
+# Enable IDE GUI folders
+set_property(GLOBAL PROPERTY USE_FOLDERS ON)
+# "Helper" targets that don't have interesting source code should set their FOLDER property to this
+set(TOOLS_HELPER_FOLDER "Helper Targets")
option(USE_CCACHE "Use ccache" OFF)
-if (USE_CCACHE)
+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()
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.")
+# ~~~
+# Find Vulkan Headers and Loader
+# Search order:
+# User-supplied CMAKE_PREFIX_PATH containing paths to the header and/or loader install dirs
+# CMake options VULKAN_HEADERS_INSTALL_DIR and/or VULKAN_LOADER_INSTALL_DIR
+# Env vars VULKAN_HEADERS_INSTALL_DIR and/or VULKAN_LOADER_INSTALL_DIR
+# If on MacOS
+# CMake option MOTLENVK_REPO_ROOT
+# Env vars MOLTENVK_REPO_ROOT
+# Fallback to FindVulkan operation using SDK install or system installed components.
+# ~~~
+set(VULKAN_HEADERS_INSTALL_DIR "HEADERS-NOTFOUND" CACHE PATH "Absolute path to a Vulkan-Headers install directory")
+set(VULKAN_LOADER_INSTALL_DIR "LOADER-NOTFOUND" CACHE PATH "Absolute path to a Vulkan-Loader install directory")
+if(WIN32 AND "${VULKAN_LOADER_INSTALL_DIR}" STREQUAL "LOADER-NOTFOUND")
+ if(CMAKE_CL_64)
+ set(VULKAN_LOADER_INSTALL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/x64")
+ else()
+ set(VULKAN_LOADER_INSTALL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/x86")
+ endif()
endif()
+set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH};${VULKAN_HEADERS_INSTALL_DIR};${VULKAN_LOADER_INSTALL_DIR};
+ $ENV{VULKAN_HEADERS_INSTALL_DIR};$ENV{VULKAN_LOADER_INSTALL_DIR})
-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)
+if(APPLE)
+ set(MOLTENVK_REPO_ROOT "MOLTENVK-NOTFOUND" CACHE PATH "Absolute path to a MoltenVK repo directory")
+ if(NOT MOLTENVK_REPO_ROOT AND NOT DEFINED ENV{MOLTENVK_REPO_ROOT})
+ message(FATAL_ERROR "Must define location of MoltenVK repo -- see BUILD.md")
endif()
- if (BUILD_WSI_XLIB_SUPPORT)
- find_package(X11 REQUIRED)
+ if(NOT MOLTENVK_REPO_ROOT)
+ set(MOLTENVK_REPO_ROOT $ENV{MOLTENVK_REPO_ROOT})
endif()
+ message(STATUS "Using MoltenVK repo location at ${MOLTENVK_REPO_ROOT}")
+endif()
+message(STATUS "Using find_package to locate Vulkan")
+find_package(Vulkan)
+find_package(VulkanHeaders)
+get_filename_component(Vulkan_LIBRARY_DIR ${Vulkan_LIBRARY} DIRECTORY)
+message(STATUS "Vulkan FOUND = ${Vulkan_FOUND}")
+message(STATUS "Vulkan Lib Dir = ${Vulkan_LIBRARY_DIR}")
+message(STATUS "Vulkan Lib = ${Vulkan_LIBRARY}")
+message(STATUS "Vulkan Headers Include = ${VulkanHeaders_INCLUDE_DIR}")
+message(STATUS "Vulkan Headers Registry = ${VulkanRegistry_DIR}")
+
+include(GNUInstallDirs)
+
+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()
- 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()
+# 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)
+ set_target_properties(uninstall PROPERTIES FOLDER ${TOOLS_HELPER_FOLDER})
endif()
-set(SCRIPTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/scripts")
-
-# Header file for CMake settings
-include_directories("${PROJECT_SOURCE_DIR}/include")
+if(APPLE)
+ # CMake versions 3 or later need CMAKE_MACOSX_RPATH defined. This avoids the CMP0042 policy message.
+ set(CMAKE_MACOSX_RPATH 1)
+endif()
-if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
+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))
+ # 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)
+ 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)
+ 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)
+# Optional codegen target
+if(PYTHONINTERP_FOUND)
+ add_custom_target(VulkanTools_generated_source
+ COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/scripts/generate_source.py
+ ${VulkanRegistry_DIR} --incremental
+ )
else()
- # is WIN32
- option(DISABLE_BUILD_PATH_DECORATION "Disable the decoration of the gslang and SPIRV-Tools build path with MSVC build type info" OFF)
- option(DISABLE_BUILDTGT_DIR_DECORATION "Disable the decoration of the gslang and SPIRV-Tools build path with target info" OFF)
- 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()
+ message("WARNING: VulkanTools_generated_source target requires python 3")
endif()
-option(BUILD_DEMOS "Build demos" ON)
-option(BUILD_ICD "Build icd" ON)
-
-find_program(GLSLANG_VALIDATOR NAMES glslangValidator
- HINTS "${EXTERNAL_SOURCE_ROOT}/glslang/${BUILDTGT_DIR}/install/bin"
- "${GLSLANG_BINARY_ROOT}/StandAlone"
- "${PROJECT_SOURCE_DIR}/external/${BINDATA_DIR}")
-
-find_library(Vulkan_LIBRARY NAMES vulkan-1 vulkan
- HINTS ${VK_SDK_PATH} )
-
-
-set (PYTHON_CMD ${PYTHON_EXECUTABLE})
-
-# Move to icd dir
-# Define macro used for building vkxml generated files
-macro(run_vk_xml_generate dependency output)
- add_custom_command(OUTPUT ${output}
- COMMAND ${PYTHON_CMD} ${SCRIPTS_DIR}/lvl_genvk.py -registry ${SCRIPTS_DIR}/vk.xml ${output}
- DEPENDS ${SCRIPTS_DIR}/vk.xml ${SCRIPTS_DIR}/generator.py ${SCRIPTS_DIR}/${dependency} ${SCRIPTS_DIR}/lvl_genvk.py ${SCRIPTS_DIR}/reg.py
- )
-endmacro()
-
-if(UNIX)
- if(INSTALL_LVL_FILES)
- install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/vulkan" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
- 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)
+if(APPLE)
+ include(mac_common.cmake)
endif()
-add_definitions(-DAPI_NAME="${API_NAME}")
+if(BUILD_CUBE)
+ add_subdirectory(cube)
+endif()
-if(BUILD_DEMOS)
- add_subdirectory(demos)
+if(BUILD_VULKANINFO)
+ add_subdirectory(vulkaninfo)
endif()
+
if(BUILD_ICD)
add_subdirectory(icd)
endif()