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