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

Fix shared build #148

Merged
merged 1 commit into from
Aug 30, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 11 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,35 @@ if (NOT DEFINED CMAKE_MACOSX_RPATH)
set(CMAKE_MACOSX_RPATH 0)
endif()

add_library(cbor STATIC ${SOURCES})
add_library(cbor_shared SHARED ${SOURCES})
add_library(cbor ${SOURCES})
target_include_directories(cbor PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

include(GenerateExportHeader)
generate_export_header(cbor EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/cbor/cbor_export.h)
target_include_directories(cbor PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cbor/cbor_export.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cbor)

if (NOT ${CBOR_VERSION_MAJOR} EQUAL 0)
MESSAGE(FATAL_ERROR "Change the shared library version scheme to reflect https://github.com/PJK/libcbor/issues/52.")
endif()

set_target_properties(cbor_shared PROPERTIES
OUTPUT_NAME cbor
set_target_properties(cbor PROPERTIES
VERSION ${CBOR_VERSION}
MACHO_COMPATIBILITY_VERSION ${CBOR_VERSION_MAJOR}.${CBOR_VERSION_MINOR}.0
SOVERSION ${CBOR_VERSION_MAJOR}.${CBOR_VERSION_MINOR})

configure_file(libcbor.pc.in libcbor.pc @ONLY)

# http://www.cmake.org/Wiki/CMake:Install_Commands
install(TARGETS cbor_shared
install(TARGETS cbor
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION bin)
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

install(DIRECTORY cbor DESTINATION include
install(DIRECTORY cbor DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.h")

install(FILES cbor.h DESTINATION include)
install(FILES cbor.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libcbor.pc"
DESTINATION "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig")
6 changes: 3 additions & 3 deletions src/allocators.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

#include "cbor/common.h"

_cbor_malloc_t _cbor_malloc = malloc;
_cbor_realloc_t _cbor_realloc = realloc;
_cbor_free_t _cbor_free = free;
CBOR_EXPORT _cbor_malloc_t _cbor_malloc = malloc;
CBOR_EXPORT _cbor_realloc_t _cbor_realloc = realloc;
CBOR_EXPORT _cbor_free_t _cbor_free = free;

void cbor_set_allocs(_cbor_malloc_t custom_malloc,
_cbor_realloc_t custom_realloc, _cbor_free_t custom_free) {
Expand Down
9 changes: 5 additions & 4 deletions src/cbor.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "cbor/encoding.h"
#include "cbor/serialization.h"
#include "cbor/streaming.h"
#include "cbor/cbor_export.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -42,8 +43,8 @@ extern "C" {
* @return **new** CBOR item or `NULL` on failure. In that case, \p result
* contains location and description of the error.
*/
cbor_item_t* cbor_load(cbor_data source, size_t source_size,
struct cbor_load_result* result);
CBOR_EXPORT cbor_item_t* cbor_load(cbor_data source, size_t source_size,
struct cbor_load_result* result);

/** Deep copy of an item
*
Expand All @@ -52,12 +53,12 @@ cbor_item_t* cbor_load(cbor_data source, size_t source_size,
* @param item[borrow] item to copy
* @return **new** CBOR deep copy
*/
cbor_item_t* cbor_copy(cbor_item_t* item);
CBOR_EXPORT cbor_item_t* cbor_copy(cbor_item_t* item);

#if CBOR_PRETTY_PRINTER
#include <stdio.h>

void cbor_describe(cbor_item_t* item, FILE* out);
CBOR_EXPORT void cbor_describe(cbor_item_t* item, FILE* out);
#endif

#ifdef __cplusplus
Expand Down
25 changes: 14 additions & 11 deletions src/cbor/arrays.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define LIBCBOR_ARRAYS_H

#include "cbor/common.h"
#include "cbor/cbor_export.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -19,22 +20,22 @@ extern "C" {
* @param item[borrow] An array
* @return The number of members
*/
size_t cbor_array_size(const cbor_item_t* item);
CBOR_EXPORT size_t cbor_array_size(const cbor_item_t* item);

/** Get the size of the allocated storage
*
* @param item[borrow] An array
* @return The size of the allocated storage (number of items)
*/
size_t cbor_array_allocated(const cbor_item_t* item);
CBOR_EXPORT size_t cbor_array_allocated(const cbor_item_t* item);

/** Get item by index
*
* @param item[borrow] An array
* @param index The index
* @return **incref** The item, or `NULL` in case of boundary violation
*/
cbor_item_t* cbor_array_get(const cbor_item_t* item, size_t index);
CBOR_EXPORT cbor_item_t* cbor_array_get(const cbor_item_t* item, size_t index);

/** Set item by index
*
Expand All @@ -45,7 +46,8 @@ cbor_item_t* cbor_array_get(const cbor_item_t* item, size_t index);
* @param index The index, first item is 0.
* @return true on success, false on allocation failure.
*/
bool cbor_array_set(cbor_item_t* item, size_t index, cbor_item_t* value);
CBOR_EXPORT bool cbor_array_set(cbor_item_t* item, size_t index,
cbor_item_t* value);

/** Replace item at an index
*
Expand All @@ -56,21 +58,22 @@ bool cbor_array_set(cbor_item_t* item, size_t index, cbor_item_t* value);
* @param index The index, first item is 0.
* @return true on success, false on allocation failure.
*/
bool cbor_array_replace(cbor_item_t* item, size_t index, cbor_item_t* value);
CBOR_EXPORT bool cbor_array_replace(cbor_item_t* item, size_t index,
cbor_item_t* value);

/** Is the array definite?
*
* @param item[borrow] An array
* @return Is the array definite?
*/
bool cbor_array_is_definite(const cbor_item_t* item);
CBOR_EXPORT bool cbor_array_is_definite(const cbor_item_t* item);

/** Is the array indefinite?
*
* @param item[borrow] An array
* @return Is the array indefinite?
*/
bool cbor_array_is_indefinite(const cbor_item_t* item);
CBOR_EXPORT bool cbor_array_is_indefinite(const cbor_item_t* item);

/** Get the array contents
*
Expand All @@ -80,20 +83,20 @@ bool cbor_array_is_indefinite(const cbor_item_t* item);
* @param item[borrow] An array
* @return #cbor_array_size items
*/
cbor_item_t** cbor_array_handle(const cbor_item_t* item);
CBOR_EXPORT cbor_item_t** cbor_array_handle(const cbor_item_t* item);

/** Create new definite array
*
* @param size Number of slots to preallocate
* @return **new** array or `NULL` upon malloc failure
*/
cbor_item_t* cbor_new_definite_array(size_t size);
CBOR_EXPORT cbor_item_t* cbor_new_definite_array(size_t size);

/** Create new indefinite array
*
* @return **new** array or `NULL` upon malloc failure
*/
cbor_item_t* cbor_new_indefinite_array();
CBOR_EXPORT cbor_item_t* cbor_new_indefinite_array();

/** Append to the end
*
Expand All @@ -104,7 +107,7 @@ cbor_item_t* cbor_new_indefinite_array();
* @param pushee[incref] The item to push
* @return true on success, false on failure
*/
bool cbor_array_push(cbor_item_t* array, cbor_item_t* pushee);
CBOR_EXPORT bool cbor_array_push(cbor_item_t* array, cbor_item_t* pushee);

#ifdef __cplusplus
}
Expand Down
29 changes: 16 additions & 13 deletions src/cbor/bytestrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define LIBCBOR_BYTESTRINGS_H

#include "cbor/common.h"
#include "cbor/cbor_export.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -27,21 +28,21 @@ extern "C" {
* @param item[borrow] a definite bytestring
* @return length of the binary data. Zero if no chunk has been attached yet
*/
size_t cbor_bytestring_length(const cbor_item_t *item);
CBOR_EXPORT size_t cbor_bytestring_length(const cbor_item_t *item);

/** Is the byte string definite?
*
* @param item[borrow] a byte string
* @return Is the byte string definite?
*/
bool cbor_bytestring_is_definite(const cbor_item_t *item);
CBOR_EXPORT bool cbor_bytestring_is_definite(const cbor_item_t *item);

/** Is the byte string indefinite?
*
* @param item[borrow] a byte string
* @return Is the byte string indefinite?
*/
bool cbor_bytestring_is_indefinite(const cbor_item_t *item);
CBOR_EXPORT bool cbor_bytestring_is_indefinite(const cbor_item_t *item);

/** Get the handle to the binary data
*
Expand All @@ -52,7 +53,7 @@ bool cbor_bytestring_is_indefinite(const cbor_item_t *item);
* @return The address of the binary data. `NULL` if no data have been assigned
* yet.
*/
cbor_mutable_data cbor_bytestring_handle(const cbor_item_t *item);
CBOR_EXPORT cbor_mutable_data cbor_bytestring_handle(const cbor_item_t *item);

/** Set the handle to the binary data
*
Expand All @@ -61,9 +62,9 @@ cbor_mutable_data cbor_bytestring_handle(const cbor_item_t *item);
* libcbor will deallocate it when appropriate using its free function
* @param length Length of the data block
*/
void cbor_bytestring_set_handle(cbor_item_t *item,
cbor_mutable_data CBOR_RESTRICT_POINTER data,
size_t length);
CBOR_EXPORT void cbor_bytestring_set_handle(cbor_item_t *item,
cbor_mutable_data CBOR_RESTRICT_POINTER data,
size_t length);

/** Get the handle to the array of chunks
*
Expand All @@ -73,14 +74,15 @@ void cbor_bytestring_set_handle(cbor_item_t *item,
* @param item[borrow] A indefinite byte string
* @return array of #cbor_bytestring_chunk_count definite bytestrings
*/
cbor_item_t **cbor_bytestring_chunks_handle(const cbor_item_t *item);
CBOR_EXPORT cbor_item_t **cbor_bytestring_chunks_handle(
const cbor_item_t *item);

/** Get the number of chunks this string consist of
*
* @param item[borrow] A indefinite bytestring
* @return The chunk count. 0 for freshly created items.
*/
size_t cbor_bytestring_chunk_count(const cbor_item_t *item);
CBOR_EXPORT size_t cbor_bytestring_chunk_count(const cbor_item_t *item);

/** Appends a chunk to the bytestring
*
Expand All @@ -93,23 +95,24 @@ size_t cbor_bytestring_chunk_count(const cbor_item_t *item);
* @return true on success, false on realloc failure. In that case, the refcount
* of `chunk` is not increased and the `item` is left intact.
*/
bool cbor_bytestring_add_chunk(cbor_item_t *item, cbor_item_t *chunk);
CBOR_EXPORT bool cbor_bytestring_add_chunk(cbor_item_t *item,
cbor_item_t *chunk);

/** Creates a new definite byte string
*
* The handle is initialized to `NULL` and length to 0
*
* @return **new** definite bytestring. `NULL` on malloc failure.
*/
cbor_item_t *cbor_new_definite_bytestring();
CBOR_EXPORT cbor_item_t *cbor_new_definite_bytestring();

/** Creates a new indefinite byte string
*
* The chunks array is initialized to `NULL` and chunkcount to 0
*
* @return **new** indefinite bytestring. `NULL` on malloc failure.
*/
cbor_item_t *cbor_new_indefinite_bytestring();
CBOR_EXPORT cbor_item_t *cbor_new_indefinite_bytestring();

/** Creates a new byte string and initializes it
*
Expand All @@ -120,7 +123,7 @@ cbor_item_t *cbor_new_indefinite_bytestring();
* @return A **new** byte string with content `handle`. `NULL` on malloc
* failure.
*/
cbor_item_t *cbor_build_bytestring(cbor_data handle, size_t length);
CBOR_EXPORT cbor_item_t *cbor_build_bytestring(cbor_data handle, size_t length);

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion src/cbor/callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void cbor_null_uint8_callback(void *_ctx, uint8_t _val) CBOR_DUMMY_CALLBACK

void cbor_null_indef_break_callback(void *_ctx) CBOR_DUMMY_CALLBACK

const struct cbor_callbacks cbor_empty_callbacks = {
CBOR_EXPORT const struct cbor_callbacks cbor_empty_callbacks = {
/* Type 0 - Unsigned integers */
.uint8 = cbor_null_uint8_callback,
.uint16 = cbor_null_uint16_callback,
Expand Down
Loading