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