diff --git a/CMakeLists.txt b/CMakeLists.txt index ecfbb83..a93e4bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,11 @@ option(NOISY_LOGGING "Noisy logging" ON) # Version information set(WOFF2_VERSION 1.0.2) +string(REPLACE "." ";" WOFF2_VERSION_COMPONENTS ${WOFF2_VERSION}) +list(GET WOFF2_VERSION_COMPONENTS 0 WOFF2_VERSION_MAJOR) +list(GET WOFF2_VERSION_COMPONENTS 1 WOFF2_VERSION_MINOR) +list(GET WOFF2_VERSION_COMPONENTS 2 WOFF2_VERSION_PATCH) + # When building shared libraries it is important to set the correct rpath # See https://cmake.org/Wiki/CMake_RPATH_handling#Always_full_RPATH set(CMAKE_SKIP_BUILD_RPATH FALSE) @@ -31,6 +36,8 @@ if ("${isSystemDir}" STREQUAL "-1") set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_LIBDIR}") endif() +configure_file(src/version.h.in src/version.h NEWLINE_STYLE UNIX) + # Find Brotli dependencies set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") find_package(BrotliDec) @@ -64,7 +71,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_FLAG}") set(CMAKE_CXX_STANDARD 11) # Set search path for our private/public headers as well as Brotli headers -include_directories("src" "include" +include_directories("src" "include" "${CMAKE_CURRENT_BINARY_DIR}/src" "${BROTLIDEC_INCLUDE_DIRS}" "${BROTLIENC_INCLUDE_DIRS}") # Common part used by decoder and encoder diff --git a/include/woff2/decode.h b/include/woff2/decode.h index 6ef3b8e..3d1b520 100644 --- a/include/woff2/decode.h +++ b/include/woff2/decode.h @@ -31,6 +31,9 @@ bool ConvertWOFF2ToTTF(uint8_t *result, size_t result_length, bool ConvertWOFF2ToTTF(const uint8_t *data, size_t length, WOFF2Out* out); +// Returns the woff2 decoder version. +uint32_t DecoderVersion (void); + } // namespace woff2 #endif // WOFF2_WOFF2_DEC_H_ diff --git a/include/woff2/encode.h b/include/woff2/encode.h index 34b7722..cd9d8cf 100644 --- a/include/woff2/encode.h +++ b/include/woff2/encode.h @@ -38,6 +38,9 @@ bool ConvertTTFToWOFF2(const uint8_t *data, size_t length, uint8_t *result, size_t *result_length, const WOFF2Params& params); +// Returns the woff2 encoder version. +uint32_t EncoderVersion (void); + } // namespace woff2 #endif // WOFF2_WOFF2_ENC_H_ diff --git a/src/version.h.in b/src/version.h.in new file mode 100644 index 0000000..2979e0c --- /dev/null +++ b/src/version.h.in @@ -0,0 +1,11 @@ +#ifndef WOFF2_VERSION_H +#define WOFF2_VERSION_H + +/* Semantic version, calculated as (MAJOR << 24) | (MINOR << 12) | PATCH */ +#define WOFF2_VERSION \ + (@WOFF2_VERSION_MAJOR@ << 24) | \ + (@WOFF2_VERSION_MINOR@ << 12) | \ + (@WOFF2_VERSION_PATCH@) + +#endif + diff --git a/src/woff2_dec.cc b/src/woff2_dec.cc index 25e18c6..674f228 100644 --- a/src/woff2_dec.cc +++ b/src/woff2_dec.cc @@ -27,6 +27,7 @@ #include "./table_tags.h" #include "./variable_length.h" #include "./woff2_common.h" +#include "./version.h" namespace woff2 { @@ -1368,4 +1369,8 @@ bool ConvertWOFF2ToTTF(const uint8_t* data, size_t length, return true; } +uint32_t DecoderVersion (void) { + return WOFF2_VERSION; +} + } // namespace woff2 diff --git a/src/woff2_enc.cc b/src/woff2_enc.cc index ec00878..3729218 100644 --- a/src/woff2_enc.cc +++ b/src/woff2_enc.cc @@ -25,6 +25,7 @@ #include "./transform.h" #include "./variable_length.h" #include "./woff2_common.h" +#include "./version.h" namespace woff2 { @@ -459,4 +460,8 @@ fprintf(stderr, "Missing table index for offset 0x%08x\n", return true; } +uint32_t EncoderVersion (void) { + return WOFF2_VERSION; +} + } // namespace woff2