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.
19 add_definitions(-DVK_USE_PLATFORM_WIN32_KHR -DVK_USE_PLATFORM_WIN32_KHX -DWIN32_LEAN_AND_MEAN)
21 add_definitions(-DVK_USE_PLATFORM_ANDROID_KHR -DVK_USE_PLATFORM_ANDROID_KHX)
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)
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)
33 if(BUILD_WSI_WAYLAND_SUPPORT)
34 add_definitions(-DVK_USE_PLATFORM_WAYLAND_KHR -DVK_USE_PLATFORM_WAYLAND_KHX)
37 message(FATAL_ERROR "Unsupported Platform!")
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)
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)
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)
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
72 endforeach(config_file)
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
79 endforeach(config_file)
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
90 endforeach(config_file)
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)
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})
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
109 set_target_properties(copy-${target}-def-file PROPERTIES FOLDER ${TOOLS_HELPER_FOLDER})
110 add_library(VkICD_${target} SHARED ${ARGN} VkICD_${target}.def)
112 install(TARGETS VkICD_${target} DESTINATION ${CMAKE_INSTALL_LIBDIR})
116 macro(add_vk_icd target)
117 add_library(VkICD_${target} SHARED ${ARGN})
118 set_target_properties(VkICD_${target} PROPERTIES LINK_FLAGS "-Wl")
120 install(TARGETS VkICD_${target} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
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})
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}
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>")
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")
155 add_vk_icd(mock_icd generated/mock_icd.cpp generated/mock_icd.h)
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
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)
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)