1# ~~~ 2# Copyright (c) 2016-2019 Valve Corporation 3# Copyright (c) 2016-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 18set(TEST_LAYER_NAME VkLayer_device_profile_api) 19 20set(VK_LAYER_RPATH /usr/lib/x86_64-linux-gnu/vulkan/layer:/usr/lib/i386-linux-gnu/vulkan/layer) 21set(CMAKE_INSTALL_RPATH ${VK_LAYER_RPATH}) 22 23if(WIN32) 24 if(NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)) 25 file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/windows/${TEST_LAYER_NAME}.json src_json) 26 if(CMAKE_GENERATOR MATCHES "^Visual Studio.*") 27 file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${TEST_LAYER_NAME}.json dst_json) 28 else() 29 file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/${TEST_LAYER_NAME}.json dst_json) 30 endif() 31 add_custom_target(${TEST_LAYER_NAME}-json ALL COMMAND copy ${src_json} ${dst_json} VERBATIM) 32 add_dependencies(${TEST_LAYER_NAME}-json ${TEST_LAYER_NAME}) 33 set_target_properties(${TEST_LAYER_NAME}-json PROPERTIES FOLDER ${LAYERS_HELPER_FOLDER}) 34 endif() 35elseif(APPLE) 36 # extra setup for out-of-tree builds 37 if(NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)) 38 if(CMAKE_GENERATOR MATCHES "^Xcode.*") 39 add_custom_target(mk_test_layer_config_dir ALL 40 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>) 41 add_custom_target(${TEST_LAYER_NAME}-json ALL 42 DEPENDS mk_test_layer_config_dir 43 COMMAND ln -sf ${CMAKE_CURRENT_SOURCE_DIR}/macos/${TEST_LAYER_NAME}.json $<CONFIG> 44 VERBATIM) 45 else() 46 add_custom_target(${TEST_LAYER_NAME}-json ALL 47 COMMAND ln -sf ${CMAKE_CURRENT_SOURCE_DIR}/macos/${TEST_LAYER_NAME}.json 48 VERBATIM) 49 endif() 50 endif() 51else() 52 # extra setup for out-of-tree builds 53 if(NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)) 54 add_custom_target(${TEST_LAYER_NAME}-json ALL 55 COMMAND ln -sf ${CMAKE_CURRENT_SOURCE_DIR}/linux/${TEST_LAYER_NAME}.json 56 VERBATIM) 57 endif() 58endif() 59 60# -------------------------------------------------------------------------------------------------------------------------------- 61 62# System-specific macros to create a library target. 63if(WIN32) 64 macro(AddVkLayer target) 65 file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/VkLayer_${target}.def DEF_FILE) 66 add_custom_target(copy-${target}-def-file ALL 67 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DEF_FILE} VkLayer_${target}.def 68 VERBATIM) 69 set_target_properties(copy-${target}-def-file PROPERTIES FOLDER ${LAYERS_HELPER_FOLDER}) 70 71 add_library(VkLayer_${target} SHARED ${ARGN} VkLayer_${target}.def) 72 add_dependencies(VkLayer_${target} VkLayer_utils) 73 target_link_libraries(VkLayer_${target} PRIVATE VkLayer_utils) 74 target_compile_definitions(VkLayer_${target} PRIVATE "_CRT_SECURE_NO_WARNINGS") 75 target_compile_options(VkLayer_${target} PRIVATE $<$<CONFIG:Debug>:/bigobj>) 76 endmacro() 77elseif(APPLE) 78 macro(AddVkLayer target) 79 add_library(VkLayer_${target} SHARED ${ARGN}) 80 add_dependencies(VkLayer_${target} VkLayer_utils) 81 set_target_properties(VkLayer_${target} PROPERTIES LINK_FLAGS "-Wl") 82 target_link_libraries(VkLayer_${target} PRIVATE VkLayer_utils) 83 target_compile_options(VkLayer_${target} PRIVATE "-Wpointer-arith" "-Wno-unused-function") 84 endmacro() 85else(UNIX AND NOT APPLE) # i.e.: Linux 86 macro(AddVkLayer target) 87 add_library(VkLayer_${target} SHARED ${ARGN}) 88 add_dependencies(VkLayer_${target} VkLayer_utils) 89 set_target_properties(VkLayer_${target} PROPERTIES LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libVkLayer_${target}.map,-Bsymbolic") 90 target_link_libraries(VkLayer_${target} PRIVATE VkLayer_utils) 91 target_compile_options(VkLayer_${target} PRIVATE "-Wpointer-arith" "-Wno-unused-function") 92 endmacro() 93endif() 94 95AddVkLayer(device_profile_api device_profile_api.cpp ${PROJECT_SOURCE_DIR}/layers/vk_layer_extension_utils.cpp) 96 97# -------------------------------------------------------------------------------------------------------------------------------- 98 99target_include_directories(${TEST_LAYER_NAME} 100 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} 101 ${PROJECT_SOURCE_DIR}/layers 102 ${CMAKE_CURRENT_BINARY_DIR} 103 ${PROJECT_BINARY_DIR} 104 ${PROJECT_BINARY_DIR}/layers 105 ${CMAKE_BINARY_DIR} 106 ${VulkanHeaders_INCLUDE_DIR}) 107 108if(WIN32) 109 # For Windows, copy necessary device_profile_api layer files for the layer_tests 110 file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/windows/${TEST_LAYER_NAME}.json SRC_JSON) 111 file(TO_NATIVE_PATH ${PROJECT_BINARY_DIR}/layers/$<CONFIG>/${TEST_LAYER_NAME}.json DST_JSON) 112 add_custom_command(TARGET ${TEST_LAYER_NAME} POST_BUILD 113 COMMAND ${CMAKE_COMMAND} -E copy ${SRC_JSON} ${DST_JSON}) 114 SET(DEVICE_PROFILE_LAYER_FILES 115 VkLayer_device_profile_api.dll 116 VkLayer_device_profile_api.exp 117 VkLayer_device_profile_api.lib) 118 file(TO_NATIVE_PATH ${PROJECT_BINARY_DIR}/layers/$<CONFIG> DST_LAYER) 119 foreach(DEV_PROF_FILE ${DEVICE_PROFILE_LAYER_FILES}) 120 file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${DEV_PROF_FILE} SRC_LAYER) 121 add_custom_command(TARGET ${TEST_LAYER_NAME} POST_BUILD 122 COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SRC_LAYER} ${DST_LAYER}) 123 endforeach() 124elseif(APPLE) 125 if(CMAKE_GENERATOR MATCHES "^Xcode.*") 126 add_custom_command(TARGET ${TEST_LAYER_NAME} POST_BUILD 127 COMMAND ln -sf ${CMAKE_CURRENT_BINARY_DIR}/${TEST_LAYER_NAME}.json ${CMAKE_BINARY_DIR}/layers/$<CONFIG> 128 COMMAND ln -sf ${CMAKE_CURRENT_BINARY_DIR}/lib${TEST_LAYER_NAME}.dylib 129 ${CMAKE_BINARY_DIR}/layers/$<CONFIG> 130 VERBATIM) 131 else() 132 add_custom_command(TARGET ${TEST_LAYER_NAME} POST_BUILD 133 COMMAND ln -sf ${CMAKE_CURRENT_BINARY_DIR}/${TEST_LAYER_NAME}.json ${CMAKE_BINARY_DIR}/layers 134 COMMAND ln -sf ${CMAKE_CURRENT_BINARY_DIR}/lib${TEST_LAYER_NAME}.dylib ${CMAKE_BINARY_DIR}/layers 135 VERBATIM) 136 endif() 137else(UNIX AND NOT APPLE) # i.e.: Linux 138 add_custom_command(TARGET ${TEST_LAYER_NAME} POST_BUILD 139 COMMAND ln -sf ${CMAKE_CURRENT_BINARY_DIR}/${TEST_LAYER_NAME}.json ${PROJECT_BINARY_DIR}/layers 140 COMMAND ln -sf ${CMAKE_CURRENT_BINARY_DIR}/lib${TEST_LAYER_NAME}.so ${PROJECT_BINARY_DIR}/layers 141 VERBATIM) 142endif() 143