Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: get version with CMakeExtraUtils #435

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .git_archival.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node: $Format:%H$
node-date: $Format:%cI$
describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.git_archival.txt export-subst
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
include(NuriKitUtils)

nuri_get_version()
project(NuriKit VERSION "${NURI_CORE_VERSION}" LANGUAGES CXX)
project(NuriKit VERSION "${PROJECT_VERSION}" LANGUAGES CXX)

# Compile options
set(NURI_OPTIMIZATION_LEVEL "O3" CACHE STRING "Optimization level")
Expand Down
87 changes: 12 additions & 75 deletions cmake/NuriKitUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,87 +3,24 @@
# SPDX-License-Identifier: Apache-2.0
#

macro(_nuri_get_git_version_impl)
find_package(Git)

if(NOT Git_FOUND)
return()
endif()

execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
RESULT_VARIABLE git_result
OUTPUT_VARIABLE nuri_revision
ERROR_QUIET)
string(STRIP "${nuri_revision}" nuri_revision)

execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --exact-match --abbrev=0
RESULT_VARIABLE git_result
OUTPUT_VARIABLE NURI_REF
ERROR_QUIET)

if(git_result EQUAL 0)
string(STRIP "${NURI_REF}" NURI_REF)
string(REGEX REPLACE "^v" "" NURI_VERSION "${NURI_REF}")
set(NURI_FULL_VERSION "${NURI_VERSION}")
message(STATUS "NuriKit version from git: ${NURI_FULL_VERSION}")
else()
execute_process(
COMMAND ${GIT_EXECUTABLE} symbolic-ref -q --short HEAD
RESULT_VARIABLE git_result
OUTPUT_VARIABLE NURI_REF
ERROR_QUIET)

if(NOT git_result EQUAL 0)
set(NURI_REF "${nuri_revision}")
endif()

string(STRIP "${NURI_REF}" NURI_REF)
endif()
endmacro()

function(nuri_get_version)
macro(nuri_get_version)
if(SKBUILD)
# Version correctly set via scikit-build-core; skip git versioning.
set(NURI_FULL_VERSION "${SKBUILD_PROJECT_VERSION_FULL}")
string(REGEX REPLACE "\\+.+$" "" NURI_VERSION "${NURI_FULL_VERSION}")
message(
STATUS "NuriKit version from scikit-build-core: ${NURI_FULL_VERSION}")
else()
_nuri_get_git_version_impl()
endif()

if(NURI_REF)
message(STATUS "NuriKit ref from git: ${NURI_REF}")
else()
message(NOTICE "NuriKit ref not found! Using unknown.")
set(NURI_REF "unknown")
endif()

if(nuri_revision)
message(STATUS "NuriKit revision from git: ${nuri_revision}")
else()
message(NOTICE "NuriKit revision not found! Using unknown.")
set(nuri_revision "unknown")
return()
endif()

if(NOT NURI_FULL_VERSION)
set(NURI_VERSION "0.1.0.dev0")
set(NURI_FULL_VERSION "${NURI_VERSION}+${nuri_revision}")
message(NOTICE "NuriKit version not found! Using ${NURI_FULL_VERSION}")
endif()
include(FetchContent)
Fetchcontent_Declare(
CMakeExtraUtils
GIT_REPOSITORY https://github.com/LecrisUT/CMakeExtraUtils.git
GIT_TAG v0.4.1
)
FetchContent_MakeAvailable(CMakeExtraUtils)

string(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+"
NURI_CORE_VERSION "${NURI_VERSION}")
include(DynamicVersion)
dynamic_version(PROJECT_PREFIX NuriKit_)

string(TIMESTAMP NURI_YEAR "%Y" UTC)
set(NURI_YEAR "${NURI_YEAR}" PARENT_SCOPE)
set(NURI_VERSION "${NURI_VERSION}" PARENT_SCOPE)
set(NURI_CORE_VERSION "${NURI_CORE_VERSION}" PARENT_SCOPE)
set(NURI_FULL_VERSION "${NURI_FULL_VERSION}" PARENT_SCOPE)
set(NURI_REF "${NURI_REF}" PARENT_SCOPE)
endfunction()
endmacro()

function(nuri_make_available_deponly target)
include(FetchContent)
Expand Down
2 changes: 1 addition & 1 deletion docs/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ PROJECT_NAME = "@PROJECT_NAME@"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = "@NURI_REF@"
PROJECT_NUMBER = "@PROJECT_VERSION_FULL@"

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
4 changes: 2 additions & 2 deletions include/nuri/nurikit_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

namespace nuri {
// NOLINTBEGIN(clang-diagnostic-unused-const-variable)
constexpr std::string_view kNuriVersion = "@NURI_VERSION@";
constexpr std::string_view kNuriFullVersion = "@NURI_FULL_VERSION@";
constexpr std::string_view kNuriVersion = "@PROJECT_VERSION@";
constexpr std::string_view kNuriFullVersion = "@PROJECT_VERSION_FULL@";
// NOLINTEND(clang-diagnostic-unused-const-variable)
} // namespace nuri

Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ build-backend = "scikit_build_core.build"

[project]
name = "nurikit"
version = "@NURI_FULL_VERSION@"
version = "@PROJECT_VERSION_FULL@"
description = "*The* fundamental software platform for chem- and bio-informatics"
readme = "README.md"
requires-python = ">=3.7"
Expand Down Expand Up @@ -75,7 +75,6 @@ NURI_ENABLE_SANITIZERS = "@NURI_ENABLE_SANITIZERS@"
NURI_TEST_COVERAGE = "@NURI_TEST_COVERAGE@"
NURI_BUILD_DOCS = "OFF"
NURI_BUILD_PYTHON_DOCS = "OFF"
NURI_REF = "@NURI_REF@"
NURI_OPTIMIZATION_LEVEL = "@NURI_OPTIMIZATION_LEVEL@"
NURI_ENABLE_IPO = "@NURI_ENABLE_IPO@"

Expand Down
5 changes: 3 additions & 2 deletions python/docs/conf.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

import doctest
import re
from datetime import date

import doctest
from sphinx.ext import autodoc

# -- Project information -----------------------------------------------------
Expand All @@ -19,7 +20,7 @@ from sphinx.ext import autodoc
project = "@PROJECT_NAME@"
copyright = "@NURI_YEAR@ SNU Compbio Lab"
author = "SNU Compbio Lab"
release = "@NURI_REF@"
release = "@PROJECT_VERSION_FULL@"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
4 changes: 2 additions & 2 deletions python/src/nuri/_version.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# SPDX-License-Identifier: Apache-2.0
#

__version__ = "@NURI_VERSION@"
__full_version__ = "@NURI_FULL_VERSION@"
__version__ = "@PROJECT_VERSION@"
__full_version__ = "@PROJECT_VERSION_FULL@"
Loading