Cmake build: Moved creation of variable LYX_GIT_COMMIT_HASH to development/cmake/scripts/LyXGetVersion.cmake.

1.) The only file which needs this define is src/version.cpp. Our use in config.h
resulted in recompiling most of our sources.
With this change, only version.cpp needs to be recompiled.

2.) Without reconfiguring, the old commit hash was still valid. Now the
detection of commit hash is done at compile time.
This commit is contained in:
Kornel Benko 2014-10-24 16:58:54 +02:00
parent 61f0634abf
commit 81afd10fc7
4 changed files with 47 additions and 29 deletions

View File

@ -316,7 +316,6 @@ endforeach(_c_l)
FIND_PROGRAM(LYX_GITVERSION git) FIND_PROGRAM(LYX_GITVERSION git)
#message(STATUS "gitversion = ${LYX_GITVERSION}") #message(STATUS "gitversion = ${LYX_GITVERSION}")
set(LYX_GIT_COMMIT_HASH "none")
set(LYX_REVISION_VERSION ${LYX_PATCH_VERSION}) set(LYX_REVISION_VERSION ${LYX_PATCH_VERSION})
if(LYX_GITVERSION) if(LYX_GITVERSION)
if (LYX_LOCALVERSIONING) if (LYX_LOCALVERSIONING)
@ -332,13 +331,7 @@ if(LYX_GITVERSION)
set(ENABLE_DIST ON) set(ENABLE_DIST ON)
endif() endif()
endif() endif()
EXECUTE_PROCESS(COMMAND ${LYX_GITVERSION} log -1 "--pretty=format:%H"
WORKING_DIRECTORY "${TOP_SRC_DIR}" OUTPUT_VARIABLE lyxgitcommit OUTPUT_STRIP_TRAILING_WHITESPACE)
if (lyxgitcommit MATCHES "^[0-9a-f]+$")
set(LYX_GIT_COMMIT_HASH ${lyxgitcommit})
endif()
endif() endif()
#message(STATUS "LYX_GIT_COMMIT_HASH = ${LYX_GIT_COMMIT_HASH}")
# Set the programs (lyx, tex2lyx, etc.) suffix # Set the programs (lyx, tex2lyx, etc.) suffix
# When building an OS X bundle, we will append # When building an OS X bundle, we will append
@ -677,7 +670,7 @@ endif()
# Compute qt4-version from ${QTVERSION} # Compute qt4-version from ${QTVERSION}
message(STATUS "") message(STATUS "")
foreach(_v PACKAGE PACKAGE_VERSION LYX_GIT_COMMIT_HASH foreach(_v PACKAGE PACKAGE_VERSION
PROGRAM_SUFFIX LYX_DATE LYX_DIR_VER LYX_USERDIR_VER PROGRAM_SUFFIX LYX_DATE LYX_DIR_VER LYX_USERDIR_VER
LYX_ABS_TOP_SRCDIR LYX_ABS_TOP_SRCDIR
LYX_ABS_INSTALLED_DATADIR LYX_ABS_INSTALLED_LOCALEDIR LYX_INSTALL_SUFFIX) LYX_ABS_INSTALLED_DATADIR LYX_ABS_INSTALLED_LOCALEDIR LYX_INSTALL_SUFFIX)

View File

@ -39,7 +39,6 @@
#cmakedefine LYX_USERDIR_VER "${LYX_USERDIR_VER}" #cmakedefine LYX_USERDIR_VER "${LYX_USERDIR_VER}"
#define LYX_MAJOR_VERSION ${LYX_MAJOR_VERSION} #define LYX_MAJOR_VERSION ${LYX_MAJOR_VERSION}
#define LYX_MINOR_VERSION ${LYX_MINOR_VERSION} #define LYX_MINOR_VERSION ${LYX_MINOR_VERSION}
#define LYX_GIT_COMMIT_HASH "${LYX_GIT_COMMIT_HASH}"
#define PROGRAM_SUFFIX "${PROGRAM_SUFFIX}" #define PROGRAM_SUFFIX "${PROGRAM_SUFFIX}"
#define LYX_ABS_INSTALLED_DATADIR "${LYX_ABS_INSTALLED_DATADIR}" #define LYX_ABS_INSTALLED_DATADIR "${LYX_ABS_INSTALLED_DATADIR}"

View File

@ -0,0 +1,18 @@
/*
* \file lyx_commit_hash.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* This is the compilation configuration file for LyX.
* It was generated by cmake.
* You might want to change some of the defaults if something goes wrong
* during the compilation.
*/
#ifndef _LYX_COMMIT_HASH_H
#define _LYX_COMMIT_HASH_H
#define LYX_GIT_COMMIT_HASH "${LYX_GIT_COMMIT_HASH}"
#endif

View File

@ -1,4 +1,4 @@
# Copyright (c) 2012, Kornel Benko, <kornel@lyx.org> # Copyright (c) 2012-2014, Kornel Benko, <kornel@lyx.org>
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions # modification, are permitted provided that the following conditions
@ -32,6 +32,8 @@
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
set(LYX_GIT_COMMIT_HASH "none")
FIND_PROGRAM(LYX_GITVERSION git) FIND_PROGRAM(LYX_GITVERSION git)
if(LYX_GITVERSION) if(LYX_GITVERSION)
# Override the value from configure.ac, if possible # Override the value from configure.ac, if possible
@ -44,26 +46,32 @@ if(LYX_GITVERSION)
set(LYX_DATE ${CMAKE_MATCH_2}) set(LYX_DATE ${CMAKE_MATCH_2})
message(STATUS "Git-hash = ${LYX_GITHASH}") message(STATUS "Git-hash = ${LYX_GITHASH}")
endif() endif()
endif() EXECUTE_PROCESS(COMMAND ${LYX_GITVERSION} log -1 "--pretty=format:%H"
WORKING_DIRECTORY "${TOP_SRC_DIR}" OUTPUT_VARIABLE lyxgitcommit OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT EXISTS ${TOP_BINARY_DIR}/lyx_date.h) if (lyxgitcommit MATCHES "^[0-9a-f]+$")
configure_file(${TOP_CMAKE_PATH}/lyx_date.h.cmake ${TOP_BINARY_DIR}/lyx_date.h) set(LYX_GIT_COMMIT_HASH ${lyxgitcommit})
else()
configure_file(${TOP_CMAKE_PATH}/lyx_date.h.cmake ${TOP_BINARY_DIR}/lyx_date.tmp)
message(STATUS "Created ${TOP_BINARY_DIR}/lyx_date.tmp")
EXECUTE_PROCESS(
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${TOP_BINARY_DIR}/lyx_date.tmp ${TOP_BINARY_DIR}/lyx_date.h
ERROR_VARIABLE copy_err
)
if(copy_err)
message(FATAL_ERROR "${CMAKE_COMMAND} -E copy_if_different not working")
endif() endif()
EXECUTE_PROCESS(
COMMAND ${CMAKE_COMMAND} -E remove ${TOP_BINARY_DIR}/lyx_date.tmp
)
endif() endif()
foreach(_hf lyx_date lyx_commit_hash)
if(NOT EXISTS ${TOP_BINARY_DIR}/${_hf}.h)
configure_file(${TOP_CMAKE_PATH}/${_hf}.h.cmake ${TOP_BINARY_DIR}/${_hf}.h)
else()
configure_file(${TOP_CMAKE_PATH}/${_hf}.h.cmake ${TOP_BINARY_DIR}/${_hf}.tmp)
message(STATUS "Created ${TOP_BINARY_DIR}/${_hf}.tmp")
EXECUTE_PROCESS(
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${TOP_BINARY_DIR}/${_hf}.tmp ${TOP_BINARY_DIR}/${_hf}.h
ERROR_VARIABLE copy_err
)
if(copy_err)
message(FATAL_ERROR "${CMAKE_COMMAND} -E copy_if_different not working")
endif()
EXECUTE_PROCESS(
COMMAND ${CMAKE_COMMAND} -E remove ${TOP_BINARY_DIR}/${_hf}.tmp
)
endif()
endforeach()