Detect iconv type at compile time instead of project generation

This commit is contained in:
wangqr 2020-03-20 06:30:08 -04:00
parent 88c486aca4
commit ef99ce14fd
3 changed files with 7 additions and 25 deletions

View file

@ -520,12 +520,8 @@ target_include_directories(Aegisub PRIVATE ${OPENGL_INCLUDE_DIR})
target_link_libraries(Aegisub ${OPENGL_LIBRARIES})
find_package(Iconv REQUIRED)
target_compile_definitions(libaegisub PRIVATE "HAVE_ICONV")
target_include_directories(libaegisub PRIVATE ${Iconv_INCLUDE_DIRS})
target_link_libraries(libaegisub ${Iconv_LIBRARIES})
if(NOT Iconv_IS_BUILT_IN)
target_compile_definitions(libaegisub PRIVATE "AGI_ICONV_CONST")
endif()
find_package(ICU REQUIRED uc dt in)
target_include_directories(libaegisub PRIVATE ${ICU_INCLUDE_DIRS})

View file

@ -272,20 +272,6 @@ AC_SUBST(ICONV_CFLAGS)
AS_IF([test x$agi_cv_with_iconv = xno], [AC_MSG_FAILURE([Please install a working iconv library.])])
AC_AGI_COMPILE([iconv (const)], [iconv_const], [$ICONV_CFLAGS], [$ICONV_LIBS],[
#include <iconv.h>
int main(void) {
iconv_t cd = iconv_open("UTF-16", "UTF-8");
const char *in = "in";
char *out = new char();
size_t res, inbytesleft, outbytesleft;
res = iconv(cd, &in, &inbytesleft, &out, &outbytesleft);
return 0;
} ])
AS_IF([test x$agi_cv_with_iconv_const = xyes],
[AC_DEFINE(AGI_ICONV_CONST, 1, [Enable if iconv expects the in argument to be const])])
###############
# Audio Players
###############

View file

@ -33,12 +33,6 @@
#define ICONV_POSIX
#endif
#ifdef AGI_ICONV_CONST
#define ICONV_CONST_CAST(a) a
#else
#define ICONV_CONST_CAST(a) const_cast<char **>(a)
#endif
static const iconv_t iconv_invalid = (iconv_t)-1;
static const size_t iconv_failed = (size_t)-1;
@ -286,7 +280,13 @@ Iconv::~Iconv() {
}
size_t Iconv::operator()(const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) {
return iconv(cd, ICONV_CONST_CAST(inbuf), inbytesleft, outbuf, outbytesleft);
struct InbufConstCast{
const char** p;
InbufConstCast(const char** p) : p(p) {}
operator const char** () const { return p; }
operator char** () const { return const_cast<char**>(p); }
} inbuf_const_cast(inbuf);
return iconv(cd, inbuf_const_cast, inbytesleft, outbuf, outbytesleft);
}
IconvWrapper::IconvWrapper(const char* sourceEncoding, const char* destEncoding, bool enableSubst)