2 # Copyright (c) 2014-2018 Valve Corporation
3 # Copyright (c) 2014-2018 LunarG, Inc.
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 cmake_minimum_required(VERSION 2.8.11)
20 # This must come before the project command.
21 set(CMAKE_OSX_DEPLOYMENT_TARGET "10.12" CACHE STRING "Minimum OS X deployment version")
25 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
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)
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")
40 # Find Vulkan Headers and Loader
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 # Fallback to FindVulkan operation using SDK install or system installed components.
46 set(VULKAN_HEADERS_INSTALL_DIR "HEADERS-NOTFOUND" CACHE PATH "Absolute path to a Vulkan-Headers install directory")
47 set(VULKAN_LOADER_INSTALL_DIR "LOADER-NOTFOUND" CACHE PATH "Absolute path to a Vulkan-Loader install directory")
48 set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH};${VULKAN_HEADERS_INSTALL_DIR};${VULKAN_LOADER_INSTALL_DIR};
49 $ENV{VULKAN_HEADERS_INSTALL_DIR};$ENV{VULKAN_LOADER_INSTALL_DIR})
50 message(STATUS "Using find_package to locate Vulkan")
52 find_package(VulkanHeaders)
53 # "Vulkan::Vulkan" on macOS causes the framework to be linked to the app instead of an individual library
54 set(LIBVK "Vulkan::Vulkan")
55 message(STATUS "Vulkan FOUND = ${Vulkan_FOUND}")
56 message(STATUS "Vulkan Lib = ${Vulkan_LIBRARY}")
57 message(STATUS "Vulkan Headers Include = ${VulkanHeaders_INCLUDE_DIR}")
58 message(STATUS "Vulkan Headers Registry = ${VulkanRegistry_DIR}")
60 # Install-related settings
61 include(GNUInstallDirs)
62 # Set a better default install location for Windows only if the user did not provide one.
63 if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND WIN32)
64 set (CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "default install path" FORCE )
68 if (NOT TARGET uninstall)
70 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
71 "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
74 add_custom_target(uninstall
75 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
76 set_target_properties(uninstall PROPERTIES FOLDER ${TOOLS_TARGET_FOLDER})
80 # CMake versions 3 or later need CMAKE_MACOSX_RPATH defined.
81 # This avoids the CMP0042 policy message.
82 set(CMAKE_MACOSX_RPATH 1)
83 # The "install" target for MacOS fixes up bundles in place.
84 set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR})
87 if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
88 set(COMMON_COMPILE_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers")
89 set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -fno-strict-aliasing -fno-builtin-memcmp")
91 # For GCC version 7.1 or greater, we need to disable the implicit fallthrough warning since
92 # there's no consistent way to satisfy all compilers until they all accept the C++17 standard
93 if (CMAKE_COMPILER_IS_GNUCC AND NOT (CMAKE_CXX_COMPILER_VERSION LESS 7.1))
94 set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -Wimplicit-fallthrough=0")
98 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_COMPILE_FLAGS}")
100 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 ${COMMON_COMPILE_FLAGS}")
102 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_COMPILE_FLAGS} -std=c++11 -fno-rtti")
104 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
105 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
110 include(mac_common.cmake)
113 add_subdirectory(cube)
116 add_subdirectory(vulkaninfo)
119 add_subdirectory(icd)