Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/KhronosGroup/Vulkan-Loader.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Giessen <charles@lunarg.com>2022-05-03 22:53:07 +0300
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>2022-05-04 23:46:53 +0300
commit461f53cdb5ba224a87144484c6b0f77eb636cb0d (patch)
tree961d4aa4a7357dcf8ba33c392d8734c8f673ab17
parent0fd2ff83845abb924db9426b1741882e5ca064bf (diff)
Fix CMake code for getting Git Version information
The ${CMAKE_SOURCE_DIR} uses the wrong directory when the loader is included as a subproject. By using ${CMAKE_CURRENT_LIST_DIR}, the CMake code to find the git commit and branch name will use the correct directory. Additionally, the logic was ammended to curtail this issue in the future. Quotes are included in the string to allow it to be used as a string literal, instead of needing a const char[] variable and macros. Also, the CMake code was restructured to always define GIT_BRANCH_NAME and GIT_TAG_INFO.
-rw-r--r--CMakeLists.txt15
-rw-r--r--loader/loader.c6
2 files changed, 7 insertions, 14 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e16329613..21c6352f6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -148,15 +148,17 @@ if(APPLE)
set(CMAKE_MACOSX_RPATH 1)
endif()
+set(GIT_BRANCH_NAME "--unknown--")
+set(GIT_TAG_INFO "--unknown--")
find_package (Git)
-if (GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git/HEAD")
+if (GIT_FOUND AND EXISTS "${CMAKE_CURRENT_LIST_DIR}/.git/HEAD")
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --always
- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE GIT_TAG_INFO)
string(REGEX REPLACE "\n$" "" GIT_TAG_INFO "${GIT_TAG_INFO}")
- file(READ ".git/HEAD" GIT_HEAD_REF_INFO)
+ file(READ "${CMAKE_CURRENT_LIST_DIR}/.git/HEAD" GIT_HEAD_REF_INFO)
if (GIT_HEAD_REF_INFO)
string(REGEX MATCH "ref: refs/heads/(.*)" _ ${GIT_HEAD_REF_INFO})
if (CMAKE_MATCH_1)
@@ -165,12 +167,7 @@ if (GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git/HEAD")
set(GIT_BRANCH_NAME ${GIT_HEAD_REF_INFO})
endif()
string(REGEX REPLACE "\n$" "" GIT_BRANCH_NAME "${GIT_BRANCH_NAME}")
- else()
- set(GIT_BRANCH_NAME "--unknown--")
endif()
-else()
- set(GIT_BRANCH_NAME "--unknown--")
- set(GIT_TAG_INFO "--unknown--")
endif()
if(WIN32 AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
@@ -341,7 +338,7 @@ endif()
# DEBUG enables runtime loader ICD verification
# Add git branch and tag info in debug mode
-target_compile_definitions(loader_common_options INTERFACE $<$<CONFIG:DEBUG>:DEBUG;GIT_BRANCH_NAME=${GIT_BRANCH_NAME};GIT_TAG_INFO=${GIT_TAG_INFO}>)
+target_compile_definitions(loader_common_options INTERFACE $<$<CONFIG:DEBUG>:DEBUG;GIT_BRANCH_NAME="${GIT_BRANCH_NAME}";GIT_TAG_INFO="${GIT_TAG_INFO}">)
# Check for the existance of the secure_getenv or __secure_getenv commands
include(CheckFunctionExists)
diff --git a/loader/loader.c b/loader/loader.c
index 9dac71f64..c7cd3eced 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -1544,11 +1544,7 @@ void loader_initialize(void) {
loader_log(NULL, VULKAN_LOADER_INFO_BIT, 0, "Vulkan Loader Version %d.%d.%d", version.major, version.minor, version.patch);
#if defined(GIT_BRANCH_NAME) && defined(GIT_TAG_INFO)
-#define LOADER_GIT_STRINGIFY(x) #x
-#define LOADER_GIT_TOSTRING(x) LOADER_GIT_STRINGIFY(x)
- const char git_branch_name[] = LOADER_GIT_TOSTRING(GIT_BRANCH_NAME);
- const char git_tag_info[] = LOADER_GIT_TOSTRING(GIT_TAG_INFO);
- loader_log(NULL, VULKAN_LOADER_INFO_BIT, 0, "[Git - Tag: %s, Branch/Commit: %s]", git_tag_info, git_branch_name);
+ loader_log(NULL, VULKAN_LOADER_INFO_BIT, 0, "[Vulkan Loader Git - Tag: " GIT_BRANCH_NAME ", Branch/Commit: " GIT_TAG_INFO "]");
#endif
}