Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Commit

Permalink
Rename publication date to version info
Browse files Browse the repository at this point in the history
This is now generated by git.

TODO:
Merge with the git logic used for the tarballs
Test when building from tarballs
Test that it updates the version properly

Fixes #529
  • Loading branch information
nickoe committed Jul 9, 2018
1 parent 331b879 commit 84b6c84
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ add_subdirectory( src )
# Start with the package version being unknown, then prove otherwise
set( CPACK_PACKAGE_VERSION "unknown" )


add_custom_target(
version_info ALL
COMMAND ${CMAKE_COMMAND}
-DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}
-DPROJECT_BINARY_DIR=${PROJECT_BINARY_DIR}
-P ${CMAKE_MODULE_PATH}/CreateGitVersionInfo.cmake
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Generating version info"
)
#include( ${CMAKE_MODULE_PATH}/CreateGitVersionInfo.cmake )
#create_git_version_info( ${PROJECT_SOURCE_DIR} )

# Use Git to determine parts of the package name
find_package( Git )

Expand Down
88 changes: 88 additions & 0 deletions CMakeModules/CreateGitVersionInfo.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#
# (c)2018 KiCad Developers
# (c)2018 Nick Østergaard
#
# CMake module to find produce version information
#
# Variables generated:
#
# KICAD_VERSION A git describe string
# KICAD_VERSION_DATE The date of the last commit
#



macro( create_git_version_info _git_src_path )
# Include Git support to automagically create version header file.
find_package( Git )
message( STATUS "Source path is ${_git_src_path}" )

if( GIT_FOUND )
set( _Git_SAVED_LC_ALL "$ENV{LC_ALL}" )
set( ENV{LC_ALL} C )

execute_process(
COMMAND
${GIT_EXECUTABLE} describe --dirty --tags
WORKING_DIRECTORY "${_git_src_path}"
OUTPUT_VARIABLE _git_DESCRIBE
ERROR_VARIABLE _git_log_error
RESULT_VARIABLE _git_log_result
OUTPUT_STRIP_TRAILING_WHITESPACE)

execute_process(
COMMAND
${GIT_EXECUTABLE} show -s --format=%ci
WORKING_DIRECTORY "${_git_src_path}"
OUTPUT_VARIABLE _git_DATE_CI
ERROR_VARIABLE _git_log_error
RESULT_VARIABLE _git_log_result
OUTPUT_STRIP_TRAILING_WHITESPACE)
message( STATUS "${_git_DATE_CI} 0 10 _git_DATE " )

string( SUBSTRING ${_git_DATE_CI} 0 10 _git_DATE )

set( ENV{LC_ALL} ${_Git_SAVED_LC_ALL} )
endif()

if( _git_DESCRIBE )
set( KICAD_VERSION "${_git_DESCRIBE}" )
set( KICAD_VERSION_DATE "${_git_DATE}" )
endif()

set( _wvi_new_version_text
"// Do not modify this file, it was automatically generated by CMake.
Published on ${KICAD_VERSION_DATE}
`${KICAD_VERSION}`
" )

set( _wvi_write_version_file ON )

set( OUTPUT_FILE "${PROJECT_BINARY_DIR}/src/version_info.txt")

# Only write the header if it has changed, to avoid rebuilds
if( EXISTS ${OUTPUT_FILE} )
file( READ ${OUTPUT_FILE} _wvi_old_version_text )
if( _wvi_old_version_text STREQUAL _wvi_new_version_text )
message( STATUS "Not updating ${OUTPUT_FILE}" )
set( _wvi_write_version_file OFF )
endif()
endif()

if( _wvi_write_version_file )
message( STATUS "Writing ${OUTPUT_FILE} file with version: ${KICAD_VERSION}" )
file( WRITE ${OUTPUT_FILE} ${_wvi_new_version_text} )
endif()

# There should always be a valid version file. Otherwise, we might miss it.
if( NOT EXISTS ${OUTPUT_FILE} )
message( FATAL_ERROR "Configuration failed to write file ${OUTPUT_FILE}." )
endif()
endmacro()

create_git_version_info( "${PROJECT_SOURCE_DIR}" )


# -DOUTPUT_FILE=${CMAKE_BINARY_DIR}/kicad_build_version.h
# -DSRC_PATH=${PROJECT_SOURCE_DIR}

0 comments on commit 84b6c84

Please sign in to comment.