• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# ~~~
2# Copyright (c) 2014-2019 Valve Corporation
3# Copyright (c) 2014-2019 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# Needed to make structure definitions match with glslang libraries
19add_definitions(-DNV_EXTENSIONS -DAMD_EXTENSIONS)
20
21if(WIN32)
22    add_definitions(-DVK_USE_PLATFORM_WIN32_KHR -DWIN32_LEAN_AND_MEAN)
23    # Workaround for TR1 deprecation in Visual Studio 15.5 until Google Test is updated
24    add_definitions(-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING)
25elseif(ANDROID)
26    add_definitions(-DVK_USE_PLATFORM_ANDROID_KHR)
27elseif(APPLE)
28    add_definitions(-DVK_USE_PLATFORM_MACOS_MVK)
29elseif(UNIX AND NOT APPLE) # i.e. Linux
30    if(BUILD_WSI_XCB_SUPPORT)
31        add_definitions(-DVK_USE_PLATFORM_XCB_KHR)
32    endif()
33
34    if(BUILD_WSI_XLIB_SUPPORT)
35        add_definitions(-DVK_USE_PLATFORM_XLIB_KHR)
36    endif()
37
38    if(BUILD_WSI_WAYLAND_SUPPORT)
39        add_definitions(-DVK_USE_PLATFORM_WAYLAND_KHR)
40    endif()
41else()
42    message(FATAL_ERROR "Unsupported Platform!")
43endif()
44
45if(WIN32)
46    file(COPY vk_layer_validation_tests.vcxproj.user DESTINATION ${CMAKE_BINARY_DIR}/tests)
47endif()
48
49if(WIN32)
50    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_CRT_SECURE_NO_WARNINGS -D_USE_MATH_DEFINES")
51
52    # If MSVC, disable some signed/unsigned mismatch warnings.
53    if(MSVC)
54        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267")
55    endif()
56
57else()
58    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
59endif()
60
61set(LIBGLM_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/libs)
62
63set(COMMON_CPP vklayertests_pipeline_shader.cpp vklayertests_buffer_image_memory_sampler.cpp vklayertests_others.cpp vklayertests_descriptor_renderpass_framebuffer.cpp
64				vklayertests_command.cpp vklayertests_imageless_framebuffer.cpp vkpositivelayertests.cpp vkrenderframework.cpp vktestbinding.cpp vktestframework.cpp test_environment.cpp)
65
66if(NOT WIN32)
67    # extra setup for out-of-tree builds
68    if(NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR))
69        add_custom_target(VulkanVL_binary_dir_symlinks ALL COMMAND ln -sf ${CMAKE_CURRENT_SOURCE_DIR}/run_all_tests.sh VERBATIM)
70    endif()
71else()
72    if(NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR))
73        file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/_run_all_tests.ps1 RUN_ALL)
74        add_custom_target(VulkanVL_binary_dir_symlinks ALL
75                          COMMAND ${CMAKE_COMMAND} -E copy_if_different ${RUN_ALL} run_all_tests.ps1
76                          VERBATIM)
77        set_target_properties(VulkanVL_binary_dir_symlinks PROPERTIES FOLDER ${LAYERS_HELPER_FOLDER})
78    endif()
79endif()
80
81# ~~~
82# The vulkan loader search is:
83#     Existing vulkan target already present in the build
84#     User-supplied setting of CMAKE_PREFIX_PATH
85#     VULKAN_LOADER_INSTALL_DIR defined via cmake option
86#     VULKAN_LOADER_INSTALL_DIR defined via environment variable
87#     Default findVulkan operation if the VULKAN_SDK environment variable is defined
88# ~~~
89set(VULKAN_LOADER_INSTALL_DIR "LOADER-NOTFOUND" CACHE PATH "Absolute path to a Vulkan-Loader install directory")
90
91if(NOT TARGET vulkan)
92    if(VULKAN_LOADER_INSTALL_DIR)
93        message(STATUS "VULKAN_LOADER_INSTALL_DIR specified, using find_package to locate Vulkan")
94    elseif(ENV{VULKAN_LOADER_INSTALL_DIR})
95        message(STATUS "VULKAN_LOADER_INSTALL_DIR environment variable specified, using find_package to locate Vulkan")
96    else()
97        set(LOCAL_LOADER TRUE)
98        if(CMAKE_CL_64)
99            set(VULKAN_LOADER_INSTALL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../external/x64")
100        else()
101            set(VULKAN_LOADER_INSTALL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../external/x86")
102        endif()
103    endif()
104    set(
105        CMAKE_PREFIX_PATH
106        ${CMAKE_PREFIX_PATH};${VULKAN_LOADER_INSTALL_DIR};${VULKAN_HEADERS_INSTALL_DIR};$ENV{VULKAN_LOADER_INSTALL_DIR};$ENV{VULKAN_HEADERS_INSTALL_DIR}
107        )
108    find_package(Vulkan)
109endif()
110
111set_source_files_properties(${PROJECT_BINARY_DIR}/vk_safe_struct.cpp PROPERTIES GENERATED TRUE)
112add_executable(vk_layer_validation_tests
113               layer_validation_tests.cpp
114               ../layers/vk_format_utils.cpp
115               ../layers/convert_to_renderpass2.cpp
116               ../layers/generated/vk_safe_struct.cpp
117               ${COMMON_CPP})
118add_test(NAME vk_layer_validation_tests COMMAND vk_layer_validation_tests)
119add_dependencies(vk_layer_validation_tests Vulkan::Vulkan VkLayer_khronos_validation VkLayer_khronos_validation-json)
120if(NOT GTEST_IS_STATIC_LIB)
121    set_target_properties(vk_layer_validation_tests PROPERTIES COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1")
122endif()
123# Note that there is no need to add GTEST directories here due to googletest exporting them via the gtest target.
124target_include_directories(vk_layer_validation_tests
125                           PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
126                                  ${PROJECT_SOURCE_DIR}/layers
127                                  ${PROJECT_SOURCE_DIR}/layers/generated
128                                  ${GLSLANG_SPIRV_INCLUDE_DIR}
129                                  ${SPIRV_TOOLS_INCLUDE_DIR}
130                                  ${CMAKE_CURRENT_BINARY_DIR}
131                                  ${CMAKE_BINARY_DIR}
132                                  ${PROJECT_BINARY_DIR}
133                                  ${PROJECT_BINARY_DIR}/layers)
134add_dependencies(vk_layer_validation_tests
135                 VkLayer_utils)
136
137# Specify target_link_libraries
138if(WIN32)
139    target_link_libraries(vk_layer_validation_tests
140                          PRIVATE Vulkan::Vulkan
141                                  gtest
142                                  gtest_main
143                                  ${GLSLANG_LIBRARIES})
144else()
145    target_compile_options(vk_layer_validation_tests PRIVATE "-Wno-sign-compare")
146    if(BUILD_WSI_XCB_SUPPORT OR BUILD_WSI_XLIB_SUPPORT)
147        target_link_libraries(vk_layer_validation_tests
148                              PRIVATE Vulkan::Vulkan
149                                      ${XCB_LIBRARIES}
150                                      ${X11_LIBRARIES}
151                                      gtest
152                                      gtest_main
153                                      ${GLSLANG_LIBRARIES})
154    else()
155        target_link_libraries(vk_layer_validation_tests
156                              PRIVATE Vulkan::Vulkan
157                                      gtest
158                                      gtest_main
159                                      ${GLSLANG_LIBRARIES})
160    endif()
161endif()
162
163if(WIN32)
164    # For Windows, copy necessary gtest DLLs to the right spot for the vk_layer_tests...
165    if(NOT GTEST_IS_STATIC_LIB)
166        file(TO_NATIVE_PATH ${PROJECT_BINARY_DIR}/external/googletest/googletest/$<CONFIG>/*.dll SRC_GTEST_DLLS)
167        file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG> DST_GTEST_DLLS)
168        add_custom_command(TARGET vk_layer_validation_tests POST_BUILD
169                           COMMAND xcopy /Y /I ${SRC_GTEST_DLLS} ${DST_GTEST_DLLS})
170    endif()
171    # Copy the loader shared lib (if supplied) to the test application directory so the test app finds it.
172    if(VULKAN_LOADER_INSTALL_DIR AND NOT LOCAL_LOADER)
173        add_custom_command(TARGET vk_layer_validation_tests POST_BUILD
174                           COMMAND ${CMAKE_COMMAND} -E copy ${VULKAN_LOADER_INSTALL_DIR}/bin/vulkan-1.dll
175                                   $<TARGET_FILE_DIR:vk_layer_validation_tests>)
176    endif()
177endif()
178
179if(INSTALL_TESTS)
180    install(TARGETS vk_layer_validation_tests DESTINATION ${CMAKE_INSTALL_BINDIR})
181endif()
182
183add_subdirectory(layers)
184