diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bc0bb2..5378a0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,7 @@ set(GettextTranslate_ALL 1) set(GettextTranslate_GMO_BINARY 1) set_property(GLOBAL PROPERTY ALLOW_DUPLICATE_CUSTOM_TARGETS ON) +add_definitions(-DCRITERION_BUILDING_DLL=1) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -g -std=gnu99") diff --git a/include/criterion/abort.h b/include/criterion/abort.h index f20e300..1df05c0 100644 --- a/include/criterion/abort.h +++ b/include/criterion/abort.h @@ -26,6 +26,6 @@ # include "common.h" -NORETURN void criterion_abort_test(void); +CR_API NORETURN void criterion_abort_test(void); #endif /* !CRITERION_ABORT_H_ */ diff --git a/include/criterion/common.h b/include/criterion/common.h index 2a1a630..238a9c2 100644 --- a/include/criterion/common.h +++ b/include/criterion/common.h @@ -111,4 +111,29 @@ # define FORMAT(Archetype, Index, Ftc) # endif +# if defined _WIN32 || defined __CYGWIN__ +# ifdef CRITERION_BUILDING_DLL +# ifdef __GNUC__ +# define CR_API __attribute__ ((dllexport)) +# else +# define CR_API __declspec(dllexport) +# endif +# else +# ifdef __GNUC__ +# define CR_API __attribute__ ((dllimport)) +# else +# define CR_API __declspec(dllimport) +# endif +# endif +# define CR_LOCAL +# else +# if __GNUC__ >= 4 +# define CR_API __attribute__ ((visibility ("default"))) +# define CR_LOCAL __attribute__ ((visibility ("hidden"))) +# else +# define CR_API +# define CR_LOCAL +# endif +# endif + #endif /* !CRITERION_COMMON_H_ */ diff --git a/include/criterion/criterion.h b/include/criterion/criterion.h index e68f841..51c82fd 100644 --- a/include/criterion/criterion.h +++ b/include/criterion/criterion.h @@ -67,6 +67,6 @@ .data = &SUITE_IDENTIFIER_(Name, extra), \ } SECTION_SUFFIX_ -int criterion_run_all_tests(void); +CR_API int criterion_run_all_tests(void); #endif /* !CRITERION_H_ */ diff --git a/include/criterion/event.h b/include/criterion/event.h index 99c85c8..db6cfe3 100644 --- a/include/criterion/event.h +++ b/include/criterion/event.h @@ -26,9 +26,10 @@ # include # include +# include "common.h" extern FILE *g_event_pipe; -void send_event(int kind, void *data, size_t size); +CR_API void send_event(int kind, void *data, size_t size); #endif /* !CRITERION_EVENT_H_ */ diff --git a/include/criterion/logging.h b/include/criterion/logging.h index 667bca9..c5bea18 100644 --- a/include/criterion/logging.h +++ b/include/criterion/logging.h @@ -76,13 +76,13 @@ extern const struct criterion_prefix_data g_criterion_logging_prefixes[]; # define CRITERION_PREFIX_PASS (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_PASS ]) # define CRITERION_PREFIX_FAIL (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_FAIL ]) -void criterion_vlog(enum criterion_logging_level level, const char *msg, va_list args); +CR_API void criterion_vlog(enum criterion_logging_level level, const char *msg, va_list args); FORMAT(printf, 3, 4) -void criterion_plog(enum criterion_logging_level level, const struct criterion_prefix_data *prefix, const char *msg, ...); +CR_API void criterion_plog(enum criterion_logging_level level, const struct criterion_prefix_data *prefix, const char *msg, ...); FORMAT(printf, 2, 3) -void criterion_log(enum criterion_logging_level level, const char *msg, ...); +CR_API void criterion_log(enum criterion_logging_level level, const char *msg, ...); # define criterion_info(...) criterion_log(CRITERION_INFO, __VA_ARGS__) # define criterion_important(...) criterion_log(CRITERION_IMPORTANT, __VA_ARGS__) diff --git a/include/criterion/ordered-set.h b/include/criterion/ordered-set.h index 4b71081..514f601 100644 --- a/include/criterion/ordered-set.h +++ b/include/criterion/ordered-set.h @@ -50,10 +50,10 @@ struct criterion_test_set { size_t tests; }; -struct criterion_ordered_set *new_ordered_set(f_criterion_cmp cmp, +CR_API struct criterion_ordered_set *new_ordered_set(f_criterion_cmp cmp, void (*dtor)(void *, void *)); -void *insert_ordered_set(struct criterion_ordered_set *l, +CR_API void *insert_ordered_set(struct criterion_ordered_set *l, void *ptr, size_t size); diff --git a/include/criterion/theories.h b/include/criterion/theories.h index 3f7cd80..ab98781 100644 --- a/include/criterion/theories.h +++ b/include/criterion/theories.h @@ -29,14 +29,14 @@ struct criterion_theory_context; -struct criterion_theory_context* cr_theory_init(void); -void cr_theory_push_arg(struct criterion_theory_context *ctx, bool is_float, size_t size, void *ptr); -void cr_theory_free(struct criterion_theory_context *ctx); -void cr_theory_abort(void); -int cr_theory_mark(void); +CR_API struct criterion_theory_context* cr_theory_init(void); +CR_API void cr_theory_push_arg(struct criterion_theory_context *ctx, bool is_float, size_t size, void *ptr); +CR_API void cr_theory_free(struct criterion_theory_context *ctx); +CR_API void cr_theory_abort(void); +CR_API int cr_theory_mark(void); -void cr_theory_reset(struct criterion_theory_context *ctx); -void cr_theory_call(struct criterion_theory_context *ctx, void (*fnptr)(void)); +CR_API void cr_theory_reset(struct criterion_theory_context *ctx); +CR_API void cr_theory_call(struct criterion_theory_context *ctx, void (*fnptr)(void)); # define TheoryDataPoints(Category, Name) \ static struct criterion_datapoints IDENTIFIER_(Category, Name, dps)[] @@ -64,7 +64,7 @@ struct criterion_datapoints { cr_theory_abort(); \ } while (0); -void cr_theory_main(struct criterion_datapoints *dps, size_t datapoints, void (*fnptr)(void)); +CR_API void cr_theory_main(struct criterion_datapoints *dps, size_t datapoints, void (*fnptr)(void)); # define CR_VAARG_ID(Suffix, Category, Name, ...) \ IDENTIFIER_(Category, Name, Suffix)