summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwangqr <wangqr@wangqr.tk>2020-04-22 18:54:07 +0000
committerJehan Pagès <jehan@zemarmot.net>2020-04-22 18:54:07 +0000
commitae7acbd0f234a073e79425f32cb6e792ab15fd68 (patch)
treea2bac8fe0cf1477e9eec4b429d13b85a139fd5e2
parent2694ba6363d4b8555d8c57eb4e85b081f754f6d3 (diff)
Add dllexport to interface functions
This allows building the DLL on Windows with other compilers than GNU ones. See MR !4.
-rw-r--r--src/CMakeLists.txt5
-rw-r--r--src/uchardet.h23
2 files changed, 22 insertions, 6 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 952b594..61e315f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -79,6 +79,10 @@ add_library(
${UCHARDET_LIBRARY}
${UCHARDET_SOURCES}
)
+target_compile_definitions("${UCHARDET_LIBRARY}" PRIVATE BUILDING_UCHARDET)
+if(BUILD_SHARED_LIBS)
+ target_compile_definitions("${UCHARDET_LIBRARY}" PUBLIC UCHARDET_SHARED)
+endif()
if (UCHARDET_STATIC_LIBRARY)
add_library(
@@ -86,6 +90,7 @@ if (UCHARDET_STATIC_LIBRARY)
STATIC
${UCHARDET_SOURCES}
)
+ target_compile_definitions("${UCHARDET_STATIC_LIBRARY}" PRIVATE BUILDING_UCHARDET)
endif (UCHARDET_STATIC_LIBRARY)
set_target_properties(
diff --git a/src/uchardet.h b/src/uchardet.h
index 0d67d18..271d98d 100644
--- a/src/uchardet.h
+++ b/src/uchardet.h
@@ -44,6 +44,17 @@ extern "C" {
#include <stddef.h>
+#if defined(UCHARDET_SHARED) && (defined(_WIN32) || defined(__CYGWIN__))
+#ifdef BUILDING_UCHARDET
+#define UCHARDET_INTERFACE __declspec(dllexport)
+#else
+#define UCHARDET_INTERFACE __declspec(dllimport)
+#endif
+#else
+#define UCHARDET_INTERFACE
+#endif
+
+
/**
* A handle for a uchardet encoding detector.
*/
@@ -53,13 +64,13 @@ typedef struct uchardet * uchardet_t;
* Create an encoding detector.
* @return an instance of uchardet_t.
*/
-uchardet_t uchardet_new(void);
+UCHARDET_INTERFACE uchardet_t uchardet_new(void);
/**
* Delete an encoding detector.
* @param ud [in] the uchardet_t handle to delete.
*/
-void uchardet_delete(uchardet_t ud);
+UCHARDET_INTERFACE void uchardet_delete(uchardet_t ud);
/**
* Feed data to an encoding detector.
@@ -72,26 +83,26 @@ void uchardet_delete(uchardet_t ud);
* @param len [in] number of byte of data
* @return non-zero number on failure.
*/
-int uchardet_handle_data(uchardet_t ud, const char * data, size_t len);
+UCHARDET_INTERFACE int uchardet_handle_data(uchardet_t ud, const char * data, size_t len);
/**
* Notify an end of data to an encoding detector.
* @param ud [in] handle of an instance of uchardet
*/
-void uchardet_data_end(uchardet_t ud);
+UCHARDET_INTERFACE void uchardet_data_end(uchardet_t ud);
/**
* Reset an encoding detector.
* @param ud [in] handle of an instance of uchardet
*/
-void uchardet_reset(uchardet_t ud);
+UCHARDET_INTERFACE void uchardet_reset(uchardet_t ud);
/**
* Get an iconv-compatible name of the encoding that was detected.
* @param ud [in] handle of an instance of uchardet
* @return name of charset on success and "" on failure.
*/
-const char * uchardet_get_charset(uchardet_t ud);
+UCHARDET_INTERFACE const char * uchardet_get_charset(uchardet_t ud);
#ifdef __cplusplus
}