Fix tests framework_config.h to work all the time
authorCharles Giessen <charles@lunarg.com>
Thu, 2 May 2024 15:42:56 +0000 (10:42 -0500)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Thu, 2 May 2024 21:08:41 +0000 (15:08 -0600)
When using multi-config build systems such as MSVC, it was possible
for the framework_config.h to not be updated properly, resulting in
the wrong binaries being used during testing. By ditching the
common header file and directly specifying the header file to use
through a compiler definition, the code is now shorter and more
reliable.

tests/framework/CMakeLists.txt
tests/framework/test_util.h

index e61825ce8a284c0dc276cdcaba8f41595c4fc116..7412b65f033ea5dfb034fee4f1f7a081ad8acd68 100644 (file)
@@ -74,21 +74,11 @@ add_subdirectory(layer)
 #setup framework_config_temp.h.in in the current binary directory
 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/framework_config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/framework_config_temp.h.in")
 
-# setup framework_config.h.in using framework_config_temp.h.in as a source
+# setup framework_config_$<CONFIG> using framework_config_temp.h.in as a source
 file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/framework_config_$<CONFIG>.h" INPUT "${CMAKE_CURRENT_BINARY_DIR}/framework_config_temp.h.in")
 
-# copy framework_config_$<CONFIG> to the loader build directory
-add_custom_command(
-    PRE_BUILD
-    COMMAND ${CMAKE_COMMAND} "-E" "copy_if_different" "${CMAKE_CURRENT_BINARY_DIR}/framework_config_$<CONFIG>.h" "${CMAKE_CURRENT_BINARY_DIR}/framework_config.h"
-    VERBATIM
-    DEPENDS  "${CMAKE_CURRENT_BINARY_DIR}/framework_config_$<CONFIG>.h"
-    OUTPUT   "${CMAKE_CURRENT_BINARY_DIR}/framework_config.h"
-    COMMENT  "creating framework_config.h file ({event: PRE_BUILD}, {filename: framework_config.h })"
-    )
-add_custom_target (generate_framework_config DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/framework_config.h")
-add_dependencies (generate_framework_config vulkan)
-add_dependencies (testing_framework_util generate_framework_config)
+# Add a compiler definition for the path to framework_config.h with the correct config
+target_compile_definitions(testing_framework_util PUBLIC FRAMEWORK_CONFIG_HEADER="framework_config_$<CONFIG>.h")
 
 add_library(testing_dependencies STATIC test_environment.cpp test_environment.h)
 target_link_libraries(testing_dependencies
index 0a3ac6294f123751974049bee5552629279ffb01..a89c0d70a0b16b27b93afe59948b2db18316f486 100644 (file)
@@ -90,7 +90,7 @@
 #include <vulkan/vk_icd.h>
 #include <vulkan/vk_layer.h>
 
-#include "framework_config.h"
+#include FRAMEWORK_CONFIG_HEADER
 
 #if defined(__GNUC__) && __GNUC__ >= 4
 #define FRAMEWORK_EXPORT __attribute__((visibility("default")))