Skip to content

Commit

Permalink
safestringlib: add version to the library.
Browse files Browse the repository at this point in the history
The library exports macros
SAFEC_VERSION and SAFEC_VERSION_STRING macros.
The shared library is versioned too.

Signed-off-by: Tomas Winkler <[email protected]>
  • Loading branch information
Tomas Winkler committed Nov 24, 2021
1 parent 999ee37 commit 88d4f87
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(safestring)

include(version.cmake)

option(BUILD_UNITTESTS "Build also project unit-tests" OFF)

if (NOT DEFINED BUILD_OPT_DEFAULT)
Expand Down Expand Up @@ -183,6 +185,9 @@ add_library(${PROJECT_NAME}_static STATIC $<TARGET_OBJECTS:${PROJECT_NAME}_objli
target_include_directories(${PROJECT_NAME}_shared PUBLIC include)
target_include_directories(${PROJECT_NAME}_static PUBLIC include)

set_target_properties(${PROJECT_NAME}_shared PROPERTIES VERSION ${SAFEC_VERSION_STRING})
set_target_properties(${PROJECT_NAME}_static PROPERTIES VERSION ${SAFEC_VERSION_STRING})

if(BUILD_UNITTESTS)
add_subdirectory(unittests)
endif()
13 changes: 13 additions & 0 deletions include/safe_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Modified 2012, Jonathan Toppins <[email protected]>
*
* Copyright (c) 2008-2013 by Cisco Systems, Inc
* Copyright (c) 2021 by Intel Corp
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person
Expand Down Expand Up @@ -37,6 +38,18 @@
extern "C" {
#endif

/* Define safe_lib version number */
#define SAFEC_VERSION_MAJOR 1
#define SAFEC_VERSION_MINOR 1
#define SAFEC_VERSION_PATCH 0
#define SAFEC_VERSION_STRING "1.1.0"

#define SAFEC_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
#define SAFEC_VERSION \
SAFEC_VERSION_NUM(SAFEC_VERSION_MAJOR, \
SAFEC_VERSION_MINOR, \
SAFEC_VERSION_PATCH)

#include "safe_types.h"
#include "safe_lib_errno.h"

Expand Down
16 changes: 16 additions & 0 deletions version.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SPDX-License-Identifier: MIT
# Copyright (C) 2021 Intel Corporation

file(READ "include/safe_lib.h" VER_FILE)

string(REGEX MATCH "SAFEC_VERSION_MAJOR ([0-9]*)" _ ${VER_FILE})
set(SAFEC_VERSION_MAJOR ${CMAKE_MATCH_1})

string(REGEX MATCH "SAFEC_VERSION_MINOR ([0-9]*)" _ ${VER_FILE})
set(SAFEC_VERSION_MINOR ${CMAKE_MATCH_1})

string(REGEX MATCH "SAFEC_VERSION_PATCH ([0-9]*)" _ ${VER_FILE})
set(SAFEC_VERSION_PATCH ${CMAKE_MATCH_1})

set(SAFEC_VERSION_STRING
${SAFEC_VERSION_MAJOR}.${SAFEC_VERSION_MINOR}.${SAFEC_VERSION_PATCH})

0 comments on commit 88d4f87

Please sign in to comment.