build: Remove Windows loader build dependency
[platform/upstream/Vulkan-Tools.git] / CMakeLists.txt
1 # ~~~
2 # Copyright (c) 2014-2018 Valve Corporation
3 # Copyright (c) 2014-2018 LunarG, Inc.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 # ~~~
17
18 # CMake project initialization ---------------------------------------------------------------------------------------------------
19 # This section contains pre-project() initialization, and ends with the project() command.
20
21 cmake_minimum_required(VERSION 3.10.2)
22
23 # Apple: Must be set before enable_language() or project() as it may influence configuration of the toolchain and flags.
24 set(CMAKE_OSX_DEPLOYMENT_TARGET "10.12" CACHE STRING "Minimum OS X deployment version")
25
26 project(Vulkan-Tools)
27
28 # find_package(), include() and global project settings --------------------------------------------------------------------------
29
30 find_package(PythonInterp 3 QUIET)
31
32 # User-interface declarations ----------------------------------------------------------------------------------------------------
33 # This section contains variables that affect development GUIs (e.g. CMake GUI and IDEs), such as option(), folders, and variables
34 # with the CACHE property.
35
36 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
37
38 option(BUILD_CUBE "Build cube" ON)
39 option(BUILD_VULKANINFO "Build vulkaninfo" ON)
40 option(BUILD_ICD "Build icd" ON)
41 # Installing the Mock ICD to system directories is probably not desired since this ICD is not a very complete implementation.
42 # Require the user to ask that it be installed if they really want it.
43 option(INSTALL_ICD "Install icd" OFF)
44
45 # Enable IDE GUI folders
46 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
47 # "Helper" targets that don't have interesting source code should set their FOLDER property to this
48 set(TOOLS_HELPER_FOLDER "Helper Targets")
49
50 option(USE_CCACHE "Use ccache" OFF)
51 if(USE_CCACHE)
52     find_program(CCACHE_FOUND ccache)
53     if(CCACHE_FOUND)
54         set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
55     endif()
56 endif()
57
58 # ~~~
59 # Find Vulkan Headers and Loader
60 # Search order:
61 #  User-supplied CMAKE_PREFIX_PATH containing paths to the header and/or loader install dirs
62 #  CMake options VULKAN_HEADERS_INSTALL_DIR and/or VULKAN_LOADER_INSTALL_DIR
63 #  Env vars VULKAN_HEADERS_INSTALL_DIR and/or VULKAN_LOADER_INSTALL_DIR
64 #  If on MacOS
65 #   CMake option MOTLENVK_REPO_ROOT
66 #   Env vars MOLTENVK_REPO_ROOT
67 #  Fallback to FindVulkan operation using SDK install or system installed components.
68 # ~~~
69 set(VULKAN_HEADERS_INSTALL_DIR "HEADERS-NOTFOUND" CACHE PATH "Absolute path to a Vulkan-Headers install directory")
70 set(VULKAN_LOADER_INSTALL_DIR "LOADER-NOTFOUND" CACHE PATH "Absolute path to a Vulkan-Loader install directory")
71 if(WIN32 AND "${VULKAN_LOADER_INSTALL_DIR}" STREQUAL "LOADER-NOTFOUND")
72     if(CMAKE_CL_64)
73         set(VULKAN_LOADER_INSTALL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/x64")
74     else()
75         set(VULKAN_LOADER_INSTALL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/x86")
76     endif()
77 endif()
78 set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH};${VULKAN_HEADERS_INSTALL_DIR};${VULKAN_LOADER_INSTALL_DIR};
79     $ENV{VULKAN_HEADERS_INSTALL_DIR};$ENV{VULKAN_LOADER_INSTALL_DIR})
80
81 if(APPLE)
82     set(MOLTENVK_REPO_ROOT "MOLTENVK-NOTFOUND" CACHE PATH "Absolute path to a MoltenVK repo directory")
83     if(NOT MOLTENVK_REPO_ROOT AND NOT DEFINED ENV{MOLTENVK_REPO_ROOT})
84         message(FATAL_ERROR "Must define location of MoltenVK repo -- see BUILD.md")
85     endif()
86
87     if(NOT MOLTENVK_REPO_ROOT)
88         set(MOLTENVK_REPO_ROOT $ENV{MOLTENVK_REPO_ROOT})
89     endif()
90     message(STATUS "Using MoltenVK repo location at ${MOLTENVK_REPO_ROOT}")
91 endif()
92 message(STATUS "Using find_package to locate Vulkan")
93 find_package(Vulkan)
94 find_package(VulkanHeaders)
95 get_filename_component(Vulkan_LIBRARY_DIR ${Vulkan_LIBRARY} DIRECTORY)
96 message(STATUS "Vulkan FOUND = ${Vulkan_FOUND}")
97 message(STATUS "Vulkan Lib Dir = ${Vulkan_LIBRARY_DIR}")
98 message(STATUS "Vulkan Lib = ${Vulkan_LIBRARY}")
99 message(STATUS "Vulkan Headers Include = ${VulkanHeaders_INCLUDE_DIR}")
100 message(STATUS "Vulkan Headers Registry = ${VulkanRegistry_DIR}")
101
102 include(GNUInstallDirs)
103
104 if(WIN32 AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
105     # Windows: if install locations not set by user, set install prefix to "<build_dir>\install".
106     set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "default install path" FORCE)
107 endif()
108
109 # uninstall target
110 if(NOT TARGET uninstall)
111     configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
112                    "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
113                    IMMEDIATE
114                    @ONLY)
115
116     add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
117     set_target_properties(uninstall PROPERTIES FOLDER ${TOOLS_HELPER_FOLDER})
118 endif()
119
120 if(APPLE)
121     # CMake versions 3 or later need CMAKE_MACOSX_RPATH defined. This avoids the CMP0042 policy message.
122     set(CMAKE_MACOSX_RPATH 1)
123 endif()
124
125 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
126     set(COMMON_COMPILE_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers")
127     set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -fno-strict-aliasing -fno-builtin-memcmp")
128
129     # For GCC version 7.1 or greater, we need to disable the implicit fallthrough warning since there's no consistent way to satisfy
130     # all compilers until they all accept the C++17 standard
131     if(CMAKE_COMPILER_IS_GNUCC AND NOT (CMAKE_CXX_COMPILER_VERSION LESS 7.1))
132         set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -Wimplicit-fallthrough=0")
133     endif()
134
135     if(APPLE)
136         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_COMPILE_FLAGS}")
137     else()
138         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 ${COMMON_COMPILE_FLAGS}")
139     endif()
140     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_COMPILE_FLAGS} -std=c++11 -fno-rtti")
141     if(UNIX)
142         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
143         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
144     endif()
145 endif()
146
147 # Optional codegen target
148 if(PYTHONINTERP_FOUND)
149     add_custom_target(VulkanTools_generated_source
150                       COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/scripts/generate_source.py
151                               ${VulkanRegistry_DIR} --incremental
152                       )
153 else()
154     message("WARNING: VulkanTools_generated_source target requires python 3")
155 endif()
156
157 if(APPLE)
158     include(mac_common.cmake)
159 endif()
160
161 if(BUILD_CUBE)
162     add_subdirectory(cube)
163 endif()
164
165 if(BUILD_VULKANINFO)
166     add_subdirectory(vulkaninfo)
167 endif()
168
169 if(BUILD_ICD)
170     add_subdirectory(icd)
171 endif()