commit 7e17af6fb29d98f538cab80db0fdbef1bd170929
parent 1b478249f70511cd5061d33e52322c5f6df7025f
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Tue, 11 Jun 2024 00:25:28 +0200
Hide C bindings from C++ interface
Diffstat:
3 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt
@@ -2,7 +2,7 @@ set(GENERATE_OUT "${CMAKE_BINARY_DIR}/bin")
add_executable(demo main.cpp)
target_link_libraries(demo PRIVATE args)
-set_target_properties(demo PROPERTIES LINKER_LANGUAGE CXX)
+set_target_properties(demo PROPERTIES LANGUAGE CXX)
set_target_properties(demo PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
@@ -11,7 +11,7 @@ set_target_properties(demo PROPERTIES
add_executable(cdemo main.c)
target_link_libraries(cdemo PRIVATE cargs)
-set_target_properties(cdemo PROPERTIES LINKER_LANGUAGE C)
+set_target_properties(cdemo PROPERTIES LANGUAGE C)
set_target_properties(cdemo PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
diff --git a/include/args.h b/include/args.h
@@ -2,13 +2,17 @@
#define ARGS_H
#ifdef __cplusplus
+
extern "C" {
namespace args {
struct Parser;
typedef Parser args_parser;
+
#else
+
struct __Parser;
typedef struct __Parser args_parser;
+
#endif
typedef struct {
@@ -20,6 +24,15 @@ typedef struct {
int group;
} args_option_t;
+typedef int (*args_parse_f)(int key, const char *arg, args_parser *parser);
+
+typedef struct {
+ const args_option_t *options;
+ const args_parse_f parse;
+ const char *doc;
+ const char *message;
+} args_argp_t;
+
enum args_option_e {
ARGS_OPTION_ARG_OPTIONAL = 0x1,
ARGS_OPTION_HIDDEN = 0x2,
@@ -35,19 +48,14 @@ enum args_key_e {
ARGS_KEY_ERROR = 0x1000005,
};
-struct args_Parser;
-typedef int (*args_parse_f)(int key, const char *arg, args_parser *parser);
-typedef struct {
- const args_option_t *options;
- const args_parse_f parse;
- const char *doc;
- const char *message;
-} args_argp_t;
+#if !defined __cplusplus || defined WITH_C_BINDINGS
int args_parse(args_argp_t *argp, int argc, char *argv[], void *input);
void *args_parser_input(args_parser *parser);
+#endif
+
#ifdef __cplusplus
} // namespace args
} // extern "C"
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
@@ -13,7 +13,8 @@ install(TARGETS args
PUBLIC_HEADER DESTINATION include
)
- add_library(cargs STATIC c_bindings.cpp args.cpp help.cpp trie.cpp)
+add_library(cargs STATIC c_bindings.cpp args.cpp help.cpp trie.cpp)
+target_compile_definitions(cargs PRIVATE WITH_C_BINDINGS)
target_include_directories(cargs PUBLIC ../include)
set_target_properties(cargs PROPERTIES LINKER_LANGUAGE CXX)