Generate build information from CHANGES.md
This PR significantly reworks the way glslang is versioned. Instead of committing changes to the `GLSLANG_MINOR_VERSION` define in `glslang/Public/ShaderLang.h`, and using `make-revision` to generate `GLSLANG_PATCH_LEVEL` in `glslang/Include/revision.h`, all version information is now derived from the new `CHANGES.md` file. `CHANGES.md` acts as the single source of truth for glslang version information, along with a convenient place to put all release notes for each notable change made. `CHANGES.md` is parsed using the new `build_info.py` python script. This script can read basic template files to produce new source files, which it does to read the new `build_info.h.tmpl` to generate (at build time) a glslang private header at `<build-dir>/include/glslang/build_info.h`. I've written generators for each of the CMake, Bazel, gn, and `Android.mk` build scripts. The new version code conforms to the Semantic Versioning 2.0 spec. This new version is also used by the CMake rules to produce versioned shared objects, including a major-versioned SONAME. New APIs: --------- * `glslang::GetVersion()` returns a `Version` struct with the version major, minor, patch and flavor. Breaking API changes: --------------------- * The public defines `GLSLANG_MINOR_VERSION` and `GLSLANG_PATCH_LEVEL` have been entirely removed. * `glslang/Public/ShaderLang.h` and `glslang/Include/revision.h` have been deleted. * Instead, `<build-dir>/include/glslang/build_info.h` is created in the build directory, and `<build-dir>/include` is a CMake `PUBLIC` (dependee-inherited) include directory for the glslang targets. * `<build-dir>/include/glslang/build_info.h` contains the following new #defines: `GLSLANG_VERSION_MAJOR`, `GLSLANG_VERSION_MINOR`, `GLSLANG_VERSION_PATCH`, `GLSLANG_VERSION_FLAVOR`, `GLSLANG_VERSION_GREATER_THAN(major, minor, patch)`, `GLSLANG_VERSION_GREATER_OR_EQUAL_TO(major, minor, patch)`, `GLSLANG_VERSION_LESS_THAN(major, minor, patch)`, `GLSLANG_VERSION_LESS_OR_EQUAL_TO(major, minor, patch)` * The CMake install output directory contains a copy of `build_info.h` at: `include/glslang/build_info.h` * Python3 is now always required to build glslang (likely always required for transitive dependency builds).
This commit is contained in:
@@ -57,6 +57,14 @@ if(BUILD_SHARED_LIBS)
|
||||
set(LIB_TYPE SHARED)
|
||||
endif()
|
||||
|
||||
if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
|
||||
# This logic inside SPIRV-Tools, which can upset build target dependencies
|
||||
# if changed after targets are already defined. To prevent these issues,
|
||||
# ensure CMAKE_BUILD_TYPE is assigned early and at the glslang root scope.
|
||||
message(STATUS "No build type selected, default to Debug")
|
||||
set(CMAKE_BUILD_TYPE "Debug")
|
||||
endif()
|
||||
|
||||
option(SKIP_GLSLANG_INSTALL "Skip installation" ${SKIP_GLSLANG_INSTALL})
|
||||
if(NOT ${SKIP_GLSLANG_INSTALL})
|
||||
set(ENABLE_GLSLANG_INSTALL ON)
|
||||
@@ -221,12 +229,54 @@ endfunction(glslang_set_link_args)
|
||||
|
||||
# CMake needs to find the right version of python, right from the beginning,
|
||||
# otherwise, it will find the wrong version and fail later
|
||||
if(BUILD_EXTERNAL AND IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/External)
|
||||
find_package(PythonInterp 3 REQUIRED)
|
||||
find_package(PythonInterp 3 REQUIRED)
|
||||
|
||||
# We depend on these for later projects, so they should come first.
|
||||
add_subdirectory(External)
|
||||
endif()
|
||||
# Root directory for build-time generated include files
|
||||
set(GLSLANG_GENERATED_INCLUDEDIR "${CMAKE_BINARY_DIR}/include")
|
||||
|
||||
################################################################################
|
||||
# Build version information generation
|
||||
################################################################################
|
||||
set(GLSLANG_CHANGES_FILE "${CMAKE_SOURCE_DIR}/CHANGES.md")
|
||||
set(GLSLANG_BUILD_INFO_PY "${CMAKE_SOURCE_DIR}/build_info.py")
|
||||
set(GLSLANG_BUILD_INFO_H_TMPL "${CMAKE_SOURCE_DIR}/build_info.h.tmpl")
|
||||
set(GLSLANG_BUILD_INFO_H "${GLSLANG_GENERATED_INCLUDEDIR}/glslang/build_info.h")
|
||||
|
||||
# Command to build the build_info.h file
|
||||
add_custom_command(
|
||||
OUTPUT ${GLSLANG_BUILD_INFO_H}
|
||||
COMMAND ${PYTHON_EXECUTABLE} "${GLSLANG_BUILD_INFO_PY}"
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
"-i" ${GLSLANG_BUILD_INFO_H_TMPL}
|
||||
"-o" ${GLSLANG_BUILD_INFO_H}
|
||||
DEPENDS ${GLSLANG_BUILD_INFO_PY}
|
||||
${GLSLANG_CHANGES_FILE}
|
||||
${GLSLANG_BUILD_INFO_H_TMPL}
|
||||
COMMENT "Generating ${GLSLANG_BUILD_INFO_H}")
|
||||
|
||||
# Target to build the build_info.h file
|
||||
add_custom_target(glslang-build-info DEPENDS ${GLSLANG_BUILD_INFO_H})
|
||||
|
||||
# Populate the CMake GLSLANG_VERSION* variables with the build version
|
||||
# information.
|
||||
execute_process(
|
||||
COMMAND ${PYTHON_EXECUTABLE} "${GLSLANG_BUILD_INFO_PY}"
|
||||
${CMAKE_CURRENT_SOURCE_DIR} "<major>.<minor>.<patch><-flavor>;<major>;<minor>;<patch>;<flavor>"
|
||||
OUTPUT_VARIABLE "GLSLANG_VERSIONS"
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
list(GET "GLSLANG_VERSIONS" 0 "GLSLANG_VERSION")
|
||||
list(GET "GLSLANG_VERSIONS" 1 "GLSLANG_VERSION_MAJOR")
|
||||
list(GET "GLSLANG_VERSIONS" 2 "GLSLANG_VERSION_MINOR")
|
||||
list(GET "GLSLANG_VERSIONS" 3 "GLSLANG_VERSION_PATCH")
|
||||
list(GET "GLSLANG_VERSIONS" 4 "GLSLANG_VERSION_FLAVOR")
|
||||
configure_file(${GLSLANG_CHANGES_FILE} "${CMAKE_CURRENT_BINARY_DIR}/CHANGES.md") # Required to re-run cmake on version change
|
||||
|
||||
# glslang_add_build_info_dependency() adds the glslang-build-info dependency and
|
||||
# generated include directories to target.
|
||||
function(glslang_add_build_info_dependency target)
|
||||
target_include_directories(${target} PUBLIC $<BUILD_INTERFACE:${GLSLANG_GENERATED_INCLUDEDIR}>)
|
||||
add_dependencies(${target} glslang-build-info)
|
||||
endfunction()
|
||||
|
||||
# glslang_only_export_explicit_symbols() makes the symbol visibility hidden by
|
||||
# default for <target> when building shared libraries, and sets the
|
||||
@@ -256,6 +306,11 @@ else()
|
||||
message(NOTICE "Your CMake version is ${CMAKE_VERSION}. Update to at least 3.16 to enable precompiled headers to speed up incremental builds")
|
||||
endif()
|
||||
|
||||
if(BUILD_EXTERNAL AND IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/External)
|
||||
# We depend on these for later projects, so they should come first.
|
||||
add_subdirectory(External)
|
||||
endif()
|
||||
|
||||
if(NOT TARGET SPIRV-Tools-opt)
|
||||
set(ENABLE_OPT OFF)
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user