icd: Make swapchain images persistent
[platform/upstream/Vulkan-Tools.git] / icd / 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 if(WIN32)
19     add_definitions(-DVK_USE_PLATFORM_WIN32_KHR -DVK_USE_PLATFORM_WIN32_KHX -DWIN32_LEAN_AND_MEAN)
20 elseif(ANDROID)
21     add_definitions(-DVK_USE_PLATFORM_ANDROID_KHR -DVK_USE_PLATFORM_ANDROID_KHX)
22 elseif(APPLE)
23     add_definitions(-DVK_USE_PLATFORM_MACOS_MVK)
24 elseif(UNIX AND NOT APPLE) # i.e. Linux
25     if(BUILD_WSI_XCB_SUPPORT)
26         add_definitions(-DVK_USE_PLATFORM_XCB_KHR -DVK_USE_PLATFORM_XCB_KHX)
27     endif()
28
29     if(BUILD_WSI_XLIB_SUPPORT)
30         add_definitions(-DVK_USE_PLATFORM_XLIB_KHR -DVK_USE_PLATFORM_XLIB_KHX -DVK_USE_PLATFORM_XLIB_XRANDR_EXT)
31     endif()
32
33     if(BUILD_WSI_WAYLAND_SUPPORT)
34         add_definitions(-DVK_USE_PLATFORM_WAYLAND_KHR -DVK_USE_PLATFORM_WAYLAND_KHX)
35     endif()
36 else()
37     message(FATAL_ERROR "Unsupported Platform!")
38 endif()
39
40 # Copy or link the JSON files to the binary directory for ease of use in the build tree.
41 set(ICD_JSON_FILES VkICD_mock_icd)
42 if(WIN32)
43     # extra setup for out-of-tree builds
44     if(NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR))
45         if(CMAKE_GENERATOR MATCHES "^Visual Studio.*")
46             foreach(config_file ${ICD_JSON_FILES})
47                 file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/windows/${config_file}.json src_json)
48                 file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${config_file}.json dst_json)
49                 add_custom_target(${config_file}-json ALL COMMAND copy ${src_json} ${dst_json} VERBATIM)
50                 set_target_properties(${config_file}-json PROPERTIES FOLDER ${TOOLS_HELPER_FOLDER})
51             endforeach(config_file)
52         else()
53             foreach(config_file ${ICD_JSON_FILES})
54                 file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/windows/${config_file}.json src_json)
55                 file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/${config_file}.json dst_json)
56                 add_custom_target(${config_file}-json ALL COMMAND copy ${src_json} ${dst_json} VERBATIM)
57             endforeach(config_file)
58         endif()
59     endif()
60 elseif(APPLE)
61     # extra setup for out-of-tree builds
62     if(NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR))
63         if(CMAKE_GENERATOR MATCHES "^Xcode.*")
64             add_custom_target(mk_icd_config_dir ALL
65                               COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)
66             foreach(config_file ${ICD_JSON_FILES})
67                 add_custom_target(${config_file}-json ALL
68                                   DEPENDS mk_icd_config_dir
69                                   COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/macos/${config_file}.json
70                                           $<CONFIG> ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${config_file}.json
71                                   VERBATIM)
72             endforeach(config_file)
73         else()
74             foreach(config_file ${ICD_JSON_FILES})
75                 add_custom_target(${config_file}-json ALL
76                                   COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/macos/${config_file}.json
77                                           ${config_file}.json
78                                   VERBATIM)
79             endforeach(config_file)
80         endif()
81     endif()
82 else()
83     # extra setup for out-of-tree builds
84     if(NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR))
85         foreach(config_file ${ICD_JSON_FILES})
86             add_custom_target(${config_file}-json ALL
87                               COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/linux/${config_file}.json
88                                       ${config_file}.json
89                               VERBATIM)
90         endforeach(config_file)
91     endif()
92 endif()
93
94 # For ICD with a direct dependency on a project with the same name, use it.
95 if(NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR))
96     foreach(config_file ${ICD_JSON_FILES})
97         add_dependencies(${config_file}-json ${config_file})
98     endforeach(config_file)
99 endif()
100 add_custom_target(generate_icd_files DEPENDS mock_icd.h mock_icd.cpp)
101 set_target_properties(generate_icd_files PROPERTIES FOLDER ${TOOLS_HELPER_FOLDER})
102
103 if(WIN32)
104     macro(add_vk_icd target)
105         file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/VkICD_${target}.def DEF_FILE)
106         add_custom_target(copy-${target}-def-file ALL
107                           COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DEF_FILE} VkICD_${target}.def
108                           VERBATIM)
109         set_target_properties(copy-${target}-def-file PROPERTIES FOLDER ${TOOLS_HELPER_FOLDER})
110         add_library(VkICD_${target} SHARED ${ARGN} VkICD_${target}.def)
111         if(INSTALL_ICD)
112             install(TARGETS VkICD_${target} DESTINATION ${CMAKE_INSTALL_LIBDIR})
113         endif()
114     endmacro()
115 elseif(APPLE)
116     macro(add_vk_icd target)
117         add_library(VkICD_${target} SHARED ${ARGN})
118         set_target_properties(VkICD_${target} PROPERTIES LINK_FLAGS "-Wl")
119         if(INSTALL_ICD)
120             install(TARGETS VkICD_${target} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
121         endif()
122     endmacro()
123 else()
124     macro(add_vk_icd target)
125         add_library(VkICD_${target} SHARED ${ARGN})
126         set_target_properties(VkICD_${target} PROPERTIES LINK_FLAGS "-Wl,-export-dynamic,-Bsymbolic,--exclude-libs,ALL")
127         if((UNIX AND NOT APPLE) AND INSTALL_ICD) # i.e. Linux
128             install(TARGETS VkICD_${target} DESTINATION ${CMAKE_INSTALL_LIBDIR})
129         endif()
130     endmacro()
131 endif()
132
133 include_directories(${CMAKE_CURRENT_SOURCE_DIR}
134                     ${VulkanHeaders_INCLUDE_DIR}
135                     ${WAYLAND_CLIENT_INCLUDE_DIR}
136                     ${CMAKE_CURRENT_BINARY_DIR}
137                     ${PROJECT_BINARY_DIR}
138                     ${CMAKE_BINARY_DIR})
139
140 if(WIN32)
141     set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -D_CRT_SECURE_NO_WARNINGS")
142     set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -D_CRT_SECURE_NO_WARNINGS")
143     set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -D_CRT_SECURE_NO_WARNINGS")
144     set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -D_CRT_SECURE_NO_WARNINGS")
145     set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_CRT_SECURE_NO_WARNINGS /bigobj")
146     set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_CRT_SECURE_NO_WARNINGS /bigobj")
147     # Turn off transitional "changed behavior" warning message for Visual Studio versions prior to 2015. The changed behavior is
148     # that constructor initializers are now fixed to clear the struct members.
149     add_compile_options("$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,19>>:/wd4351>")
150 else()
151     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpointer-arith -Wno-unused-function -Wno-sign-compare")
152     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpointer-arith -Wno-unused-function -Wno-sign-compare")
153 endif()
154
155 add_vk_icd(mock_icd generated/mock_icd.cpp generated/mock_icd.h)
156
157 # JSON file(s) install targets. For Linux, need to remove the "./" from the library path before installing to system directories.
158 if((UNIX AND NOT APPLE) AND INSTALL_ICD) # i.e. Linux
159     foreach(config_file ${ICD_JSON_FILES})
160         add_custom_target(${config_file}-staging-json ALL
161                           COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/staging-json
162                           COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/linux/${config_file}.json ${CMAKE_CURRENT_BINARY_DIR}/staging-json
163                           COMMAND sed -i -e "/\"library_path\":/s$./libVkICD$libVkICD$"
164                                   ${CMAKE_CURRENT_BINARY_DIR}/staging-json/${config_file}.json
165                           VERBATIM
166                           DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/linux/${config_file}.json)
167         install(FILES ${CMAKE_CURRENT_BINARY_DIR}/staging-json/${config_file}.json
168                 DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/vulkan/icd.d)
169     endforeach(config_file)
170 endif()
171
172 # Windows uses the JSON file as-is.
173 if(WIN32 AND INSTALL_ICD)
174     foreach(config_file ${ICD_JSON_FILES})
175         install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/windows/${config_file}.json DESTINATION ${CMAKE_INSTALL_LIBDIR})
176     endforeach(config_file)
177 endif()