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