From 45baeb32a7db8930cf3dc4f32cb5fefba742c6b5 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Thu, 11 Jul 2024 19:52:54 +0800 Subject: populate slang-tag-version with cmake (#4611) At the moment it is always "unknown" --- slang-tag-version.h | 1 - slang.h | 21 ++++++++++++--------- source/slang/CMakeLists.txt | 6 +++--- source/slang/slang.cpp | 4 ++-- 4 files changed, 17 insertions(+), 15 deletions(-) delete mode 100644 slang-tag-version.h diff --git a/slang-tag-version.h b/slang-tag-version.h deleted file mode 100644 index 9b241a745..000000000 --- a/slang-tag-version.h +++ /dev/null @@ -1 +0,0 @@ -#define SLANG_TAG_VERSION "unknown" diff --git a/slang.h b/slang.h index 0f75c4c95..2f8f8d15d 100644 --- a/slang.h +++ b/slang.h @@ -1658,15 +1658,18 @@ extern "C" void* userData); /*! - @brief Get the build version 'tag' string. The string is the same as produced via `git describe --tags` - for the project. If Slang is built separately from the automated build scripts - the contents will by default be 'unknown'. Any string can be set by changing the - contents of 'slang-tag-version.h' file and recompiling the project. - - This function will return exactly the same result as the method getBuildTag string on IGlobalSession. - - An advantage of using this function over the method is that doing so does not require the creation of - a session, which can be a fairly costly operation. + @brief Get the build version 'tag' string. The string is the same as + produced via `git describe --tags --match v*` for the project. If such a + version could not be determined at build time then the contents will be + 0.0.0-unknown. Any string can be set by passing + -DSLANG_VERSION_FULL=whatever during the cmake invocation. + + This function will return exactly the same result as the method + getBuildTagString on IGlobalSession. + + An advantage of using this function over the method is that doing so does + not require the creation of a session, which can be a fairly costly + operation. @return The build tag string */ diff --git a/source/slang/CMakeLists.txt b/source/slang/CMakeLists.txt index 495a05f36..40eca76a9 100644 --- a/source/slang/CMakeLists.txt +++ b/source/slang/CMakeLists.txt @@ -249,7 +249,7 @@ target_include_directories( # # Slang itself # -configure_file(${slang_SOURCE_DIR}/slang-tag-version.h.in slang-tag-version.h) +configure_file(${slang_SOURCE_DIR}/slang-tag-version.h.in slang-version-header/slang-tag-version.h) slang_add_target( . ${SLANG_LIB_TYPE} @@ -267,10 +267,10 @@ slang_add_target( # slang.h is in the project root, so include that directory in the interface # for slang INCLUDE_DIRECTORIES_PUBLIC ${slang_SOURCE_DIR} - INCLUDE_DIRECTORIES_PRIVATE ${CMAKE_CURRENT_BINARY_DIR} + INCLUDE_DIRECTORIES_PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/slang-version-header EXPORT_MACRO_PREFIX SLANG INSTALL - PUBLIC_HEADERS ${slang_SOURCE_DIR}/slang*.h + PUBLIC_HEADERS ${slang_SOURCE_DIR}/slang*.h ${CMAKE_CURRENT_BINARY_DIR}/slang-version-header/*.h ) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index d601dcd0e..9827f9c5c 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -47,7 +47,7 @@ #include "slang-check-impl.h" -#include "../../slang-tag-version.h" +#include "slang-tag-version.h" #include @@ -124,7 +124,7 @@ namespace Slang { const char* getBuildTagString() { - if (UnownedStringSlice(SLANG_TAG_VERSION) == "unknown") + if (UnownedStringSlice(SLANG_TAG_VERSION) == "0.0.0-unknown") { // If the tag is unknown, then we will try to get the timestamp of the shared library // and use that as the version string, so that we can at least return something -- cgit v1.2.3