cmake: Update CMake to check env for MoltenVK
[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_minimum_required(VERSION 2.8.11)
19
20 # This must come before the project command.
21 set(CMAKE_OSX_DEPLOYMENT_TARGET "10.12" CACHE STRING "Minimum OS X deployment version")
22
23 project(Vulkan-Tools)
24
25 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
26
27 option(BUILD_CUBE "Build cube" ON)
28 option(BUILD_VULKANINFO "Build vulkaninfo" ON)
29 option(BUILD_ICD "Build icd" ON)
30 # Installing the Mock ICD to system directories is probably not desired since
31 # this ICD is not a very complete implementation.
32 # Require the user to ask that it be installed if they really want it.
33 option(INSTALL_ICD "Install icd" OFF)
34
35 # Enable IDE GUI folders
36 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
37 # "Helper" targets that don't have interesting source code should set their FOLDER property to this
38 set(TOOLS_TARGET_FOLDER "Helper Targets")
39
40 # Find Vulkan Headers and Loader
41 # Search order:
42 #  User-supplied CMAKE_PREFIX_PATH containing paths to the header and/or loader install dirs
43 #  CMake options VULKAN_HEADERS_INSTALL_DIR and/or VULKAN_LOADER_INSTALL_DIR
44 #  Env vars VULKAN_HEADERS_INSTALL_DIR and/or VULKAN_LOADER_INSTALL_DIR
45 #  If on MacOS
46 #   CMake option MOTLENVK_REPO_ROOT
47 #   Env vars MOLTENVK_REPO_ROOT
48 #  Fallback to FindVulkan operation using SDK install or system installed components.
49 set(VULKAN_HEADERS_INSTALL_DIR "HEADERS-NOTFOUND" CACHE PATH "Absolute path to a Vulkan-Headers install directory")
50 set(VULKAN_LOADER_INSTALL_DIR "LOADER-NOTFOUND" CACHE PATH "Absolute path to a Vulkan-Loader install directory")
51 set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH};${VULKAN_HEADERS_INSTALL_DIR};${VULKAN_LOADER_INSTALL_DIR};
52                        $ENV{VULKAN_HEADERS_INSTALL_DIR};$ENV{VULKAN_LOADER_INSTALL_DIR})
53
54 if (APPLE)
55     set(MOLTENVK_REPO_ROOT "MOLTENVK-NOTFOUND" CACHE PATH "Absolute path to a MoltenVK repo directory")
56     if (NOT MOLTENVK_REPO_ROOT AND NOT DEFINED ENV{MOLTENVK_REPO_ROOT})
57         message(FATAL_ERROR "Must define location of MoltenVK repo -- see BUILD.md")
58     endif()
59
60     if (NOT MOLTENVK_REPO_ROOT)
61         set(MOLTENVK_REPO_ROOT $ENV{MOLTENVK_REPO_ROOT})
62     endif()
63     message(STATUS "Using MoltenVK repo location at ${MOLTENVK_REPO_ROOT}")
64 endif()
65 message(STATUS "Using find_package to locate Vulkan")
66 find_package(Vulkan)
67 find_package(VulkanHeaders)
68 # "Vulkan::Vulkan" on macOS causes the framework to be linked to the app instead of an individual library
69 set(LIBVK "Vulkan::Vulkan")
70 message(STATUS "Vulkan FOUND = ${Vulkan_FOUND}")
71 message(STATUS "Vulkan Lib = ${Vulkan_LIBRARY}")
72 message(STATUS "Vulkan Headers Include = ${VulkanHeaders_INCLUDE_DIR}")
73 message(STATUS "Vulkan Headers Registry = ${VulkanRegistry_DIR}")
74
75 # Install-related settings
76 include(GNUInstallDirs)
77 # Set a better default install location for Windows only if the user did not provide one.
78 if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND WIN32)
79     set (CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "default install path" FORCE )
80 endif()
81
82 # uninstall target
83 if (NOT TARGET uninstall)
84     configure_file(
85         "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
86         "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
87         IMMEDIATE @ONLY)
88
89     add_custom_target(uninstall
90         COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
91     set_target_properties(uninstall PROPERTIES FOLDER ${TOOLS_TARGET_FOLDER})
92 endif()
93
94 if(APPLE)
95     # CMake versions 3 or later need CMAKE_MACOSX_RPATH defined.
96     # This avoids the CMP0042 policy message.
97     set(CMAKE_MACOSX_RPATH 1)
98     # The "install" target for MacOS fixes up bundles in place.
99     set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR})
100 endif()
101
102 if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
103     set(COMMON_COMPILE_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers")
104     set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -fno-strict-aliasing -fno-builtin-memcmp")
105
106     # For GCC version 7.1 or greater, we need to disable the implicit fallthrough warning since
107     # there's no consistent way to satisfy all compilers until they all accept the C++17 standard
108     if (CMAKE_COMPILER_IS_GNUCC AND NOT (CMAKE_CXX_COMPILER_VERSION LESS 7.1))
109         set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -Wimplicit-fallthrough=0")
110     endif()
111
112     if (APPLE)
113         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_COMPILE_FLAGS}")
114     else()
115         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 ${COMMON_COMPILE_FLAGS}")
116     endif()
117     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_COMPILE_FLAGS} -std=c++11 -fno-rtti")
118     if (UNIX)
119         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
120         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
121     endif()
122 endif()
123
124 if(APPLE)
125     include(mac_common.cmake)
126 endif()
127 if(BUILD_CUBE)
128     add_subdirectory(cube)
129 endif()
130 if(BUILD_VULKANINFO)
131     add_subdirectory(vulkaninfo)
132 endif()
133 if(BUILD_ICD)
134     add_subdirectory(icd)
135 endif()