1# ~~~ 2# Copyright (c) 2021 Valve Corporation 3# Copyright (c) 2021 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 18add_library(testing_framework_util STATIC test_util.cpp) 19target_link_libraries(testing_framework_util PUBLIC loader_common_options Vulkan::Headers) 20 21if(UNIX OR APPLE) 22 target_link_libraries(testing_framework_util PUBLIC ${CMAKE_DL_LIBS}) 23endif() 24 25if(UNIX) 26 target_compile_options(testing_framework_util PUBLIC -fPIC) 27endif() 28# Gives access to all headers in the framework folder, in the framework binary, and in the whole project (mainly for loader/generated) 29target_include_directories(testing_framework_util PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}) 30 31if (UNIX) 32 if (LOADER_ENABLE_ADDRESS_SANITIZER) 33 target_compile_options(testing_framework_util PUBLIC -fsanitize=address) 34 target_link_options(testing_framework_util PUBLIC -fsanitize=address) 35 endif() 36 if (LOADER_ENABLE_THREAD_SANITIZER) 37 target_compile_options(testing_framework_util PUBLIC -fsanitize=thread) 38 target_link_options(testing_framework_util PUBLIC -fsanitize=thread) 39 target_compile_options(gtest PUBLIC -fsanitize=thread) 40 target_link_options(gtest PUBLIC -fsanitize=thread) 41 endif() 42 if (LOADER_ENABLE_UNDEFINED_BEHAVIOR_SANITIZER) 43 target_compile_options(testing_framework_util PUBLIC -fsanitize=undefined) 44 target_link_options(testing_framework_util PUBLIC -fsanitize=undefined) 45 endif() 46endif() 47 48if (MSVC) 49# silence hidden class member warnings in test framework 50 target_compile_options(testing_framework_util PUBLIC /wd4458) 51endif() 52 53function(AddSharedLibrary LIBRARY_NAME) 54 set(singleValueArgs DEF_FILE) 55 set(multiValueArgs SOURCES DEFINITIONS) 56 cmake_parse_arguments(PARSED_ARGS "" "${singleValueArgs}" 57 "${multiValueArgs}" ${ARGN} ) 58 59 add_library(${LIBRARY_NAME} SHARED ${PARSED_ARGS_SOURCES}) 60 target_link_libraries(${LIBRARY_NAME} PUBLIC testing_framework_util) 61 target_compile_definitions(${LIBRARY_NAME} PRIVATE ${PARSED_ARGS_DEFINITIONS} VK_NO_PROTOTYPES) 62 # Windows requires export definitions for these libraries 63 if(WIN32) 64 target_sources(${LIBRARY_NAME} PRIVATE export_definitions/${PARSED_ARGS_DEF_FILE}.def) 65 endif() 66endfunction() 67 68add_subdirectory(data) 69add_subdirectory(shim) 70add_subdirectory(icd) 71add_subdirectory(layer) 72 73#configure the framework_config.h.in file - used to locate all the binaries generated so that it can be used in the tests 74#setup framework_config_temp.h.in in the current binary directory 75configure_file("${CMAKE_CURRENT_SOURCE_DIR}/framework_config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/framework_config_temp.h.in") 76 77# setup framework_config.h.in using framework_config_temp.h.in as a source 78file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/framework_config_$<CONFIG>.h" INPUT "${CMAKE_CURRENT_BINARY_DIR}/framework_config_temp.h.in") 79 80# copy framework_config_$<CONFIG> to the loader build directory 81add_custom_command( 82 PRE_BUILD 83 COMMAND ${CMAKE_COMMAND} "-E" "copy_if_different" "${CMAKE_CURRENT_BINARY_DIR}/framework_config_$<CONFIG>.h" "${CMAKE_CURRENT_BINARY_DIR}/framework_config.h" 84 VERBATIM 85 DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/framework_config_$<CONFIG>.h" 86 OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/framework_config.h" 87 COMMENT "creating framework_config.h file ({event: PRE_BUILD}, {filename: framework_config.h })" 88 ) 89add_custom_target (generate_framework_config DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/framework_config.h") 90add_dependencies (generate_framework_config vulkan) 91add_dependencies (testing_framework_util generate_framework_config) 92 93add_library(testing_dependencies STATIC test_environment.cpp test_environment.h) 94target_link_libraries(testing_dependencies 95 PUBLIC gtest Vulkan::Headers testing_framework_util shim-library) 96target_include_directories(testing_dependencies PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) 97target_compile_definitions(testing_dependencies PUBLIC "GTEST_LINKED_AS_SHARED_LIBRARY=1") 98if (APPLE_STATIC_LOADER) 99 target_compile_definitions(testing_dependencies PUBLIC "APPLE_STATIC_LOADER=1") 100 target_link_libraries(testing_dependencies PUBLIC vulkan) 101endif() 102