Skip to content

Commit

Permalink
build: trying to parse version info from header
Browse files Browse the repository at this point in the history
  • Loading branch information
jgaeddert committed Oct 26, 2024
1 parent 6e86192 commit de0ad54
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 9 deletions.
23 changes: 16 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2007 - 2023 Joseph Gaeddert
# Copyright (c) 2007 - 2024 Joseph Gaeddert
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -31,6 +31,14 @@
#

cmake_minimum_required(VERSION 3.10)

# run custom command to parse version number from include/liquid.h
#execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/version.sh
# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
# OUTPUT_VARIABLE LIQUID_VERSION)

# project definition
#project(liquid VERSION ${LIQUID_VERSION} LANGUAGES C CXX)
project(liquid VERSION 1.6.0 LANGUAGES C CXX)

# require a C99 compiler for all targets
Expand Down Expand Up @@ -762,15 +770,16 @@ set_target_properties(${LIBNAME_PYTHON} PROPERTIES OUTPUT_NAME liquid)

# enable python extensions to C++ classes
target_compile_definitions(${LIBNAME_PYTHON} PUBLIC LIQUID_PYTHONLIB)
# pull version info from pyproject.toml
# pull version info from top of this file
target_compile_definitions(${LIBNAME_PYTHON} PRIVATE VERSION_INFO="${liquid_VERSION}")

install(TARGETS ${LIBNAME_PYTHON} LIBRARY DESTINATION .)


# dump a (sorted) list of cmake variables
# get_cmake_property(_variableNames VARIABLES)
# list (SORT _variableNames)
# foreach (_variableName ${_variableNames})
# message(STATUS "${_variableName}=${${_variableName}}")
# endforeach()
get_cmake_property(_variableNames VARIABLES)
list (SORT _variableNames)
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()

24 changes: 22 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ build-backend = "scikit_build_core.build"
[project]
name = "liquid-dsp"
description = "software-defined radio digital signal processing library"
version = "1.6.0"
#dynamic = ["version"]
#version = "1.6.0"
dynamic = ["version"] # set automatically from cmake
requires-python = ">= 3.7"
authors = [{name = "Joseph D. Gaeddert", email = "[email protected]"}]
dependencies = []
Expand All @@ -32,8 +32,28 @@ Repository = "https://github.com/jgaeddert/liquid-dsp"
Issues = "https://github.com/jgaeddert/liquid-dsp/issues"
Changelog = "https://github.com/jgaeddert/liquid-dsp/blob/master/CHANGELOG.md"

[tool.scikit-build]
cmake.verbose = true
logging.level = "INFO"
#metadata.version.provider = "scikit_build_core.metadata.setuptools_scm"
#sdist.include = ["_version.py"]


[tool.scikit-build.metadata.version]
provider = "scikit_build_core.metadata.regex"
input = "include/liquid.h"
regex = '''(?sx)
\#define \s+ LIQUID_VERSION_MAJOR \s+ (?P<major>\d+) .*?
\#define \s+ LIQUID_VERSION_MINOR \s+ (?P<minor>\d+) .*?
\#define \s+ LIQUID_VERSION_PATCH \s+ (?P<patch>\d+) .*?
\#define \s+ LIQUID_VERSION_DEV \s+ (?P<dev>\d+) .*?
'''
result = "{major}.{minor}.{patch}dev{dev}"
remove = "dev0"

#[tool.setuptools_scm] # Section required
#write_to = "_version.py"

#[project.scripts]
#liquid = "liquid:main_cli"

Expand Down
55 changes: 55 additions & 0 deletions scripts/version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/sh

# This script parses the global header and extracts the major.minor.patch version for
# liquid-dsp and prints to the screen. This is a simplified version of:
# https://github.com/tinyalsa/tinyalsa/blob/master/scripts/version.sh

INCLUDE_FILE="include/liquid.h"

# exit program with error
die()
{
echo "error: $@" 1>&2
exit 1
}

# check that file exists
check_files()
{
[ -f ${INCLUDE_FILE} ] || die "No ${INCLUDE_FILE} found!";
}

# get a part of the version from the header, e.g. LIQUID_VERSION_MAJOR
get_version_part()
{
set -- "$1" "$(grep -m 1 "^#define\([ \t]*\)$1" ${INCLUDE_FILE} | sed 's/[^0-9]*//g')"

if [ -z "$2" ]; then
die "Could not get $1 from ${INCLUDE_FILE}"
fi

echo "$2"
}

# gets the complete version from the include file
get_version()
{
VERSION_MAJOR=$(get_version_part "LIQUID_VERSION_MAJOR")
VERSION_MINOR=$(get_version_part "LIQUID_VERSION_MINOR")
VERSION_PATCH=$(get_version_part "LIQUID_VERSION_PATCH")
}

print_version()
{
printf "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}${LF}"
return 0
}

check_files
get_version
print_version "$2"
exit $?

# The script should never reach this place.
die "Internal error. Please report this."

0 comments on commit de0ad54

Please sign in to comment.