blob: 5daa9ab8ef1d42148fb5beb433a4dca0074677ab [file] [log] [blame]
Mike Weiblen08c8e542018-06-26 14:47:37 -06001# ~~~
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
Mike Weiblene31a3222018-08-16 14:09:08 -060018if(WIN32)
Tobin Ehlis5ef1efc2017-10-13 09:26:20 -060019 add_definitions(-DVK_USE_PLATFORM_WIN32_KHR -DVK_USE_PLATFORM_WIN32_KHX -DWIN32_LEAN_AND_MEAN)
Mike Weiblene31a3222018-08-16 14:09:08 -060020elseif(ANDROID)
Tobin Ehlis5ef1efc2017-10-13 09:26:20 -060021 add_definitions(-DVK_USE_PLATFORM_ANDROID_KHR -DVK_USE_PLATFORM_ANDROID_KHX)
Mike Weiblene31a3222018-08-16 14:09:08 -060022elseif(APPLE)
23 add_definitions(-DVK_USE_PLATFORM_MACOS_MVK)
24elseif(UNIX AND NOT APPLE) # i.e. Linux
Mike Weiblen9ed609d2018-06-30 22:50:43 -060025 if(BUILD_WSI_XCB_SUPPORT)
Brad Smithd9f46412022-09-06 19:34:36 -040026 find_package(XCB REQUIRED)
27 include_directories(${XCB_INCLUDE_DIR})
Tobin Ehlis5ef1efc2017-10-13 09:26:20 -060028 add_definitions(-DVK_USE_PLATFORM_XCB_KHR -DVK_USE_PLATFORM_XCB_KHX)
29 endif()
30
Mike Weiblen9ed609d2018-06-30 22:50:43 -060031 if(BUILD_WSI_XLIB_SUPPORT)
32 add_definitions(-DVK_USE_PLATFORM_XLIB_KHR -DVK_USE_PLATFORM_XLIB_KHX -DVK_USE_PLATFORM_XLIB_XRANDR_EXT)
Tobin Ehlis5ef1efc2017-10-13 09:26:20 -060033 endif()
34
Mike Weiblen9ed609d2018-06-30 22:50:43 -060035 if(BUILD_WSI_WAYLAND_SUPPORT)
36 add_definitions(-DVK_USE_PLATFORM_WAYLAND_KHR -DVK_USE_PLATFORM_WAYLAND_KHX)
Tobin Ehlis5ef1efc2017-10-13 09:26:20 -060037 endif()
Tobin Ehlis5ef1efc2017-10-13 09:26:20 -060038else()
39 message(FATAL_ERROR "Unsupported Platform!")
40endif()
41
Karl Schultzc3b64a72018-05-28 15:14:19 -060042# Copy or link the JSON files to the binary directory for ease of use in the build tree.
Tobin Ehlis5ef1efc2017-10-13 09:26:20 -060043set(ICD_JSON_FILES VkICD_mock_icd)
Mike Weiblen9ed609d2018-06-30 22:50:43 -060044if(WIN32)
Karl Schultzc3b64a72018-05-28 15:14:19 -060045 # extra setup for out-of-tree builds
Mike Weiblen9ed609d2018-06-30 22:50:43 -060046 if(NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR))
47 if(CMAKE_GENERATOR MATCHES "^Visual Studio.*")
48 foreach(config_file ${ICD_JSON_FILES})
49 file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/windows/${config_file}.json src_json)
Mike Weiblene31a3222018-08-16 14:09:08 -060050 file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${config_file}.json dst_json)
Mike Weiblen9ed609d2018-06-30 22:50:43 -060051 add_custom_target(${config_file}-json ALL COMMAND copy ${src_json} ${dst_json} VERBATIM)
Mike Weiblene31a3222018-08-16 14:09:08 -060052 set_target_properties(${config_file}-json PROPERTIES FOLDER ${TOOLS_HELPER_FOLDER})
Tobin Ehlis5ef1efc2017-10-13 09:26:20 -060053 endforeach(config_file)
54 else()
Mike Weiblen9ed609d2018-06-30 22:50:43 -060055 foreach(config_file ${ICD_JSON_FILES})
56 file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/windows/${config_file}.json src_json)
57 file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/${config_file}.json dst_json)
58 add_custom_target(${config_file}-json ALL COMMAND copy ${src_json} ${dst_json} VERBATIM)
Tobin Ehlis5ef1efc2017-10-13 09:26:20 -060059 endforeach(config_file)
60 endif()
61 endif()
Mike Schuchardted2a0352018-03-26 13:14:25 -060062elseif(APPLE)
63 # extra setup for out-of-tree builds
Mike Weiblen9ed609d2018-06-30 22:50:43 -060064 if(NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR))
65 if(CMAKE_GENERATOR MATCHES "^Xcode.*")
66 add_custom_target(mk_icd_config_dir ALL
67 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)
68 foreach(config_file ${ICD_JSON_FILES})
Mike Schuchardt249440a2018-03-29 10:12:04 -060069 add_custom_target(${config_file}-json ALL
Mike Weiblen9ed609d2018-06-30 22:50:43 -060070 DEPENDS mk_icd_config_dir
Mike Weiblene31a3222018-08-16 14:09:08 -060071 COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/macos/${config_file}.json
72 $<CONFIG> ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${config_file}.json
Mike Weiblen9ed609d2018-06-30 22:50:43 -060073 VERBATIM)
Mike Schuchardt249440a2018-03-29 10:12:04 -060074 endforeach(config_file)
75 else()
Mike Weiblen9ed609d2018-06-30 22:50:43 -060076 foreach(config_file ${ICD_JSON_FILES})
Mike Schuchardt249440a2018-03-29 10:12:04 -060077 add_custom_target(${config_file}-json ALL
Mike Weiblene31a3222018-08-16 14:09:08 -060078 COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/macos/${config_file}.json
79 ${config_file}.json
Mike Weiblen9ed609d2018-06-30 22:50:43 -060080 VERBATIM)
Mike Schuchardt249440a2018-03-29 10:12:04 -060081 endforeach(config_file)
82 endif()
Mike Schuchardted2a0352018-03-26 13:14:25 -060083 endif()
Tobin Ehlis5ef1efc2017-10-13 09:26:20 -060084else()
85 # extra setup for out-of-tree builds
Mike Weiblen9ed609d2018-06-30 22:50:43 -060086 if(NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR))
87 foreach(config_file ${ICD_JSON_FILES})
Mike Weiblene31a3222018-08-16 14:09:08 -060088 add_custom_target(${config_file}-json ALL
89 COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CURRENT_SOURCE_DIR}/linux/${config_file}.json
90 ${config_file}.json
91 VERBATIM)
Tobin Ehlis5ef1efc2017-10-13 09:26:20 -060092 endforeach(config_file)
93 endif()
94endif()
Mark Lobodzinski97259532018-05-11 21:15:07 -060095
Tobin Ehlis5ef1efc2017-10-13 09:26:20 -060096# For ICD with a direct dependency on a project with the same name, use it.
Mike Weiblen9ed609d2018-06-30 22:50:43 -060097if(NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR))
98 foreach(config_file ${ICD_JSON_FILES})
Mark Lobodzinski7e46a5a2017-12-05 16:41:25 -070099 add_dependencies(${config_file}-json ${config_file})
100 endforeach(config_file)
101endif()
Mike Weiblen9ed609d2018-06-30 22:50:43 -0600102add_custom_target(generate_icd_files DEPENDS mock_icd.h mock_icd.cpp)
Mike Weiblene31a3222018-08-16 14:09:08 -0600103set_target_properties(generate_icd_files PROPERTIES FOLDER ${TOOLS_HELPER_FOLDER})
Tobin Ehlis5ef1efc2017-10-13 09:26:20 -0600104
Mike Weiblen9ed609d2018-06-30 22:50:43 -0600105if(WIN32)
Tobin Ehlis5ef1efc2017-10-13 09:26:20 -0600106 macro(add_vk_icd target)
Mike Weiblen9ed609d2018-06-30 22:50:43 -0600107 file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/VkICD_${target}.def DEF_FILE)
108 add_custom_target(copy-${target}-def-file ALL
109 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DEF_FILE} VkICD_${target}.def
110 VERBATIM)
Mike Weiblene31a3222018-08-16 14:09:08 -0600111 set_target_properties(copy-${target}-def-file PROPERTIES FOLDER ${TOOLS_HELPER_FOLDER})
Mike Weiblen9ed609d2018-06-30 22:50:43 -0600112 add_library(VkICD_${target} SHARED ${ARGN} VkICD_${target}.def)
Mike Weiblen9ed609d2018-06-30 22:50:43 -0600113 if(INSTALL_ICD)
114 install(TARGETS VkICD_${target} DESTINATION ${CMAKE_INSTALL_LIBDIR})
115 endif()
Tobin Ehlis5ef1efc2017-10-13 09:26:20 -0600116 endmacro()
Karl Schultz9ceac062017-12-12 10:33:01 -0500117elseif(APPLE)
118 macro(add_vk_icd target)
Mike Weiblen9ed609d2018-06-30 22:50:43 -0600119 add_library(VkICD_${target} SHARED ${ARGN})
Mike Weiblen9ed609d2018-06-30 22:50:43 -0600120 set_target_properties(VkICD_${target} PROPERTIES LINK_FLAGS "-Wl")
121 if(INSTALL_ICD)
122 install(TARGETS VkICD_${target} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
123 endif()
Karl Schultz9ceac062017-12-12 10:33:01 -0500124 endmacro()
Tobin Ehlis5ef1efc2017-10-13 09:26:20 -0600125else()
126 macro(add_vk_icd target)
Mike Weiblen9ed609d2018-06-30 22:50:43 -0600127 add_library(VkICD_${target} SHARED ${ARGN})
Mike Weiblen9ed609d2018-06-30 22:50:43 -0600128 set_target_properties(VkICD_${target} PROPERTIES LINK_FLAGS "-Wl,-export-dynamic,-Bsymbolic,--exclude-libs,ALL")
Mike Weiblene31a3222018-08-16 14:09:08 -0600129 if((UNIX AND NOT APPLE) AND INSTALL_ICD) # i.e. Linux
Mike Weiblen9ed609d2018-06-30 22:50:43 -0600130 install(TARGETS VkICD_${target} DESTINATION ${CMAKE_INSTALL_LIBDIR})
131 endif()
Tobin Ehlis5ef1efc2017-10-13 09:26:20 -0600132 endmacro()
133endif()
134
Mike Weiblene31a3222018-08-16 14:09:08 -0600135include_directories(${CMAKE_CURRENT_SOURCE_DIR}
136 ${VulkanHeaders_INCLUDE_DIR}
Jan Engelhardtf8ba4172018-11-12 18:32:06 +0100137 ${WAYLAND_CLIENT_INCLUDE_DIR}
Mike Weiblene31a3222018-08-16 14:09:08 -0600138 ${CMAKE_CURRENT_BINARY_DIR}
139 ${PROJECT_BINARY_DIR}
140 ${CMAKE_BINARY_DIR})
Tobin Ehlis5ef1efc2017-10-13 09:26:20 -0600141
Mike Weiblen9ed609d2018-06-30 22:50:43 -0600142if(WIN32)
143 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -D_CRT_SECURE_NO_WARNINGS")
144 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -D_CRT_SECURE_NO_WARNINGS")
145 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -D_CRT_SECURE_NO_WARNINGS")
146 set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -D_CRT_SECURE_NO_WARNINGS")
147 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_CRT_SECURE_NO_WARNINGS /bigobj")
148 set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_CRT_SECURE_NO_WARNINGS /bigobj")
149 # Turn off transitional "changed behavior" warning message for Visual Studio versions prior to 2015. The changed behavior is
150 # that constructor initializers are now fixed to clear the struct members.
Tobin Ehlis5ef1efc2017-10-13 09:26:20 -0600151 add_compile_options("$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,19>>:/wd4351>")
152else()
Mike Weiblen9ed609d2018-06-30 22:50:43 -0600153 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpointer-arith -Wno-unused-function -Wno-sign-compare")
154 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpointer-arith -Wno-unused-function -Wno-sign-compare")
Tobin Ehlis5ef1efc2017-10-13 09:26:20 -0600155endif()
156
Mike Schuchardt70a87472019-07-23 11:12:29 -0700157add_vk_icd(mock_icd generated/mock_icd.cpp generated/mock_icd.h)
Tobin Ehlis5ef1efc2017-10-13 09:26:20 -0600158
Mike Weiblen9ed609d2018-06-30 22:50:43 -0600159# JSON file(s) install targets. For Linux, need to remove the "./" from the library path before installing to system directories.
Mike Weiblene31a3222018-08-16 14:09:08 -0600160if((UNIX AND NOT APPLE) AND INSTALL_ICD) # i.e. Linux
Mike Weiblen9ed609d2018-06-30 22:50:43 -0600161 foreach(config_file ${ICD_JSON_FILES})
Karl Schultzc3b64a72018-05-28 15:14:19 -0600162 add_custom_target(${config_file}-staging-json ALL
Mike Weiblen9ed609d2018-06-30 22:50:43 -0600163 COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/staging-json
164 COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/linux/${config_file}.json ${CMAKE_CURRENT_BINARY_DIR}/staging-json
165 COMMAND sed -i -e "/\"library_path\":/s$./libVkICD$libVkICD$"
166 ${CMAKE_CURRENT_BINARY_DIR}/staging-json/${config_file}.json
167 VERBATIM
168 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/linux/${config_file}.json)
Mike Weiblene31a3222018-08-16 14:09:08 -0600169 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/staging-json/${config_file}.json
170 DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/vulkan/icd.d)
Karl Schultzc3b64a72018-05-28 15:14:19 -0600171 endforeach(config_file)
172endif()
173
174# Windows uses the JSON file as-is.
175if(WIN32 AND INSTALL_ICD)
Mike Weiblen9ed609d2018-06-30 22:50:43 -0600176 foreach(config_file ${ICD_JSON_FILES})
Karl Schultzc3b64a72018-05-28 15:14:19 -0600177 install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/windows/${config_file}.json DESTINATION ${CMAKE_INSTALL_LIBDIR})
178 endforeach(config_file)
179endif()