Skip to content

Commit 6ac41cd

Browse files
committed
Prefect CMake support.
修改: CMakeLists.txt 修改: ChangeLog 修改: lib/iconv.cpp 修改: tests/tests.cmake
1 parent 9f1d350 commit 6ac41cd

File tree

4 files changed

+36
-34
lines changed

4 files changed

+36
-34
lines changed

CMakeLists.txt

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,48 @@
11
cmake_minimum_required(VERSION 3.12)
22
project(cppp-reiconv VERSION 2.0.0)
33

4+
# Define options
5+
option(ENABLE_EXTRA "Enable extra encodings and features." OFF)
6+
7+
# Set C++ standard
48
set(CMAKE_CXX_STANDARD 11)
59

610
include("${CMAKE_SOURCE_DIR}/build-aux/cmake/cppp.cmake")
711

812
check_have_visibility()
913

10-
set(DLL_VARIABLE "__attribute__((__visibility__(\"default\")))")
11-
14+
# Generate header file for build
15+
if(WIN32)
16+
set(DLL_VARIABLE "__declspec(dllexport)")
17+
elseif(HAVE_VISIBILITY)
18+
set(DLL_VARIABLE "__attribute__((__visibility__(\"default\")))")
19+
else()
20+
set(DLL_VARIABLE "")
21+
endif()
1222
configure_file("${srcdir}/include/cppp/reiconv.hpp.in" "${output_includedir}/cppp/reiconv.hpp")
1323

14-
# Clear DLL_VARIABLE
15-
set(DLL_VARIABLE "")
24+
# Generate header file for install
25+
if(WIN32)
26+
set(DLL_VARIABLE "__declspec(dllimport)")
27+
elseif(HAVE_VISIBILITY)
28+
set(DLL_VARIABLE "__attribute__((__visibility__(\"default\")))")
29+
else()
30+
set(DLL_VARIABLE "")
31+
endif()
1632
configure_file("${srcdir}/include/cppp/reiconv.hpp.in" "${output_includedir}/cppp/reiconv.hpp.inst")
1733

34+
# Add includes
1835
include_directories("${srcdir}/lib")
1936
include_directories("${srcdir}/lib/generated")
2037
include_directories("${output_includedir}")
2138

2239
# Add definitions
23-
add_compile_definitions(ENABLE_EXTRA=1)
40+
if(ENABLE_EXTRA)
41+
add_compile_definitions(ENABLE_EXTRA=1)
42+
endif()
2443

2544
# Add library
26-
add_library(libcppp-reiconv.shared SHARED "${srcdir}/lib/iconv.cpp")
27-
28-
# Set properties
29-
set_target_properties(libcppp-reiconv.shared PROPERTIES
30-
OUTPUT_NAME ${PROJECT_NAME}
31-
LIBRARY_OUTPUT_DIRECTORY "${output_shareddir}"
32-
ARCHIVE_OUTPUT_DIRECTORY "${output_staticddir}"
33-
VERSION ${PROJECT_VERSION} )
45+
cppp_build_library(${PROJECT_NAME} "${srcdir}/lib/iconv.cpp" TRUE TRUE)
3446

47+
# Include test suite.
3548
include("tests/tests.cmake")

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
Remove autoconf buildsystem support.
1111
Add CMake support.
1212
Move generated file into 'lib/generated'.
13+
Move cppp-reiconv to a C++ library.
1314

1415
2023-06-29 Bruno Haible <bruno@clisp.org>
1516

lib/iconv.cpp

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,14 @@
2020
#include <cppp/reiconv.hpp>
2121

2222
#include <limits.h>
23-
#include <stdlib.h>
24-
#include <string.h>
25-
26-
#ifdef __CYGWIN__
27-
#include <cygwin/version.h>
28-
#endif
23+
#include <iostream>
24+
#include <cstdlib>
25+
#include <cstring>
2926

3027
namespace cppp{namespace base{namespace reiconv
3128
{
3229

33-
#ifdef ENABLE_EXTRA
30+
#if ENABLE_EXTRA
3431
/*
3532
* Consider all system dependent encodings, for any system,
3633
* and the extra encodings.
@@ -592,20 +589,6 @@ namespace cppp{namespace base{namespace reiconv
592589
/* version number: (major<<8) + minor */
593590
int reiconv_version = (3 << 8) + 0;
594591

595-
#if defined __FreeBSD__ && !defined __gnu_freebsd__
596-
/* GNU libiconv is the native FreeBSD iconv implementation since 2002.
597-
It wants to define the symbols 'iconv_open', 'iconv', 'iconv_close'. */
598-
#define strong_alias(name, aliasname) _strong_alias(name, aliasname)
599-
#define _strong_alias(name, aliasname) \
600-
extern __typeof (name) aliasname __attribute__ ((alias (#name)));
601-
#undef iconv_open
602-
#undef iconv
603-
#undef iconv_close
604-
strong_alias (libiconv_open, iconv_open)
605-
strong_alias (libiconv, iconv)
606-
strong_alias (libiconv_close, iconv_close)
607-
#endif
608-
609592
#endif
610593

611594
#define tmpbufsize 4096
@@ -620,6 +603,8 @@ namespace cppp{namespace base{namespace reiconv
620603
if (cd == (iconv_t)(-1)) {
621604
if (errno != EINVAL)
622605
return -1;
606+
/* Autodetect feature is a extra feature. */
607+
#if ENABLE_EXTRA
623608
/* Unsupported fromcode or tocode. Check whether the caller requested
624609
autodetection. */
625610
if (!strcmp(fromcode,"autodetect_utf8")) {
@@ -662,6 +647,7 @@ namespace cppp{namespace base{namespace reiconv
662647
ret = iconv_string(tocode,"EUC-KR",start,end,resultp,lengthp);
663648
return ret;
664649
}
650+
#endif
665651
errno = EINVAL;
666652
return -1;
667653
}

tests/tests.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ if (ENABLE_TEST)
176176
WORKING_DIRECTORY "${output_testsdir}"
177177
COMMAND "${output_testsdir}/test-shiftseq" )
178178

179+
if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
179180
# AIX specific encodings
180181
test("stateless" "CP856")
181182
test("stateless" "CP922")
@@ -185,6 +186,7 @@ if (ENABLE_TEST)
185186
test("stateless" "CP1161")
186187
test("stateless" "CP1162")
187188
test("stateless" "CP1163")
189+
endif()
188190

189191
# OSF/1 specific encodings
190192
test("stateless" "DEC-KANJI")

0 commit comments

Comments
 (0)