|
| 1 | +# |
| 2 | +# (c)2018 KiCad Developers |
| 3 | +# (c)2018 Nick Østergaard |
| 4 | +# |
| 5 | +# CMake module to find produce version information |
| 6 | +# |
| 7 | +# Variables generated: |
| 8 | +# |
| 9 | +# KICAD_VERSION A git describe string |
| 10 | +# KICAD_VERSION_DATE The date of the last commit |
| 11 | +# |
| 12 | + |
| 13 | +macro( create_git_version_info _git_src_path ) |
| 14 | + # Include Git support to automagically create version header file. |
| 15 | + find_package( Git ) |
| 16 | + message( STATUS "Source path is ${_git_src_path}" ) |
| 17 | + |
| 18 | + if( GIT_FOUND ) |
| 19 | + set( _Git_SAVED_LC_ALL "$ENV{LC_ALL}" ) |
| 20 | + set( ENV{LC_ALL} C ) |
| 21 | + |
| 22 | + execute_process( |
| 23 | + COMMAND |
| 24 | + ${GIT_EXECUTABLE} describe --dirty --tags |
| 25 | + WORKING_DIRECTORY "${_git_src_path}" |
| 26 | + OUTPUT_VARIABLE _git_DESCRIBE |
| 27 | + ERROR_VARIABLE _git_log_error |
| 28 | + RESULT_VARIABLE _git_log_result |
| 29 | + OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 30 | + |
| 31 | + execute_process( |
| 32 | + COMMAND |
| 33 | + ${GIT_EXECUTABLE} show -s --format=%ci |
| 34 | + WORKING_DIRECTORY "${_git_src_path}" |
| 35 | + OUTPUT_VARIABLE _git_DATE_CI |
| 36 | + ERROR_VARIABLE _git_log_error |
| 37 | + RESULT_VARIABLE _git_log_result |
| 38 | + OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 39 | + message( STATUS "${_git_DATE_CI} 0 10 _git_DATE " ) |
| 40 | + |
| 41 | + string( SUBSTRING ${_git_DATE_CI} 0 10 _git_DATE ) |
| 42 | + |
| 43 | + set( ENV{LC_ALL} ${_Git_SAVED_LC_ALL} ) |
| 44 | + endif() |
| 45 | + |
| 46 | + if( _git_DESCRIBE ) |
| 47 | + set( KICAD_VERSION "${_git_DESCRIBE}" ) |
| 48 | + set( KICAD_VERSION_DATE "${_git_DATE}" ) |
| 49 | + endif() |
| 50 | + |
| 51 | + set( _wvi_new_version_text |
| 52 | +"// Do not modify this file, it was automatically generated by CMake. |
| 53 | +Published on ${KICAD_VERSION_DATE} |
| 54 | +
|
| 55 | +`${KICAD_VERSION}` |
| 56 | +" ) |
| 57 | + |
| 58 | + set( _wvi_write_version_file ON ) |
| 59 | + |
| 60 | + # Only write the header if it has changed, to avoid rebuilds |
| 61 | + if( EXISTS ${OUTPUT_FILE} ) |
| 62 | + file( READ ${OUTPUT_FILE} _wvi_old_version_text ) |
| 63 | + if( _wvi_old_version_text STREQUAL _wvi_new_version_text ) |
| 64 | + message( STATUS "Not updating ${OUTPUT_FILE}" ) |
| 65 | + set( _wvi_write_version_file OFF ) |
| 66 | + endif() |
| 67 | + endif() |
| 68 | + |
| 69 | + if( _wvi_write_version_file ) |
| 70 | + message( STATUS "Writing ${OUTPUT_FILE} file with version: ${KICAD_VERSION}" ) |
| 71 | + file( WRITE ${OUTPUT_FILE} ${_wvi_new_version_text} ) |
| 72 | + endif() |
| 73 | + |
| 74 | + # There should always be a valid version file. Otherwise, we might miss it. |
| 75 | + if( NOT EXISTS ${OUTPUT_FILE} ) |
| 76 | + message( FATAL_ERROR "Configuration failed to write file ${OUTPUT_FILE}." ) |
| 77 | + endif() |
| 78 | +endmacro() |
| 79 | + |
| 80 | +create_git_version_info( "${PROJECT_SOURCE_DIR}" ) |
| 81 | + |
0 commit comments