From 64144ec9b691a9c3e0e2b6f69c518c2ab3a7192d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Wed, 15 Jan 2020 21:43:58 -0300 Subject: [PATCH] cmake: Add Git module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- cmake/Git.cmake | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 cmake/Git.cmake diff --git a/cmake/Git.cmake b/cmake/Git.cmake new file mode 100644 index 000000000..8dbebcde8 --- /dev/null +++ b/cmake/Git.cmake @@ -0,0 +1,25 @@ +find_package(Git) + +if(NOT GIT_FOUND OR NOT EXISTS "${PROJECT_SOURCE_DIR}/.git") + return() +endif() + +# Update submodules as needed +option(GIT_SUBMODULE "Check submodules during build" ON) +if(NOT GIT_SUBMODULE) + return() +endif() + +message(STATUS "Submodule update") +execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + RESULT_VARIABLE GIT_SUBMODULE_RESULT) +if(NOT GIT_SUBMODULE_RESULT EQUAL "0") + message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMODULE_RESULT}, please checkout submodules") +endif() + +# Fetch the necessary git variables +execute_process(COMMAND ${GIT_EXECUTABLE} describe --always --tags + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE GIT_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) -- 2.22.0