-
-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
be8a262
Initial commit
sdebionne ed51b3b
Add test section
sdebionne c8bae80
fixup! Initial commit
sdebionne 19c7117
Workaround conda-build#4241
sdebionne 86aa264
fixup! Add test section
sdebionne c016969
Add Windows support
sdebionne 0282683
fixup! Add Windows support
sdebionne f8eb97a
fixup! Add Windows support
sdebionne 1db2338
fixup! Add Windows support
sdebionne 287080b
fixup! Add Windows support
sdebionne e5c1f38
fixup! Add Windows support
sdebionne 20d6bb2
fixup! Add Windows support
sdebionne 27749f5
fixup! Add Windows support
sdebionne 2710e2d
fixup! Add Windows support
sdebionne 710d2f0
fixup! Add Windows support
sdebionne 7dd3e9c
fixup! Add Windows support
sdebionne c970651
Cleanup meta.yaml comments and add run_exports constraints
sdebionne c6a7bcb
Add ${CMAKE_ARGS} to the cmake command line
sdebionne 0e7f9b1
Remove LICENCE file
sdebionne 377f003
Merge branch 'main' into tinycbor
carterbox f05c42a
Use stdlib template
carterbox add974c
Add CMAKE_ARGS to Windows build
carterbox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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
25
recipes/tinycbor/0002-Fix-static_assert-compiler-support.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 +- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you opened a pull request to upstream this patch? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ARGS% | ||
cmake --build build --target install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
cmake -Bbuild -H. -G "Ninja" ${CMAKE_ARGS} -DCMAKE_FIND_ROOT_PATH:PATH=${PREFIX} -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY | ||
cmake --build build --target install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{% set name = "tinycbor" %} | ||
{% set version = "0.6.0" %} | ||
|
||
package: | ||
name: {{ name|lower }} | ||
version: {{ version }} | ||
|
||
source: | ||
url: https://github.com/intel/tinycbor/archive/v{{ version }}.tar.gz | ||
sha256: 512e2c9fce74f60ef9ed3af59161e905f9e19f30a52e433fc55f39f4c70d27e4 | ||
patches: | ||
- 0001-Add-CMake-support.patch | ||
- 0002-Fix-static_assert-compiler-support.patch | ||
|
||
build: | ||
sdebionne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
number: 0 | ||
run_exports: | ||
- {{ pin_subpackage( name|lower, max_pin='x.x' ) }} | ||
|
||
requirements: | ||
build: | ||
- {{ compiler('c') }} | ||
- {{ stdlib('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. | ||
license: MIT | ||
license_family: MIT | ||
license_file: LICENSE | ||
doc_url: https://intel.github.io/tinycbor/current/ | ||
dev_url: https://github.com/intel/tinycbor | ||
|
||
extra: | ||
recipe-maintainers: | ||
- sdebionne |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.