build: Fix mock ICD install issues
[platform/upstream/Vulkan-Tools.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8.11)
2
3 # This must come before the project command.
4 set(CMAKE_OSX_DEPLOYMENT_TARGET "10.12" CACHE STRING "Minimum OS X deployment version")
5
6 project (Vulkan-Tools)
7 # set (CMAKE_VERBOSE_MAKEFILE 1)
8
9 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
10
11 # If CMAKE 3.7+, use FindVulkan
12 if (NOT CMAKE_VERSION VERSION_LESS 3.7.0)
13     message(STATUS "Using find_package to locate Vulkan")
14     find_package(Vulkan)
15 endif()
16
17 if(APPLE)
18     # CMake versions 3 or later need CMAKE_MACOSX_RPATH defined.
19     # This avoids the CMP0042 policy message.
20     set(CMAKE_MACOSX_RPATH 1)
21     # The "install" target for MacOS fixes up bundles in place.
22     set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR})
23 endif()
24
25 # Enable cmake folders
26 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
27 set(TOOLS_TARGET_FOLDER lvl_cmake_targets)
28
29 # Output warning if vulkan headers submodule contents are not present
30 if (NOT EXISTS "${PROJECT_SOURCE_DIR}/Vulkan-Headers/include/vulkan/vulkan_core.h")
31     message(FATAL_ERROR "Please run 'git submodule update --init' before running cmake")
32 endif()
33
34 # Header file for CMake settings
35 include_directories("${PROJECT_SOURCE_DIR}/Vulkan-Headers/include")
36
37 if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
38     set(COMMON_COMPILE_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers")
39     set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -fno-strict-aliasing -fno-builtin-memcmp")
40
41     # For GCC version 7.1 or greater, we need to disable the implicit fallthrough warning since
42     # there's no consistent way to satisfy all compilers until they all accept the C++17 standard
43     if (CMAKE_COMPILER_IS_GNUCC AND NOT (CMAKE_CXX_COMPILER_VERSION LESS 7.1))
44         set(COMMON_COMPILE_FLAGS "${COMMON_COMPILE_FLAGS} -Wimplicit-fallthrough=0")
45     endif()
46
47     if (APPLE)
48         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_COMPILE_FLAGS}")
49     else()
50         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 ${COMMON_COMPILE_FLAGS}")
51     endif()
52     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_COMPILE_FLAGS} -std=c++11 -fno-rtti")
53     if (UNIX)
54         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
55         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
56     endif()
57 endif()
58
59 if(NOT WIN32)
60     set (BUILDTGT_DIR build)
61     set (BINDATA_DIR Bin)
62     set (LIBSOURCE_DIR Lib)
63 else()
64     # For Windows, since 32-bit and 64-bit items can co-exist, we build each in its own build directory.
65     # 32-bit target data goes in build32, and 64-bit target data goes into build.  So, include/link the
66     # appropriate data at build time.
67     if (DISABLE_BUILDTGT_DIR_DECORATION)
68         set (BUILDTGT_DIR "")
69         set (BINDATA_DIR "")
70         set (LIBSOURCE_DIR "")
71     elseif (CMAKE_CL_64)
72         set (BUILDTGT_DIR build)
73         set (BINDATA_DIR Bin)
74         set (LIBSOURCE_DIR Lib)
75     else()
76         set (BUILDTGT_DIR build32)
77         set (BINDATA_DIR Bin32)
78         set (LIBSOURCE_DIR Lib32)
79     endif()
80     if(DISABLE_BUILD_PATH_DECORATION)
81         set (DEBUG_DECORATION "")
82         set (RELEASE_DECORATION "")
83     else()
84         set (DEBUG_DECORATION "Debug")
85         set (RELEASE_DECORATION "Release")
86     endif()
87
88 endif()
89
90 option(BUILD_CUBE "Build cube" ON)
91 option(BUILD_VULKANINFO "Build vulkaninfo" ON)
92 option(BUILD_ICD "Build icd" ON)
93 # Installing the Mock ICD to system directories is probably not desired since
94 # this ICD is not a very complete implementation.
95 # Require the user to ask that it be installed if they really want it.
96 option(INSTALL_ICD "Install icd" OFF)
97
98 if(UNIX)
99     include(GNUInstallDirs)
100     # uninstall target
101     configure_file(
102         "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
103         "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
104         IMMEDIATE @ONLY)
105
106     add_custom_target(uninstall-Vulkan-Tools
107         COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
108 endif()
109
110 if(APPLE)
111     include(mac_common.cmake)
112 endif()
113 if(BUILD_CUBE)
114     add_subdirectory(cube)
115 endif()
116 if(BUILD_VULKANINFO)
117     add_subdirectory(vulkaninfo)
118 endif()
119 if(BUILD_ICD)
120     add_subdirectory(icd)
121 endif()