From 5ddc9b378b5bf651abfb40c39a2926a9fc2bb957 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Fri, 10 Jul 2015 14:47:59 -0400 Subject: [PATCH] Correctly fix version header generation to be rebuilt during make. * Use CMake add_custom_target() to run WriteVersionHeader.cmake as a command. * Modify WriteVersionHeader.cmake to be run as a command instead of a macro. * Add version header creation as a CMake common library build dependency. * Add cached CMake variable KICAD_BUILD_VERSION when build version is defined during configuration. --- CMakeLists.txt | 11 ----- CMakeModules/CreateBzrVersionHeader.cmake | 10 ++-- CMakeModules/WriteVersionHeader.cmake | 60 +++++++++++++---------- common/CMakeLists.txt | 19 +++++++ 4 files changed, 57 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9230b9e495..f478bc271a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -685,17 +685,6 @@ if( KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES ) endif() -# Automagically create version header file if the version string was not defined during -# the build configuration. If CreateBzrVersionHeader cannot determine the current repo, -# version, a version.h file is still created with KICAD_BUILD_VERSION set to "no-bzr". -if( KICAD_BUILD_VERSION ) - include( WriteVersionHeader ) - write_version_header( ${KICAD_BUILD_VERSION} ) -else() - include( CreateBzrVersionHeader ) - create_bzr_version_header() -endif() - if( EXISTS ${CMAKE_SOURCE_DIR}/include/config.h ) # This file may exist ( created by an alternate process to the svn test above), # e.g. could be created by a checkout script that produces a source tar file. diff --git a/CMakeModules/CreateBzrVersionHeader.cmake b/CMakeModules/CreateBzrVersionHeader.cmake index d169366bec..2c86e5f302 100644 --- a/CMakeModules/CreateBzrVersionHeader.cmake +++ b/CMakeModules/CreateBzrVersionHeader.cmake @@ -22,9 +22,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA # -include( WriteVersionHeader ) - -macro( create_bzr_version_header ) +macro( create_bzr_version_header _bzr_src_path ) # If bzr is not found or an error occurs using the bzr commands to determine the repo # version, set the build version string to "no-bzr" set( KICAD_BUILD_VERSION "no-bzr" ) @@ -38,7 +36,7 @@ macro( create_bzr_version_header ) # Get the tree revision execute_process( - COMMAND ${Bazaar_EXECUTABLE} revno --tree ${PROJECT_SOURCE_DIR} + COMMAND ${Bazaar_EXECUTABLE} revno --tree ${_bzr_src_path} OUTPUT_VARIABLE _bzr_TREE_DATE RESULT_VARIABLE _bzr_revno_result OUTPUT_STRIP_TRAILING_WHITESPACE ) @@ -46,7 +44,7 @@ macro( create_bzr_version_header ) if( ${_bzr_revno_result} EQUAL 0 ) # Get more info about that revision execute_process( - COMMAND ${Bazaar_EXECUTABLE} log -r${_bzr_TREE_DATE} ${PROJECT_SOURCE_DIR} + COMMAND ${Bazaar_EXECUTABLE} log -r${_bzr_TREE_DATE} ${_bzr_src_path} OUTPUT_VARIABLE _bzr_LAST_CHANGE_LOG ERROR_VARIABLE _bzr_log_error RESULT_VARIABLE _bzr_log_result @@ -73,5 +71,5 @@ macro( create_bzr_version_header ) set( KICAD_BUILD_VERSION "(${_kicad_bzr_date} BZR ${Kicad_REPO_REVISION})" ) endif() - write_version_header( ${KICAD_BUILD_VERSION} ) + set( KICAD_BUILD_VERSION ${KICAD_BUILD_VERSION} ) endmacro() diff --git a/CMakeModules/WriteVersionHeader.cmake b/CMakeModules/WriteVersionHeader.cmake index 710cf2a38c..9637546309 100644 --- a/CMakeModules/WriteVersionHeader.cmake +++ b/CMakeModules/WriteVersionHeader.cmake @@ -22,34 +22,43 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA # -function( write_version_header _wvh_version_str_arg ) +# Automagically create version header file if the version string was not defined during +# the build configuration. If CreateBzrVersionHeader cannot determine the current repo, +# version, a version.h file is still created with KICAD_BUILD_VERSION set to "no-bzr". +if( NOT KICAD_BUILD_VERSION ) + set( _wvh_version_str "no-vcs-found" ) - if( NOT ${_wvh_version_str_arg} ) - set( _wvh_version_str ${_wvh_version_str_arg} ) - else() - set( _wvh_version_str "undefined" ) + # If the code is managed by Bazaar, used bzr to determine the version string. + if( EXISTS "${SRC_PATH}/.bzr" ) + message( STATUS "Using Bazaar to determine build version string." ) + include( ${CMAKE_MODULE_PATH}/CreateBzrVersionHeader.cmake ) + create_bzr_version_header( ${SRC_PATH} ) + set( _wvh_version_str ${KICAD_BUILD_VERSION} ) endif() +else() + set( _wvh_version_str ${KICAD_BUILD_VERSION} ) +endif() - set( _wvh_write_version_file ON ) +set( _wvh_write_version_file ON ) - # Compare the version argument against the version in the existing header file for a mismatch. - if( EXISTS ${CMAKE_BINARY_DIR}/version.h ) - file( STRINGS ${CMAKE_BINARY_DIR}/version.h _current_version_str - REGEX "^#define[\t ]+KICAD_BUILD_VERSION[\t ]+.*" ) - string( REGEX REPLACE "^#define KICAD_BUILD_VERSION \"([()a-zA-Z0-9 -.]+)\".*" - "\\1" _wvh_last_version "${_current_version_str}" ) +# Compare the version argument against the version in the existing header file for a mismatch. +if( EXISTS ${OUTPUT_FILE} ) + file( STRINGS ${CMAKE_BINARY_DIR}/version.h _current_version_str + REGEX "^#define[\t ]+KICAD_BUILD_VERSION[\t ]+.*" ) + string( REGEX REPLACE "^#define KICAD_BUILD_VERSION \"([()a-zA-Z0-9 -.]+)\".*" + "\\1" _wvh_last_version "${_current_version_str}" ) - # No change, do not write version.h - if( _wvh_version_str STREQUAL _wvh_last_version ) - message( STATUS "Not updating ${CMAKE_BINARY_DIR}/version.h" ) - set( _wvh_write_version_file OFF ) - endif() + # No change, do not write version.h + if( _wvh_version_str STREQUAL _wvh_last_version ) + message( STATUS "Not updating ${OUTPUT_FILE}" ) + set( _wvh_write_version_file OFF ) endif() +endif() - if( _wvh_write_version_file ) - message( STATUS "Writing version.h file with version: ${_wvh_version_str}" ) +if( _wvh_write_version_file ) + message( STATUS "Writing ${OUTPUT_FILE} file with version: ${_wvh_version_str}" ) - file( WRITE ${CMAKE_BINARY_DIR}/version.h + file( WRITE ${OUTPUT_FILE} "/* Do not modify this file, it was automatically generated by CMake. */ /* @@ -64,10 +73,9 @@ function( write_version_header _wvh_version_str_arg ) " ) - endif() +endif() - # There should always be a valid version.h file. Otherwise, the build will fail. - if( NOT EXISTS ${CMAKE_BINARY_DIR}/version.h ) - message( FATAL_ERROR "Configuration failed to write file ${CMAKE_BINARY_DIR}/version.h." ) - endif() -endfunction() +# There should always be a valid version.h file. Otherwise, the build will fail. +if( NOT EXISTS ${CMAKE_BINARY_DIR}/version.h ) + message( FATAL_ERROR "Configuration failed to write file ${OUTPUT_FILE}." ) +endif() diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index fc6237cd6d..2b558c42e1 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -115,6 +115,23 @@ install( TARGETS lib_kicad endif() +# KiCad build version string defaults to undefined which forces the build version header +# command to look for Bazaar to create the version string header. +set( KICAD_BUILD_VERSION "" CACHE STRING "Version string defined at configuration time." ) + +# Generate version header file. +add_custom_target( + version_header ALL + COMMAND ${CMAKE_COMMAND} + -DKICAD_BUILD_VERSION=${KICAD_BUILD_VERSION} + -DOUTPUT_FILE=${CMAKE_BINARY_DIR}/version.h + -DSRC_PATH=${PROJECT_SOURCE_DIR} + -DCMAKE_MODULE_PATH=${CMAKE_MODULE_PATH} + -P ${CMAKE_MODULE_PATH}/WriteVersionHeader.cmake + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMENT "Generating version string header" + ) + set( COMMON_ABOUT_DLG_SRCS dialog_about/AboutDialog_main.cpp dialog_about/dialog_about.cpp @@ -259,8 +276,10 @@ set( COMMON_SRCS ) add_library( common STATIC ${COMMON_SRCS} ) add_dependencies( common lib-dependencies ) +add_dependencies( common version_header ) target_link_libraries( common ${Boost_LIBRARIES} ) + set( PCB_COMMON_SRCS base_screen.cpp eda_text.cpp