Skip to content

Commit

Permalink
Auto generates version header
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeltryby committed Nov 2, 2021
1 parent 8e46106 commit 16fe864
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -46,3 +46,4 @@ tests/solver/data/feng*

# Generated files
*_export.h
version.h
2 changes: 2 additions & 0 deletions CMakeLists.txt
Expand Up @@ -45,8 +45,10 @@ set(LIBRARY_DIST "lib")
set(CONFIG_DIST "cmake")


# Define build options
option(BUILD_TESTS "Build component tests (requires Boost)" OFF)
option(BUILD_DOCS "Build toolkit docs (requires Doxygen)" OFF)
option(GEN_VER_HEADER "Automatically update version header" OFF)


# Add project subdirectories
Expand Down
40 changes: 40 additions & 0 deletions extern/version.cmake
@@ -0,0 +1,40 @@
#
# version.cmake - generate SWMM version information header
#
# Created: November 2, 2021
# Updated:
#
# Author: Michael E. Tryby
# US EPA - ORD/CESER
#
# Usage:
# To overwrite version.h file with current info into set GEN_VER_HEADER=ON.

if(GEN_VER_HEADER)

# Get the latest commit hash for the working branch
execute_process(
COMMAND
git rev-parse HEAD
WORKING_DIRECTORY
${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE
GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Generate a build id
string(
TIMESTAMP BUILD_ID UTC
)

# Configure the version header
configure_file(
../../extern/version.h.in version.h
)

file(COPY ${CMAKE_CURRENT_BINARY_DIR}/version.h
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/
)

endif()
27 changes: 27 additions & 0 deletions extern/version.h.in
@@ -0,0 +1,27 @@
/*
* version.h - SWMM version information
*
* Created on: Nov 2, 2021
*
* Author: Michael E. Tryby
* US EPA - ORD/CESER
*/


#ifndef VERSION_H_
#define VERSION_H_



#define VERSION "@swmm-solver_VERSION@"
#define VERSION_MAJOR @swmm-solver_VERSION_MAJOR@
#define VERSION_MINOR @swmm-solver_VERSION_MINOR@
#define VERSION_PATCH @swmm-solver_VERSION_PATCH@

#define GIT_HASH "@GIT_HASH@"

#define BUILD_ID "@BUILD_ID@"



#endif /* VERSION_H_ */
4 changes: 4 additions & 0 deletions src/solver/CMakeLists.txt
Expand Up @@ -14,6 +14,9 @@ find_package(OpenMP
C
)

# Generate version header
include(../../extern/version.cmake)


# configure file groups
set(SWMM_PUBLIC_HEADERS
Expand All @@ -28,6 +31,7 @@ file(GLOB
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.c *.h
)


if(BUILD_DEF)
# Builds library with def file interface for backward compatibility
set_source_files_properties(${PROJECT_SOURCE_DIR}/bindings/swmm5.def
Expand Down

0 comments on commit 16fe864

Please sign in to comment.