Skip to content

Commit

Permalink
Add KTX_GIT_VERSION_FULL and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
xoofx committed Jul 22, 2024
1 parent 9ffa59d commit a0e85e3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 6 additions & 0 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ add `-D BASISU_SUPPORT_OPENCL=ON` to the CMake configure command.
> There is very little advantage to using OpenCL in the context
> of `libktx`. It is disabled in the default build configuration.
> **Note:**
>
> When building from the `tar.gz` and not from the git repository directly, it is recommended to pass the variable `KTX_GIT_VERSION_FULL` with the associated git tag (e.g `v4.3.2`)
> ```bash
> cmake . -G Ninja -B build -DKTX_GIT_VERSION_FULL=v4.3.2
> ```
Building
--------
Expand Down
13 changes: 7 additions & 6 deletions cmake/version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ function(generate_version _var )
endfunction()

# Get latest tag from git if not passed to cmake
if(NOT KTX_VERSION_FULL)
git_describe_raw(KTX_VERSION_FULL --abbrev=0 --match v[0-9]*)
# This property can be passed to cmake when building from tar.gz
if(NOT KTX_GIT_VERSION_FULL)
git_describe_raw(KTX_GIT_VERSION_FULL --abbrev=0 --match v[0-9]*)
endif()
#message("KTX full version: ${KTX_VERSION_FULL}")

Expand All @@ -119,7 +120,7 @@ endif()

# First try a full regex ( vMAJOR.MINOR.PATCH-TWEAK )
string(REGEX MATCH "^v([0-9]*)\.([0-9]*)\.([0-9]*)(-[^\.]*)"
KTX_VERSION ${KTX_VERSION_FULL})
KTX_VERSION ${KTX_GIT_VERSION_FULL})

if(KTX_VERSION)
set(KTX_VERSION_MAJOR ${CMAKE_MATCH_1})
Expand All @@ -129,7 +130,7 @@ if(KTX_VERSION)
else()
# If full regex failed, go for vMAJOR.MINOR.PATCH
string(REGEX MATCH "^v([0-9]*)\.([0-9]*)\.([^\.]*)"
KTX_VERSION ${KTX_VERSION_FULL})
KTX_VERSION ${KTX_GIT_VERSION_FULL})

if(KTX_VERSION)
set(KTX_VERSION_MAJOR ${CMAKE_MATCH_1})
Expand Down Expand Up @@ -176,15 +177,15 @@ function( create_version_header dest_path target )
add_custom_command(
OUTPUT ${version_h_output}
# On Windows this command has to be invoked by a shell in order to work
COMMAND ${BASH_EXECUTABLE} -c "\"scripts/mkversion\" \"-v\" \"${KTX_VERSION_FULL}\" \"-o\" \"version.h\" \"${dest_path}\""
COMMAND ${BASH_EXECUTABLE} -c "\"scripts/mkversion\" \"-v\" \"${KTX_GIT_VERSION_FULL}\" \"-o\" \"version.h\" \"${dest_path}\""
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Generate ${version_h_output}"
VERBATIM
)
else()
add_custom_command(
OUTPUT ${version_h_output}
COMMAND scripts/mkversion -v ${KTX_VERSION_FULL} -o version.h ${dest_path}
COMMAND scripts/mkversion -v ${KTX_GIT_VERSION_FULL} -o version.h ${dest_path}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Generate ${version_h_output}"
VERBATIM
Expand Down

0 comments on commit a0e85e3

Please sign in to comment.