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

Add tinycbor c++ library package #21900

Merged
merged 22 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 16 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
209 changes: 209 additions & 0 deletions recipes/tinycbor/0001-Add-CMake-support.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
From e0fcc34f29633e8d4213581ad1c40575f9d2a0f1 Mon Sep 17 00:00:00 2001
From: Samuel Debionne <[email protected]>
Date: Wed, 23 Aug 2023 16:13:36 +0200
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you opened a PR to upstream this patch? Does this CMake build system generate artifacts that are named the same as the ones generated by makefiles? For example, sometimes the DLL name on windows might have/not have the lib prefix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure the original build system supports Windows, I'll need to check.

Subject: [PATCH 1/2] Add CMake support

---
CMakeLists.txt | 95 +++++++++++++++++++++++++++++++++++
cmake/PackageConfig.cmake | 35 +++++++++++++
cmake/project-config.cmake.in | 16 ++++++
src/cbor.h | 2 +-
tests/CMakeLists.txt | 3 ++
5 files changed, 150 insertions(+), 1 deletion(-)
create mode 100644 CMakeLists.txt
create mode 100644 cmake/PackageConfig.cmake
create mode 100644 cmake/project-config.cmake.in
create mode 100644 tests/CMakeLists.txt

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..08d5d45
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,95 @@
+# /****************************************************************************
+# **
+# ** Copyright (C) 2015 Intel Corporation
+# **
+# ** Permission is hereby granted, free of charge, to any person obtaining a copy
+# ** of this software and associated documentation files (the "Software"), to deal
+# ** in the Software without restriction, including without limitation the rights
+# ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# ** copies of the Software, and to permit persons to whom the Software is
+# ** furnished to do so, subject to the following conditions:
+# **
+# ** The above copyright notice and this permission notice shall be included in
+# ** all copies or substantial portions of the Software.
+# **
+# ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# ** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# ** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# ** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# ** THE SOFTWARE.
+# **
+# ****************************************************************************/
+
+cmake_minimum_required(VERSION 3.10)
+
+project(tinycbor LANGUAGES C VERSION 0.6.0)
+
+# Set path to additional cmake scripts
+set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
+
+set(TARGETS_EXPORT_NAME "tinycbor-targets")
+
+# Include additional modules that are used unconditionally
+include(GNUInstallDirs)
+include(GenerateExportHeader)
+
+add_library(tinycbor SHARED
+ src/cborencoder.c
+ src/cborencoder_close_container_checked.c
+ src/cborerrorstrings.c
+ src/cborparser.c
+ src/cborparser_dup_string.c
+ src/cborpretty.c
+ src/cborpretty_stdio.c
+ src/cbortojson.c
+ src/cborvalidation.c
+ src/cbor.h
+ src/tinycbor-version.h
+)
+
+# Generate export macros
+generate_export_header(tinycbor BASE_NAME "cbor" EXPORT_MACRO_NAME "CBOR_API" EXPORT_FILE_NAME "tinycbor-export.h")
+
+# Check for open_memstream and store the result in HAVE_OPEN_MEMSTREAM
+include (CheckSymbolExists)
+check_symbol_exists(open_memstream stdio.h HAVE_OPEN_MEMSTREAM)
+check_symbol_exists(funopen stdio.h HAVE_OPEN_FUNOPEN)
+check_symbol_exists(fopencookie stdio.h HAVE_OPEN_FOPENCOOKIE)
+
+if(NOT HAVE_OPEN_MEMSTREAM)
+ if (HAVE_OPEN_FUNOPEN AND HAVE_OPEN_FOPENCOOKIE)
+ message(STATUS "using open_memstream implementation")
+ target_sources(tinycbor PRIVATE src/open_memstream.c)
+ else()
+ target_compile_definitions(tinycbor PRIVATE WITHOUT_OPEN_MEMSTREAM)
+ message(WARNING "funopen and fopencookie unavailable, open_memstream can not be implemented and conversion to JSON will not work properly!")
+ endif()
+endif()
+
+target_include_directories(tinycbor
+ PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
+ PUBLIC "$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>"
+ PUBLIC "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
+
+# Set version and output name
+set_target_properties(tinycbor PROPERTIES
+ VERSION "${PROJECT_VERSION}"
+ SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
+
+install(FILES src/cbor.h src/tinycbor-version.h ${CMAKE_BINARY_DIR}/tinycbor-export.h TYPE INCLUDE)
+install(
+ TARGETS tinycbor
+ EXPORT "${TARGETS_EXPORT_NAME}"
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} # import library
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} # .so files are libraries
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} # .dll files are binaries
+ INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} # this does not actually install anything (but used by downstream projects)
+)
+
+set (PROJECT_LIBRARIES tinycbor)
+include(PackageConfig)
+
+enable_testing()
+add_subdirectory(tests)
diff --git a/cmake/PackageConfig.cmake b/cmake/PackageConfig.cmake
new file mode 100644
index 0000000..ec9cff8
--- /dev/null
+++ b/cmake/PackageConfig.cmake
@@ -0,0 +1,35 @@
+# This cmake code creates the configuration that is found and used by
+# find_package() of another cmake project
+
+# get lower and upper case project name for the configuration files
+
+# configure and install the configuration files
+include(CMakePackageConfigHelpers)
+
+configure_package_config_file(
+ "${CMAKE_SOURCE_DIR}/cmake/project-config.cmake.in"
+ "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
+ INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
+ #PATH_VARS CMAKE_INSTALL_DIR
+)
+
+write_basic_package_version_file(
+ "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
+ VERSION ${PROJECT_VERSION}
+ COMPATIBILITY SameMinorVersion
+)
+
+install(FILES
+ "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
+ "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
+ COMPONENT devel
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
+)
+
+if (PROJECT_LIBRARIES OR PROJECT_STATIC_LIBRARIES)
+ install(
+ EXPORT "${TARGETS_EXPORT_NAME}"
+ FILE ${TARGETS_EXPORT_NAME}.cmake
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
+ )
+endif ()
diff --git a/cmake/project-config.cmake.in b/cmake/project-config.cmake.in
new file mode 100644
index 0000000..6729c5c
--- /dev/null
+++ b/cmake/project-config.cmake.in
@@ -0,0 +1,16 @@
+# Config file for @PROJECT_NAME_LOWER@
+#
+# It defines the following variables:
+#
+# @PROJECT_NAME_UPPER@_INCLUDE_DIRS - include directory
+# @PROJECT_NAME_UPPER@_LIBRARIES - all dynamic libraries
+# @PROJECT_NAME_UPPER@_STATIC_LIBRARIES - all static libraries
+
+@PACKAGE_INIT@
+
+include(CMakeFindDependencyMacro)
+
+# Add optional dependencies here
+
+include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
+check_required_components("@PROJECT_NAME@")
diff --git a/src/cbor.h b/src/cbor.h
index be5bbc7..1868e9e 100644
--- a/src/cbor.h
+++ b/src/cbor.h
@@ -35,6 +35,7 @@
#include <stdio.h>

#include "tinycbor-version.h"
+#include "tinycbor-export.h"

#define TINYCBOR_VERSION ((TINYCBOR_VERSION_MAJOR << 16) | (TINYCBOR_VERSION_MINOR << 8) | TINYCBOR_VERSION_PATCH)

@@ -721,4 +722,3 @@ CBOR_INLINE_API CborError cbor_value_to_pretty(FILE *out, const CborValue *value
#endif

#endif /* CBOR_H */
-
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644
index 0000000..92a2be0
--- /dev/null
+++ b/tests/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_executable(tst_c90 c90/tst_c90.c)
+target_link_libraries(tst_c90 tinycbor)
+add_test(NAME c90 COMMAND tst_c90)
--
2.34.1
25 changes: 25 additions & 0 deletions recipes/tinycbor/0002-Fix-static_assert-compiler-support.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From 6639f6db4d0a0b88dbbd7c0eda6a2b1e08ae22d2 Mon Sep 17 00:00:00 2001
From: Samuel Debionne <[email protected]>
Date: Wed, 23 Aug 2023 16:14:19 +0200
Subject: [PATCH 2/2] Fix static_assert compiler support

---
src/compilersupport_p.h | 2 +-
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you opened a pull request to upstream this patch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have just opened intel/tinycbor#242

1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/compilersupport_p.h b/src/compilersupport_p.h
index 0879801..27042ce 100644
--- a/src/compilersupport_p.h
+++ b/src/compilersupport_p.h
@@ -44,7 +44,7 @@
# include <stdbool.h>
#endif

-#if __STDC_VERSION__ >= 201112L || (defined(__cplusplus) && __cplusplus >= 201103L) || (defined(__cpp_static_assert) && __cpp_static_assert >= 200410)
+#if __STDC_VERSION__ >= 202311L || (defined(__cplusplus) && __cplusplus >= 201103L) || (defined(__cpp_static_assert) && __cpp_static_assert >= 200410)
# define cbor_static_assert(x) static_assert(x, #x)
#elif !defined(__cplusplus) && defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406) && (__STDC_VERSION__ > 199901L)
# define cbor_static_assert(x) _Static_assert(x, #x)
--
2.34.1

21 changes: 21 additions & 0 deletions recipes/tinycbor/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License
sdebionne marked this conversation as resolved.
Show resolved Hide resolved

Copyright (c) 2017 Intel Corporation

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 2 additions & 0 deletions recipes/tinycbor/bld.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cmake -Bbuild -H. -G "Ninja" -DCMAKE_INSTALL_PREFIX=%LIBRARY_PREFIX% -DCMAKE_FIND_ROOT_PATH=%LIBRARY_PREFIX% -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY
cmake --build build --target install
3 changes: 3 additions & 0 deletions recipes/tinycbor/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
cmake -Bbuild -H. -G "Ninja" -DCMAKE_INSTALL_PREFIX=$PREFIX -DCMAKE_FIND_ROOT_PATH=$PREFIX -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY
sdebionne marked this conversation as resolved.
Show resolved Hide resolved
cmake --build build --target install
90 changes: 90 additions & 0 deletions recipes/tinycbor/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Note: there are many handy hints in comments in this example -- remove them when you've finalized your recipe
# If your package is python based, we recommend using Grayskull to generate it instead:
# https://github.com/conda-incubator/grayskull

# Jinja variables help maintain the recipe as you'll update the version only here.
# Using the name variable with the URL in line 14 is convenient
# when copying and pasting from another recipe, but not really needed.
{% set name = "tinycbor" %}
{% set version = "0.6.0" %}

package:
name: {{ name|lower }}
version: {{ version }}

source:
# If getting the source from GitHub, remove the line above,
# uncomment the line below, and modify as needed. Use releases if available:
#url: https://github.com/intel/tinycbor/releases/download/{{ version }}/tinycbor-{{ version }}.tar.gz
# and otherwise fall back to archive:
url: https://github.com/intel/tinycbor/archive/v{{ version }}.tar.gz
sha256: 512e2c9fce74f60ef9ed3af59161e905f9e19f30a52e433fc55f39f4c70d27e4
# sha256 is the preferred checksum -- you can get it for a file with:
# `openssl sha256 <file name>`.
# You may need the openssl package, available on conda-forge:
# `conda install openssl -c conda-forge``
patches:
- 0001-Add-CMake-support.patch
- 0002-Fix-static_assert-compiler-support.patch

build:
sdebionne marked this conversation as resolved.
Show resolved Hide resolved
# Uncomment the following line if the package is pure Python and the recipe is exactly the same for all platforms.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove all the explainer comments if you're done with them. The comments are still available in the reference recipe.

# It is okay if the dependencies are not built for all platforms/versions, although selectors are still not allowed.
# See https://conda-forge.org/docs/maintainer/knowledge_base.html#noarch-python for more details.
# noarch: python
# If the installation is complex, or different between Unix and Windows, use separate bld.bat and build.sh files instead of this key.
# By default, the package will be built for the Python versions supported by conda-forge and for all major OSs.
# Add the line "skip: True # [py<35]" (for example) to limit to Python 3.5 and newer, or "skip: True # [not win]" to limit to Windows.
# More info about selectors can be found in the conda-build docs:
# https://docs.conda.io/projects/conda-build/en/latest/resources/define-metadata.html#preprocessing-selectors
number: 0

requirements:
build:
# If your project compiles code (such as a C extension) then add the required compilers as separate entries here.
# Compilers are named 'c', 'cxx' and 'fortran'.
- {{ compiler('c') }}
- cmake
- ninja

test:
commands:
- test -f ${PREFIX}/lib/libtinycbor${SHLIB_EXT} # [unix]
- test -f ${PREFIX}/lib/cmake/tinycbor/tinycbor-targets.cmake # [unix]
- test -f ${PREFIX}/include/cbor.h # [unix]
- test -f ${PREFIX}/include/tinycbor-version.h # [unix]
- test -f ${PREFIX}/include/tinycbor-export.h # [unix]
- if not exist %LIBRARY_BIN%\tinycbor.dll exit 1 # [win]
- if not exist %LIBRARY_LIB%\tinycbor.lib exit 1 # [win]
- if not exist %LIBRARY_LIB%\cmake\tinycbor\tinycbor-targets.cmake exit 1 # [win]
- if not exist %LIBRARY_INC%\cbor.h exit 1 # [win]
- if not exist %LIBRARY_INC%\tinycbor-version.h exit 1 # [win]
- if not exist %LIBRARY_INC%\tinycbor-export.h exit 1 # [win]

about:
home: https://github.com/intel/tinycbor
summary: 'Concise Binary Object Representation (CBOR) Library'
description: |
The TinyCBOR library is a small CBOR encoder and decoder library, optimized for very fast
operation with very small footprint. The main encoder and decoder functions do not allocate memory.
# Remember to specify the license variants for BSD, Apache, GPL, and LGPL.
# Use the SPDX identifier, e.g: GPL-2.0-only instead of GNU General Public License version 2.0
# See https://spdx.org/licenses/
license: MIT
# The license_family, i.e. "BSD" if license is "BSD-3-Clause".
# Optional
license_family: MIT
# It is required to include a license file in the package,
# (even if the license doesn't require it) using the license_file entry.
# Please also note that some projects have multiple license files which all need to be added using a valid yaml list.
# See https://docs.conda.io/projects/conda-build/en/latest/resources/define-metadata.html#license-file
license_file: LICENSE
# The doc_url and dev_url are optional.
doc_url: https://intel.github.io/tinycbor/current/
dev_url: https://github.com/intel/tinycbor

extra:
recipe-maintainers:
# GitHub IDs for maintainers of the recipe.
# Always check with the people listed below if they are OK becoming maintainers of the recipe. (There will be spam!)
- sdebionne