Commit 9cbb6505 authored by Ghislain MARY's avatar Ghislain MARY

Improve git version header generation with CMake.

parent d032a3a4
......@@ -49,12 +49,14 @@ set(BASE_SOURCE_FILES_C
set(BASE_GENERATED_SOURCE_FILES_C
${CMAKE_CURRENT_BINARY_DIR}/basedescs.h
${CMAKE_CURRENT_BINARY_DIR}/gitversion.h
)
set_source_files_properties(${BASE_GENERATED_SOURCE_FILES_C} PROPERTIES GENERATED TRUE)
find_package(Git)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/gitversion.h
COMMAND ${CMAKE_COMMAND} -DGIT_EXECUTABLE=${GIT_EXECUTABLE} -DOUTPUT_DIR=${CMAKE_CURRENT_BINARY_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/gitversion.cmake)
add_custom_target(ms2-git-version
COMMAND ${CMAKE_COMMAND} -DGIT_EXECUTABLE=${GIT_EXECUTABLE} -DMEDIASTREAMER_VERSION=${MEDIASTREAMER_VERSION} -DWORK_DIR=${CMAKE_CURRENT_SOURCE_DIR} -DOUTPUT_DIR=${CMAKE_CURRENT_BINARY_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/gitversion.cmake
BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/gitversion.h"
)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/basedescs.h
COMMAND ${CMAKE_COMMAND} -DAWK_PROGRAM=${AWK_PROGRAM} -DAWK_SCRIPTS_DIR=${CMAKE_CURRENT_SOURCE_DIR}/../
-DINPUT_DIR=${CMAKE_CURRENT_SOURCE_DIR} -DOUTPUT_DIR=${CMAKE_CURRENT_BINARY_DIR}
......@@ -96,6 +98,7 @@ else()
endif()
endif()
endif()
add_dependencies(mediastreamer_base ms2-git-version)
target_link_libraries(mediastreamer_base ${BASE_LIBS})
install(TARGETS mediastreamer_base EXPORT ${EXPORT_TARGETS_NAME}Targets
......@@ -471,6 +474,7 @@ else()
endif()
endif()
endif()
add_dependencies(mediastreamer_voip ms2-git-version)
target_link_libraries(mediastreamer_voip ${VOIP_LIBS})
string(REPLACE ";" " " LINK_FLAGS_STR "${LINK_FLAGS}")
if(LINK_FLAGS_STR)
......
############################################################################
# CMakeLists.txt
# gitversion.cmake
# Copyright (C) 2014 Belledonne Communications, Grenoble France
#
############################################################################
......@@ -21,18 +21,32 @@
############################################################################
if(GIT_EXECUTABLE)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --always
OUTPUT_VARIABLE GIT_REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${CMAKE_COMMAND} -E echo "#define GIT_VERSION \"${GIT_REVISION}\""
OUTPUT_FILE ${OUTPUT_DIR}/gitversion.h
)
macro(GIT_COMMAND OUTPUT_VAR)
set(GIT_ARGS ${ARGN})
execute_process(
COMMAND ${GIT_EXECUTABLE} ${ARGN}
WORKING_DIRECTORY ${WORK_DIR}
OUTPUT_VARIABLE ${OUTPUT_VAR}
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endmacro()
GIT_COMMAND(GIT_DESCRIBE describe --always)
GIT_COMMAND(GIT_TAG describe --abbrev=0)
GIT_COMMAND(GIT_REVISION rev-parse HEAD)
endif()
if(GIT_DESCRIBE)
if(NOT GIT_TAG STREQUAL MEDIASTREAMER_VERSION)
message(FATAL_ERROR "MEDIASTREAMER_VERSION and git tag differ. Please put them identical")
endif()
set(GIT_VERSION "${GIT_DESCRIBE}")
configure_file("${WORK_DIR}/gitversion.h.in" "${OUTPUT_DIR}/gitversion.h" @ONLY)
elseif(GIT_REVISION)
set(GIT_VERSION "${MEDIASTREAMER_VERSION}_${GIT_REVISION}")
configure_file("${WORK_DIR}/gitversion.h.in" "${OUTPUT_DIR}/gitversion.h" @ONLY)
else()
execute_process(
COMMAND ${CMAKE_COMMAND} -E echo "#define GIT_VERSION \"unknown\""
OUTPUT_FILE ${OUTPUT_DIR}/gitversion.h
)
if(NOT EXISTS "${OUTPUT_DIR}/gitversion.h")
execute_process(COMMAND ${CMAKE_COMMAND} -E touch "${OUTPUT_DIR}/gitversion.h")
endif()
endif()
/*
mediastreamer2 library - modular sound and video processing and streaming
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 GIT_VERSION "@GIT_VERSION@"
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment