Skip to content

Commit

Permalink
build: Fix tests using wrong build
Browse files Browse the repository at this point in the history
When switching between different configurations, it was possible for
the "binary_location.h" file to not get updated correctly, resulting
in the wrong binaries being used during testing.
  • Loading branch information
charles-lunarg committed May 2, 2024
1 parent d21838a commit 810e550
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
16 changes: 3 additions & 13 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,6 @@ find_package(VulkanLoader CONFIG)
# setup binary_locations_$<CONFIG>.h.in using binary_locations.h.in as a source
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/binary_locations_$<CONFIG>.h" INPUT "${CMAKE_CURRENT_SOURCE_DIR}/binary_locations.h.in")

# copy binary_locations_$<CONFIG> to the build directory
add_custom_command(
PRE_BUILD
COMMAND ${CMAKE_COMMAND} "-E" "copy_if_different" "${CMAKE_CURRENT_BINARY_DIR}/binary_locations_$<CONFIG>.h" "${CMAKE_CURRENT_BINARY_DIR}/binary_locations.h"
VERBATIM
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/binary_locations_$<CONFIG>.h"
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/binary_locations.h"
COMMENT "creating binary_locations.h file ({event: PRE_BUILD}, {filename: binary_locations.h })"
)
add_custom_target (generate_binary_locations DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/binary_locations.h")
add_dependencies (generate_binary_locations vkcube vkcubepp VkICD_mock_icd vulkaninfo)

find_package(GTest REQUIRED CONFIG QUIET)

add_executable(vulkan_tools_tests)
Expand All @@ -59,12 +47,14 @@ source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES ${TEST_SOURCES})

target_include_directories(vulkan_tools_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(vulkan_tools_tests GTest::gtest Vulkan::Headers Vulkan::Loader)
add_dependencies(vulkan_tools_tests generate_binary_locations)
if (WIN32)
target_compile_definitions(vulkan_tools_tests PUBLIC -DVK_USE_PLATFORM_WIN32_KHR -DWIN32_LEAN_AND_MEAN -DNOMINMAX)
endif()
set_target_properties(vulkan_tools_tests PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")

# Set the exact path to binary_locations_$<CONFIG>.h's
target_compile_definitions(vulkan_tools_tests PRIVATE BINARY_LOCATIONS_HEADER_FILE="binary_locations_$<CONFIG>.h")

if (DEFINED GIT_BRANCH_NAME AND DEFINED GIT_TAG_INFO)
target_compile_definitions(vulkan_tools_tests PRIVATE GIT_BRANCH_NAME="${GIT_BRANCH_NAME}" GIT_TAG_INFO="${GIT_TAG_INFO}")
endif()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "vulkan/vulkan.h"

// Location of the built binaries in this repo
#include "binary_locations.h"
#include BINARY_LOCATIONS_HEADER_FILE

#if defined(WIN32)
#include <windows.h>
Expand Down

0 comments on commit 810e550

Please sign in to comment.