Skip to content

Commit

Permalink
Merge pull request #173 from zachasme/feature-include-lib-version
Browse files Browse the repository at this point in the history
ENH: Include defined constants for current library version
  • Loading branch information
nrabinowitz committed Jan 8, 2019
2 parents 6af4914 + d447b22 commit fac1bae
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,6 @@ binding-functions
# These KML files are generated by `make kml`
KML/res*cells.kml
KML/res*centers.kml

# Generated files
src/h3lib/include/h3api.h
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The public API of this library consists of the functions declared in file
[h3api.h](./src/h3lib/include/h3api.h).

## [Unreleased]
### Added
- Include defined constants for current library version

## [3.3.0] - 2018-12-25
### Added
Expand Down
17 changes: 13 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ endif()
file(READ VERSION H3_VERSION LIMIT_COUNT 1)
# Clean any newlines
string(REPLACE "\n" "" H3_VERSION "${H3_VERSION}")
string(REPLACE "." ";" H3_VERSION_LIST "${H3_VERSION}")
list(GET H3_VERSION_LIST 0 H3_VERSION_MAJOR)
list(GET H3_VERSION_LIST 1 H3_VERSION_MINOR)
list(GET H3_VERSION_LIST 2 H3_VERSION_PATCH)
set(H3_SOVERSION 1)

project(h3 LANGUAGES C VERSION ${H3_VERSION})
Expand Down Expand Up @@ -99,7 +103,6 @@ set(LIB_SOURCE_FILES
src/h3lib/include/constants.h
src/h3lib/include/coordijk.h
src/h3lib/include/algos.h
src/h3lib/include/h3api.h
src/h3lib/include/stackAlloc.h
src/h3lib/lib/algos.c
src/h3lib/lib/coordijk.c
Expand Down Expand Up @@ -184,8 +187,12 @@ set(OTHER_SOURCE_FILES
set(ALL_SOURCE_FILES
${LIB_SOURCE_FILES} ${APP_SOURCE_FILES} ${OTHER_SOURCE_FILES})

set(UNCONFIGURED_API_HEADER src/h3lib/include/h3api.h.in)
set(CONFIGURED_API_HEADER src/h3lib/include/h3api.h)
configure_file(${UNCONFIGURED_API_HEADER} ${CONFIGURED_API_HEADER})

# Build the H3 library
add_library(h3 ${LIB_SOURCE_FILES})
add_library(h3 ${LIB_SOURCE_FILES} ${CONFIGURED_API_HEADER})

target_compile_options(h3 PRIVATE ${H3_COMPILE_FLAGS})
target_link_libraries(h3 PRIVATE ${H3_LINK_FLAGS})
Expand All @@ -207,7 +214,8 @@ if(have_vla)
target_compile_definitions(h3 PUBLIC H3_HAVE_VLA)
endif()
target_include_directories(h3 PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/h3lib/include>)
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/h3lib/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src/h3lib/include>)

# Automatic code formatting
find_program(CLANG_FORMAT_PATH clang-format)
Expand All @@ -222,6 +230,7 @@ if(ENABLE_FORMAT)
-i
${ALL_SOURCE_FILES}
${EXAMPLE_SOURCE_FILES}
${UNCONFIGURED_API_HEADER}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Formatting sources"
)
Expand Down Expand Up @@ -552,7 +561,7 @@ install(
# * src/h3lib/include/h3api.h -> <prefix>/include/h3/h3api.h
# Only the h3api.h header is needed by applications using H3.
install(
FILES src/h3lib/include/h3api.h
FILES "${CMAKE_CURRENT_BINARY_DIR}/src/h3lib/include/h3api.h"
DESTINATION "${include_install_dir}/h3"
)

Expand Down
6 changes: 6 additions & 0 deletions src/apps/testapps/testH3Api.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,10 @@ SUITE(h3Api) {
setGeoDegs(&boundary.verts[6], 18.043007860, -66.27669118199998);
t_assertBoundary(h3, &boundary);
}

TEST(version) {
t_assert(H3_VERSION_MAJOR >= 0, "major version is set");
t_assert(H3_VERSION_MINOR >= 0, "minor version is set");
t_assert(H3_VERSION_PATCH >= 0, "patch version is set");
}
}
7 changes: 7 additions & 0 deletions src/h3lib/include/h3api.h → src/h3lib/include/h3api.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ extern "C" {
/** @brief the H3Index fits within a 64-bit unsigned integer */
typedef uint64_t H3Index;

/* library version numbers generated from VERSION file */
// clang-format off
#define H3_VERSION_MAJOR @H3_VERSION_MAJOR@
#define H3_VERSION_MINOR @H3_VERSION_MINOR@
#define H3_VERSION_PATCH @H3_VERSION_PATCH@
// clang-format on

/** Maximum number of cell boundary vertices; worst case is pentagon:
* 5 original verts + 5 edge crossings
*/
Expand Down

0 comments on commit fac1bae

Please sign in to comment.