Add dllexport to interface functions

This allows building the DLL on Windows with other compilers than GNU ones.
See MR !4.
This commit is contained in:
wangqr 2020-04-22 18:54:07 +00:00 committed by Jehan Pagès
parent 2694ba6363
commit ae7acbd0f2
2 changed files with 22 additions and 6 deletions

View File

@ -79,6 +79,10 @@ add_library(
${UCHARDET_LIBRARY} ${UCHARDET_LIBRARY}
${UCHARDET_SOURCES} ${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) if (UCHARDET_STATIC_LIBRARY)
add_library( add_library(
@ -86,6 +90,7 @@ if (UCHARDET_STATIC_LIBRARY)
STATIC STATIC
${UCHARDET_SOURCES} ${UCHARDET_SOURCES}
) )
target_compile_definitions("${UCHARDET_STATIC_LIBRARY}" PRIVATE BUILDING_UCHARDET)
endif (UCHARDET_STATIC_LIBRARY) endif (UCHARDET_STATIC_LIBRARY)
set_target_properties( set_target_properties(

View File

@ -44,6 +44,17 @@ extern "C" {
#include <stddef.h> #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. * A handle for a uchardet encoding detector.
*/ */
@ -53,13 +64,13 @@ typedef struct uchardet * uchardet_t;
* Create an encoding detector. * Create an encoding detector.
* @return an instance of uchardet_t. * @return an instance of uchardet_t.
*/ */
uchardet_t uchardet_new(void); UCHARDET_INTERFACE uchardet_t uchardet_new(void);
/** /**
* Delete an encoding detector. * Delete an encoding detector.
* @param ud [in] the uchardet_t handle to delete. * @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. * Feed data to an encoding detector.
@ -72,26 +83,26 @@ void uchardet_delete(uchardet_t ud);
* @param len [in] number of byte of data * @param len [in] number of byte of data
* @return non-zero number on failure. * @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. * Notify an end of data to an encoding detector.
* @param ud [in] handle of an instance of uchardet * @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. * Reset an encoding detector.
* @param ud [in] handle of an instance of uchardet * @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. * Get an iconv-compatible name of the encoding that was detected.
* @param ud [in] handle of an instance of uchardet * @param ud [in] handle of an instance of uchardet
* @return name of charset on success and "" on failure. * @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 #ifdef __cplusplus
} }