build: Update known-good files for 1.2.146 header
[platform/upstream/Vulkan-Tools.git] / CMakeLists.txt
index b625b80..fea4515 100644 (file)
 # limitations under the License.
 # ~~~
 
-cmake_minimum_required(VERSION 2.8.11)
+# CMake project initialization ---------------------------------------------------------------------------------------------------
+# This section contains pre-project() initialization, and ends with the project() command.
 
-# This must come before 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-Tools)
 
+# find_package(), include() and global project settings --------------------------------------------------------------------------
+
+find_package(PythonInterp 3 QUIET)
+
+# 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")
 
 option(BUILD_CUBE "Build cube" ON)
@@ -34,7 +48,15 @@ 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_TARGET_FOLDER "Helper Targets")
+set(TOOLS_HELPER_FOLDER "Helper Targets")
+
+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)
+    endif()
+endif()
 
 # ~~~
 # Find Vulkan Headers and Loader
@@ -49,6 +71,13 @@ set(TOOLS_TARGET_FOLDER "Helper Targets")
 # ~~~
 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})
 
@@ -66,35 +95,34 @@ endif()
 message(STATUS "Using find_package to locate Vulkan")
 find_package(Vulkan)
 find_package(VulkanHeaders)
-# "Vulkan::Vulkan" on macOS causes the framework to be linked to the app instead of an individual library
-set(LIBVK "Vulkan::Vulkan")
+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}")
 
-# Install-related settings
 include(GNUInstallDirs)
-# Set a better default install location for Windows only if the user did not provide one.
-if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND WIN32)
+
+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()
 
 # uninstall target
 if(NOT TARGET uninstall)
-    configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
+    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_TARGET_FOLDER})
+    set_target_properties(uninstall PROPERTIES FOLDER ${TOOLS_HELPER_FOLDER})
 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()
 
 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
@@ -119,15 +147,28 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
     endif()
 endif()
 
+# 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()
+    message("WARNING: VulkanTools_generated_source target requires python 3")
+endif()
+
 if(APPLE)
     include(mac_common.cmake)
 endif()
+
 if(BUILD_CUBE)
     add_subdirectory(cube)
 endif()
+
 if(BUILD_VULKANINFO)
     add_subdirectory(vulkaninfo)
 endif()
+
 if(BUILD_ICD)
     add_subdirectory(icd)
 endif()