diff --git a/modules/ECMSourceVersionControl.cmake b/modules/ECMSourceVersionControl.cmake --- a/modules/ECMSourceVersionControl.cmake +++ b/modules/ECMSourceVersionControl.cmake @@ -12,6 +12,7 @@ #============================================================================= # Copyright 2019 Harald Sitter +# Copyright 2019 Thomas Fischer # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -44,3 +45,82 @@ else() set(ECM_SOURCE_UNDER_VERSION_CONTROL FALSE) endif() + +if(EXISTS "${CMAKE_SOURCE_DIR}/.git") + # Git + find_program(GIT_EXECUTABLE + NAMES git.bat git # for Windows, 'git.bat' must be found before 'git' + ) + if(GIT_EXECUTABLE) + execute_process( + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + COMMAND "${GIT_EXECUTABLE}" rev-parse --short HEAD + OUTPUT_VARIABLE ECM_SOURCE_VERSION_CONTROL_REVISION + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + execute_process( + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + COMMAND "${GIT_EXECUTABLE}" rev-parse --abbrev-ref HEAD + OUTPUT_VARIABLE ECM_SOURCE_VERSION_CONTROL_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + execute_process( + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + COMMAND "${GIT_EXECUTABLE}" rev-list --count HEAD + OUTPUT_VARIABLE ECM_SOURCE_VERSION_CONTROL_COMMIT_COUNT + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + else() + message("No Git executable found despite Git repository found") + endif() +elseif(EXISTS "${CMAKE_SOURCE_DIR}/.svn") + # Subversion + find_program(SVN_EXECUTABLE + NAMES svn.bat svn # for Windows, 'svn.bat' must be found before 'svn' + ) + if(SVN_EXECUTABLE) + execute_process( + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + COMMAND "${SVN_EXECUTABLE}" info --show-item relative-url + OUTPUT_VARIABLE ECM_SOURCE_VERSION_CONTROL_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + execute_process( + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + COMMAND "${SVN_EXECUTABLE}" info --show-item last-changed-revision # FIXME or just 'revision'? + OUTPUT_VARIABLE ECM_SOURCE_VERSION_CONTROL_COMMIT_COUNT + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + set(ECM_SOURCE_VERSION_CONTROL_REVISION + "r${ECM_SOURCE_VERSION_CONTROL_COMMIT_COUNT}" # FIXME is this the 'r' the only difference between revision and commit count? + ) + else() + message("No Subversion executable found despite Subversion repository found") + endif() +elseif(EXISTS "${CMAKE_SOURCE_DIR}/.hg") + # Mercurial + find_program(HG_EXECUTABLE + NAMES hg.bat hg # for Windows, 'hg.bat' must be found before 'hg' + ) + if(HG_EXECUTABLE) + execute_process( + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + COMMAND "${HG_EXECUTABLE}" branch + OUTPUT_VARIABLE ECM_SOURCE_VERSION_CONTROL_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + # TODO ECM_SOURCE_VERSION_CONTROL_COMMIT_COUNT and ECM_SOURCE_VERSION_CONTROL_REVISION + else() + message("No Mercurial executable found despite Mercurial repository found") + endif() +elseif(EXISTS "${CMAKE_SOURCE_DIR}/.bzr") + # Bazaar + find_program(BZR_EXECUTABLE + NAMES bzr.bat bzr # for Windows, 'bzr.bat' must be found before 'bzr' + ) + if(BZR_EXECUTABLE) + # TODO ECM_SOURCE_VERSION_CONTROL_BRANCH and ECM_SOURCE_VERSION_CONTROL_COMMIT_COUNT and ECM_SOURCE_VERSION_CONTROL_REVISION + else() + message("No Bazaar executable found despite Bazaar repository found") + endif() +endif()