From 00e96f59f7af7fd7a47421ea0f118036182f8ea6 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Thu, 15 Oct 2015 15:27:49 +0200 Subject: [PATCH] Regenerate liblinphone_gitversion.h with CMake when the git revision has changed. --- coreapi/CMakeLists.txt | 15 +++++++-------- coreapi/gitversion.cmake | 11 +++-------- coreapi/gitversion.h.in | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+), 16 deletions(-) create mode 100644 coreapi/gitversion.h.in diff --git a/coreapi/CMakeLists.txt b/coreapi/CMakeLists.txt index 79cb1dcb5..10e39316e 100644 --- a/coreapi/CMakeLists.txt +++ b/coreapi/CMakeLists.txt @@ -120,13 +120,11 @@ else() list(APPEND SOURCE_FILES linphone_tunnel_stubs.c) endif() -set(GENERATED_SOURCE_FILES - ${CMAKE_CURRENT_BINARY_DIR}/liblinphone_gitversion.h -) -set_source_files_properties(${GENERATED_SOURCE_FILES} PROPERTIES GENERATED TRUE) find_package(Git) -add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/liblinphone_gitversion.h - COMMAND ${CMAKE_COMMAND} -DGIT_EXECUTABLE=${GIT_EXECUTABLE} -DWORK_DIR=${CMAKE_CURRENT_SOURCE_DIR} -DOUTPUT_DIR=${CMAKE_CURRENT_BINARY_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/gitversion.cmake) +add_custom_target(liblinphone-git-version + COMMAND ${CMAKE_COMMAND} -DGIT_EXECUTABLE=${GIT_EXECUTABLE} -DWORK_DIR=${CMAKE_CURRENT_SOURCE_DIR} -DOUTPUT_DIR=${CMAKE_CURRENT_BINARY_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/gitversion.cmake + BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/liblinphone_gitversion.h" +) add_definitions( -DUSE_BELLESIP @@ -161,10 +159,10 @@ if(INTL_FOUND) endif() if(ENABLE_STATIC) - add_library(linphone STATIC ${SOURCE_FILES} ${GENERATED_SOURCE_FILES}) + add_library(linphone STATIC ${SOURCE_FILES}) target_link_libraries(linphone ${LIBS}) else() - add_library(linphone SHARED ${SOURCE_FILES} ${GENERATED_SOURCE_FILES}) + add_library(linphone SHARED ${SOURCE_FILES}) set_target_properties(linphone PROPERTIES VERSION ${LINPHONE_SO_VERSION} LINKER_LANGUAGE CXX) target_link_libraries(linphone ${LIBS}) if(MSVC) @@ -176,6 +174,7 @@ else() endif() endif() endif() +add_dependencies(linphone liblinphone-git-version) if(WIN32 AND CMAKE_SYSTEM_NAME STREQUAL "WindowsPhone") set_target_properties(linphone PROPERTIES PREFIX "lib") endif() diff --git a/coreapi/gitversion.cmake b/coreapi/gitversion.cmake index 23fecb10c..eb0f99e3c 100644 --- a/coreapi/gitversion.cmake +++ b/coreapi/gitversion.cmake @@ -27,13 +27,8 @@ if(GIT_EXECUTABLE) OUTPUT_VARIABLE GIT_REVISION OUTPUT_STRIP_TRAILING_WHITESPACE ) - execute_process( - COMMAND ${CMAKE_COMMAND} -E echo "#define LIBLINPHONE_GIT_VERSION \"${GIT_REVISION}\"" - OUTPUT_FILE ${OUTPUT_DIR}/liblinphone_gitversion.h - ) else() - execute_process( - COMMAND ${CMAKE_COMMAND} -E echo "#define LIBLINPHONE_GIT_VERSION \"unknown\"" - OUTPUT_FILE ${OUTPUT_DIR}/liblinphone_gitversion.h - ) + set(GIT_REVISION "unknown") endif() + +configure_file("${WORK_DIR}/gitversion.h.in" "${OUTPUT_DIR}/liblinphone_gitversion.h" @ONLY) diff --git a/coreapi/gitversion.h.in b/coreapi/gitversion.h.in new file mode 100644 index 000000000..493b4bcb1 --- /dev/null +++ b/coreapi/gitversion.h.in @@ -0,0 +1,21 @@ +/* +linphone +Copyright (C) 2010-2014 Belledonne Communications SARL + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + + +#define LIBLINPHONE_GIT_VERSION "@GIT_REVISION@" \ No newline at end of file