Home | History | Annotate | Download | only in layers
      1 # ~~~
      2 # Copyright (c) 2016-2018 Valve Corporation
      3 # Copyright (c) 2016-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 
     18 set(TEST_LAYER_NAME VkLayer_device_profile_api)
     19 
     20 set(VK_LAYER_RPATH /usr/lib/x86_64-linux-gnu/vulkan/layer:/usr/lib/i386-linux-gnu/vulkan/layer)
     21 set(CMAKE_INSTALL_RPATH ${VK_LAYER_RPATH})
     22 
     23 if(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()
     35 elseif(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()
     51 else()
     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()
     58 endif()
     59 
     60 # --------------------------------------------------------------------------------------------------------------------------------
     61 
     62 # System-specific macros to create a library target.
     63 if(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} VulkanVL_generate_helper_files 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()
     77 elseif(APPLE)
     78     macro(AddVkLayer target)
     79         add_library(VkLayer_${target} SHARED ${ARGN})
     80         add_dependencies(VkLayer_${target} VulkanVL_generate_helper_files 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()
     85 else(UNIX AND NOT APPLE) # i.e.: Linux
     86     macro(AddVkLayer target)
     87         add_library(VkLayer_${target} SHARED ${ARGN})
     88         add_dependencies(VkLayer_${target} VulkanVL_generate_helper_files VkLayer_utils)
     89         set_target_properties(VkLayer_${target} PROPERTIES LINK_FLAGS "-Wl,-Bsymbolic")
     90         target_link_libraries(VkLayer_${target} PRIVATE VkLayer_utils)
     91         target_compile_options(VkLayer_${target} PRIVATE "-Wpointer-arith" "-Wno-unused-function")
     92     endmacro()
     93 endif()
     94 
     95 AddVkLayer(device_profile_api device_profile_api.cpp ${PROJECT_SOURCE_DIR}/layers/vk_layer_extension_utils.cpp)
     96 
     97 # --------------------------------------------------------------------------------------------------------------------------------
     98 
     99 # TODO: Clear out this list
    100 target_include_directories(${TEST_LAYER_NAME}
    101                            PRIVATE ${VulkanHeaders_INCLUDE_DIR}
    102                                    ${CMAKE_CURRENT_SOURCE_DIR}
    103                                    ${PROJECT_SOURCE_DIR}/layers
    104                                    ${CMAKE_CURRENT_BINARY_DIR}
    105                                    ${PROJECT_BINARY_DIR}
    106                                    ${PROJECT_BINARY_DIR}/layers
    107                                    ${CMAKE_BINARY_DIR})
    108 
    109 if(WIN32)
    110     # For Windows, copy necessary gtest DLLs to the right spot for the vk_layer_tests...
    111     if (MSVC_IDE)
    112         file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/*device_profile_api.* SRC_LAYER)
    113     else()
    114         file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/*device_profile_api.* SRC_LAYER)
    115     endif()
    116 
    117     file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/windows/${TEST_LAYER_NAME}.json SRC_JSON)
    118     file(TO_NATIVE_PATH ${PROJECT_BINARY_DIR}/layers/$<CONFIG> DST_LAYER)
    119     add_custom_command(TARGET ${TEST_LAYER_NAME} POST_BUILD
    120                        COMMAND xcopy /Y /I ${SRC_LAYER} ${DST_LAYER}
    121                        COMMAND xcopy /Y /I ${SRC_JSON} ${DST_LAYER})
    122 elseif(APPLE)
    123     if(CMAKE_GENERATOR MATCHES "^Xcode.*")
    124         add_custom_command(TARGET ${TEST_LAYER_NAME} POST_BUILD
    125                            COMMAND ln -sf ${CMAKE_CURRENT_BINARY_DIR}/${TEST_LAYER_NAME}.json ${CMAKE_BINARY_DIR}/layers/$<CONFIG>
    126                            COMMAND ln -sf ${CMAKE_CURRENT_BINARY_DIR}/lib${TEST_LAYER_NAME}.dylib
    127                                    ${CMAKE_BINARY_DIR}/layers/$<CONFIG>
    128                            VERBATIM)
    129     else()
    130         add_custom_command(TARGET ${TEST_LAYER_NAME} POST_BUILD
    131                            COMMAND ln -sf ${CMAKE_CURRENT_BINARY_DIR}/${TEST_LAYER_NAME}.json ${CMAKE_BINARY_DIR}/layers
    132                            COMMAND ln -sf ${CMAKE_CURRENT_BINARY_DIR}/lib${TEST_LAYER_NAME}.dylib ${CMAKE_BINARY_DIR}/layers
    133                            VERBATIM)
    134     endif()
    135 else(UNIX AND NOT APPLE) # i.e.: Linux
    136     add_custom_command(TARGET ${TEST_LAYER_NAME} POST_BUILD
    137                        COMMAND ln -sf ${CMAKE_CURRENT_BINARY_DIR}/${TEST_LAYER_NAME}.json ${PROJECT_BINARY_DIR}/layers
    138                        COMMAND ln -sf ${CMAKE_CURRENT_BINARY_DIR}/lib${TEST_LAYER_NAME}.so ${PROJECT_BINARY_DIR}/layers
    139                        VERBATIM)
    140 endif()
    141