Skip to content

Commit

Permalink
add C++ linkage fixes + allow disabling tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fruityloops1 committed Dec 10, 2023
1 parent d49d55b commit a790a48
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
32 changes: 17 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@ target_compile_definitions(base122 PUBLIC BASE122_STATIC)
target_compile_definitions(base122 PRIVATE BASE122_COMPILING)
target_compile_definitions(base122_shared PRIVATE BASE122_COMPILING)

add_executable (test-libbase122 test/test.c test/assertions.c)
target_link_libraries(test-libbase122 base122)
# Use C99 in test-libbase122.
set_property(TARGET test-libbase122 PROPERTY C_STANDARD 99)
if (ENABLE_FUZZER)
message ("Enabling fuzzer targets")
add_executable (fuzz-libbase122 test/fuzz.c test/assertions.c)
target_compile_options(fuzz-libbase122 PRIVATE -fsanitize=fuzzer)
target_link_options(fuzz-libbase122 PRIVATE -fsanitize=fuzzer)
target_link_libraries(fuzz-libbase122 base122)
set_property(TARGET fuzz-libbase122 PROPERTY C_STANDARD 99)
if (ENABLE_BASE122_TEST)
add_executable (test-libbase122 test/test.c test/assertions.c)
target_link_libraries(test-libbase122 base122)
# Use C99 in test-libbase122.
set_property(TARGET test-libbase122 PROPERTY C_STANDARD 99)
if (ENABLE_FUZZER)
message ("Enabling fuzzer targets")
add_executable (fuzz-libbase122 test/fuzz.c test/assertions.c)
target_compile_options(fuzz-libbase122 PRIVATE -fsanitize=fuzzer)
target_link_options(fuzz-libbase122 PRIVATE -fsanitize=fuzzer)
target_link_libraries(fuzz-libbase122 base122)
set_property(TARGET fuzz-libbase122 PROPERTY C_STANDARD 99)
endif()
target_include_directories(test-libbase122 PRIVATE ${CMAKE_SOURCE_DIR})

enable_testing()
add_test (NAME test-libbase122 COMMAND test-libbase122)
endif()
target_include_directories(test-libbase122 PRIVATE ${CMAKE_SOURCE_DIR})

enable_testing()
add_test (NAME test-libbase122 COMMAND test-libbase122)

add_executable (b122 src/b122.c)
target_link_libraries(b122 base122)
Expand Down
9 changes: 9 additions & 0 deletions src/base122.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef LIBBASE122_H
#define LIBBASE122_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stddef.h> /* for size_t */

typedef struct {
Expand Down Expand Up @@ -34,4 +38,9 @@ int BASE122_EXPORT base122_encode(const unsigned char *in, size_t in_len, unsign
int BASE122_EXPORT base122_decode(const unsigned char *in, size_t in_len, unsigned char *out,
size_t out_len, size_t *out_written, base122_error_t *error);


#ifdef __cplusplus
}
#endif

#endif /* LIBBASE122_H */
9 changes: 9 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef LIBBASE_122_UTIL_H
#define LIBBASE_122_UTIL_H

#ifdef __cplusplus
extern "C" {
#endif

#include <assert.h>
#include <stddef.h> /* for size_t */

Expand Down Expand Up @@ -142,4 +146,9 @@ static int bitwriter_write(bitwriter_t *writer, size_t nbits, unsigned char in)
return 0;
}


#ifdef __cplusplus
}
#endif

#endif /* LIBBASE_122_UTIL_H */

0 comments on commit a790a48

Please sign in to comment.