diff --git a/CMakeLists.txt b/CMakeLists.txt index fdad60d1b..240aed2b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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 @@ -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() diff --git a/pyproject.toml b/pyproject.toml index 4a81f4965..827de69c7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = "joseph@liquidsdr.org"}] dependencies = [] @@ -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\d+) .*? +\#define \s+ LIQUID_VERSION_MINOR \s+ (?P\d+) .*? +\#define \s+ LIQUID_VERSION_PATCH \s+ (?P\d+) .*? +\#define \s+ LIQUID_VERSION_DEV \s+ (?P\d+) .*? +''' +result = "{major}.{minor}.{patch}dev{dev}" +remove = "dev0" + +#[tool.setuptools_scm] # Section required +#write_to = "_version.py" + #[project.scripts] #liquid = "liquid:main_cli" diff --git a/scripts/version.sh b/scripts/version.sh new file mode 100755 index 000000000..2c9316e7a --- /dev/null +++ b/scripts/version.sh @@ -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." +