vulkaninfo: Generate vulkaninfo.rc file
[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 # Enable beta Vulkan extensions
37 add_definitions(-DVK_ENABLE_BETA_EXTENSIONS)
38
39 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
40
41 option(BUILD_CUBE "Build cube" ON)
42 option(BUILD_VULKANINFO "Build vulkaninfo" ON)
43 option(BUILD_ICD "Build icd" ON)
44 # Installing the Mock ICD to system directories is probably not desired since this ICD is not a very complete implementation.
45 # Require the user to ask that it be installed if they really want it.
46 option(INSTALL_ICD "Install icd" OFF)
47
48 if(WIN32)
49     # Optional: Allow specify the exact version used in the vulkaninfo executable
50     # Format is major.minor.patch.build
51     set(VULKANINFO_BUILD_DLL_VERSIONINFO "" CACHE STRING "Set the version to be used in the vulkaninfo.rc file. Default value is 1.0.1111.2222")
52 endif()
53
54 # Enable IDE GUI folders
55 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
56 # "Helper" targets that don't have interesting source code should set their FOLDER property to this
57 set(TOOLS_HELPER_FOLDER "Helper Targets")
58
59 option(USE_CCACHE "Use ccache" OFF)
60 if(USE_CCACHE)
61     find_program(CCACHE_FOUND ccache)
62     if(CCACHE_FOUND)
63         set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
64     endif()
65 endif()
66
67 # ~~~
68 # Find Vulkan Headers and Loader
69 # Search order:
70 #  User-supplied CMAKE_PREFIX_PATH containing paths to the header and/or loader install dirs
71 #  CMake options VULKAN_HEADERS_INSTALL_DIR and/or VULKAN_LOADER_INSTALL_DIR
72 #  Env vars VULKAN_HEADERS_INSTALL_DIR and/or VULKAN_LOADER_INSTALL_DIR
73 #  If on MacOS
74 #   CMake option MOTLENVK_REPO_ROOT
75 #   Env vars MOLTENVK_REPO_ROOT
76 #  Fallback to FindVulkan operation using SDK install or system installed components.
77 # ~~~
78 set(VULKAN_HEADERS_INSTALL_DIR "HEADERS-NOTFOUND" CACHE PATH "Absolute path to a Vulkan-Headers install directory")
79 set(VULKAN_LOADER_INSTALL_DIR "LOADER-NOTFOUND" CACHE PATH "Absolute path to a Vulkan-Loader install directory")
80 if(WIN32 AND "${VULKAN_LOADER_INSTALL_DIR}" STREQUAL "LOADER-NOTFOUND")
81     if(CMAKE_CL_64)
82         set(VULKAN_LOADER_INSTALL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/x64")
83     else()
84         set(VULKAN_LOADER_INSTALL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/x86")
85     endif()
86 endif()
87 set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH};${VULKAN_HEADERS_INSTALL_DIR};${VULKAN_LOADER_INSTALL_DIR};
88     $ENV{VULKAN_HEADERS_INSTALL_DIR};$ENV{VULKAN_LOADER_INSTALL_DIR})
89
90 if(APPLE)
91     set(MOLTENVK_REPO_ROOT "MOLTENVK-NOTFOUND" CACHE PATH "Absolute path to a MoltenVK repo directory")
92     if(NOT MOLTENVK_REPO_ROOT AND NOT DEFINED ENV{MOLTENVK_REPO_ROOT})
93         message(FATAL_ERROR "Must define location of MoltenVK repo -- see BUILD.md")
94     endif()
95
96     if(NOT MOLTENVK_REPO_ROOT)
97         set(MOLTENVK_REPO_ROOT $ENV{MOLTENVK_REPO_ROOT})
98     endif()
99     message(STATUS "Using MoltenVK repo location at ${MOLTENVK_REPO_ROOT}")
100 endif()
101 message(STATUS "Using find_package to locate Vulkan")
102 find_package(Vulkan)
103 find_package(VulkanHeaders)
104 get_filename_component(Vulkan_LIBRARY_DIR ${Vulkan_LIBRARY} DIRECTORY)
105 message(STATUS "Vulkan FOUND = ${Vulkan_FOUND}")
106 message(STATUS "Vulkan Lib Dir = ${Vulkan_LIBRARY_DIR}")
107 message(STATUS "Vulkan Lib = ${Vulkan_LIBRARY}")
108 message(STATUS "Vulkan Headers Include = ${VulkanHeaders_INCLUDE_DIR}")
109 message(STATUS "Vulkan Headers Registry = ${VulkanRegistry_DIR}")
110
111 include(GNUInstallDirs)
112
113 if(WIN32 AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
114     # Windows: if install locations not set by user, set install prefix to "<build_dir>\install".
115     set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "default install path" FORCE)
116 endif()
117
118 # uninstall target
119 if(NOT TARGET uninstall)
120     configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
121                    "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
122                    IMMEDIATE
123                    @ONLY)
124
125     add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
126     set_target_properties(uninstall PROPERTIES FOLDER ${TOOLS_HELPER_FOLDER})
127 endif()
128
129 if(APPLE)
130     # CMake versions 3 or later need CMAKE_MACOSX_RPATH defined. This avoids the CMP0042 policy message.
131     set(CMAKE_MACOSX_RPATH 1)
132 endif()
133
134 option(BUILD_WERROR "Treat compiler warnings as errors" ON)
135 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
136     set(COMMON_COMPILE_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers")
137     set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -fno-strict-aliasing -fno-builtin-memcmp")
138
139     if(MAKE_C_COMPILER_ID MATCHES "Clang")
140         set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -Wno-sign-conversion -Wno-shorten-64-to-32 -Wno-string-conversion -Wno-implicit-in-conversion -Wno-enum-enum-conversion")
141     endif()
142
143     if(BUILD_WERROR)
144         if((CMAKE_COMPILER_IS_GNUCXX AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.3.0)) OR
145           (("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0.0)))
146           set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -Werror")
147         endif()
148     endif()
149
150     # For GCC version 7.1 or greater, we need to disable the implicit fallthrough warning since there's no consistent way to satisfy
151     # all compilers until they all accept the C++17 standard
152     if(CMAKE_COMPILER_IS_GNUCC AND NOT (CMAKE_CXX_COMPILER_VERSION LESS 7.1))
153         set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -Wimplicit-fallthrough=0")
154     endif()
155
156     if(APPLE)
157         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_COMPILE_FLAGS}")
158     else()
159         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 ${COMMON_COMPILE_FLAGS}")
160     endif()
161     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_COMPILE_FLAGS} -std=c++11 -fno-rtti")
162     if(UNIX)
163         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
164         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
165     endif()
166 elseif(MSVC)
167     if(BUILD_WERROR)
168         add_compile_options("/WX")
169     endif()
170     # Warn about nested declarations
171     add_compile_options("/w34456")
172     # Warn about potentially uninitialized variables
173     add_compile_options("/w34701")
174     add_compile_options("/w34703")
175     # Warn about different indirection types.
176     add_compile_options("/w34057")
177     # Warn about signed/unsigned mismatch.
178     add_compile_options("/w34245")
179 endif()
180
181 # Optional codegen target
182 if(PYTHONINTERP_FOUND)
183     add_custom_target(VulkanTools_generated_source
184                       COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/scripts/generate_source.py
185                               ${VulkanRegistry_DIR} --incremental
186                       )
187 else()
188     message("WARNING: VulkanTools_generated_source target requires python 3")
189 endif()
190
191 if(APPLE)
192     include(mac_common.cmake)
193 endif()
194
195 if(BUILD_CUBE)
196     add_subdirectory(cube)
197 endif()
198
199 if(BUILD_VULKANINFO)
200     add_subdirectory(vulkaninfo)
201 endif()
202
203 if(BUILD_ICD)
204     add_subdirectory(icd)
205 endif()