Skip to content

CMake: version management #141

Closed

Description

@Mizux

Currently the version is hard coded directly in CMakeLists.txt, e.g.:

project(CpuFeatures VERSION 0.6.0 LANGUAGES C)

So each time a new release is pushed, using the github release interface, you must do the sync manually with the CMakeLists.txt

We should instead try to generate it from the last git tag (and fallback to 9.9.9 or 9999 like gentoo) IMHO

Proposal

A small proposal (not tested!!!)

CMakeLists.txt:

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(utils)
set_version(VERSION)
project(CpuFeatures VERSION ${VERSION} LANGUAGES C)

cmake/utils.cmake:

function(get_version_from_git_tag GIT_VERSION)
  find_package(Git QUIET)
  if(NOT GIT_FOUND)
    message(STATUS "Did not find git package.")
    set(VERSION 9.9.9)
  else()
    # If no tags can be found, it is a git shallow clone
    execute_process(COMMAND
      ${GIT_EXECUTABLE} describe --tags
      RESULT_VARIABLE _OUTPUT_VAR
      OUTPUT_VARIABLE FULL
      ERROR_QUIET
      WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
    if(NOT _OUTPUT_VAR)
      set(VERSION "${RESULT_VARIABLE}")
    else()
      message(STATUS "Did not find any tag.")
      set(VERSION "9.9.9")
    endif()
  endif()
  set(${GIT_VERSION} "${VERSION}" PARENT_SCOPE)
endfunction()

function(set_version VERSION)
  # Retrieve version from git tag if .git is present otherwise set it to 9.9.9
  get_filename_component(GIT_DIR ".git" ABSOLUTE)
  if(EXISTS ${GIT_DIR})
    get_version_from_git_tag(GIT_VERSION)
  else()
    # If not a git repo force version to 9.9.9
    set(GIT_VERSION "9.9.9")
  endif()
  set(${VERSION} "${GIT_VERSION}" PARENT_SCOPE)
endfunction()

ref: Gentoo 9999 ebuild https://forums.gentoo.org/viewtopic-p-7428490.html

Activity

  1. added
    bug
    enhancement
    cmake
    on Oct 15, 2020
  2. gchatelet commented on Oct 15, 2020

    @gchatelet
    Collaborator

    Thanks for the proposal! How does this interact with installation? Does it put a burden on package maintainers?

  3. Mizux commented on Oct 15, 2020

    @Mizux
    CollaboratorAuthor

    For package maintainers using a git clone with the tag, it should work as expected.
    Now the bad news, for archive based build, you'll end up with the version fallback i.e. the wrong version name.

  4. gchatelet commented on Oct 15, 2020

    @gchatelet
    Collaborator

    As per our off line discussion let's create a simple bash script that will take care of the release process (version bump, tag, github release and release notes)

  5. added a commit that references this issue on Oct 16, 2020
    956cf8e
  6. added a commit that references this issue on Oct 16, 2020
    6d0767e
  7. self-assigned this
    on Jun 11, 2021
  8. added this to the v0.7.0 milestone on Jun 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugcmakeenhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions