cmake: standardize iconv options

This commit is contained in:
Edward Thomson
2024-12-29 23:28:12 +00:00
parent 78a8c44cc1
commit 9ea1f6d4ed
14 changed files with 91 additions and 58 deletions

View File

@@ -40,6 +40,11 @@ option(USE_GSSAPI "Enable SPNEGO authentication using GSSAPI" OFF)
set(USE_REGEX "" CACHE STRING "Selects regex provider. One of regcomp_l, pcre2, pcre, regcomp, or builtin.")
set(USE_COMPRESSION "" CACHE STRING "Selects compression backend. Either builtin or zlib.")
if(APPLE)
# Currently only available on macOS for `precomposeUnicode` support
set(USE_I18N "" CACHE STRING "Enables internationalization support.")
endif()
# Debugging options
option(USE_LEAK_CHECKER "Run tests with leak checker" OFF)
option(USE_STANDALONE_FUZZERS "Enable standalone fuzzers (compatible with gcc)" OFF)
@@ -73,10 +78,6 @@ if(UNIX)
option(ENABLE_REPRODUCIBLE_BUILDS "Enable reproducible builds" OFF)
endif()
if(APPLE)
option(USE_ICONV "Link with and use iconv library" ON)
endif()
if(MSVC)
# This option must match the settings used in your program, in particular if you
# are linking statically

40
cmake/SelectI18n.cmake Normal file
View File

@@ -0,0 +1,40 @@
include(SanitizeBool)
find_package(IntlIconv)
if(USE_I18N STREQUAL "" AND NOT USE_ICONV STREQUAL "")
sanitizebool(USE_ICONV)
set(USE_I18N "${USE_ICONV}")
endif()
if(USE_I18N STREQUAL "")
set(USE_I18N ON)
endif()
sanitizebool(USE_I18N)
if(USE_I18N)
if(USE_I18N STREQUAL ON)
if(ICONV_FOUND)
set(USE_I18N "iconv")
else()
message(FATAL_ERROR "Unable to detect internationalization support")
endif()
endif()
if(USE_I18N STREQUAL "iconv")
else()
message(FATAL_ERROR "unknown internationalization backend: ${USE_I18N}")
endif()
list(APPEND LIBGIT2_SYSTEM_INCLUDES ${ICONV_INCLUDE_DIR})
list(APPEND LIBGIT2_SYSTEM_LIBS ${ICONV_LIBRARIES})
list(APPEND LIBGIT2_PC_LIBS ${ICONV_LIBRARIES})
set(GIT_I18N 1)
set(GIT_I18N_ICONV 1)
add_feature_info(i18n ON "using ${USE_I18N}")
else()
set(GIT_I18N 0)
add_feature_info(i18n NO "internationalization support is disabled")
endif()

View File

@@ -44,6 +44,7 @@ include(SelectRegex)
include(SelectXdiff)
include(SelectSSH)
include(SelectCompression)
include(SelectI18n)
#
# Platform support
@@ -180,21 +181,6 @@ if(USE_NTLMCLIENT)
endif()
add_feature_info(ntlmclient GIT_NTLM "NTLM authentication support for Unix")
#
# Optional external dependencies
# iconv
if(USE_ICONV)
find_package(IntlIconv)
endif()
if(ICONV_FOUND)
set(GIT_USE_ICONV 1)
list(APPEND LIBGIT2_SYSTEM_INCLUDES ${ICONV_INCLUDE_DIR})
list(APPEND LIBGIT2_SYSTEM_LIBS ${ICONV_LIBRARIES})
list(APPEND LIBGIT2_PC_LIBS ${ICONV_LIBRARIES})
endif()
add_feature_info(iconv GIT_USE_ICONV "iconv encoding conversion support")
#
# Include child projects
#

View File

@@ -95,7 +95,7 @@ int git_libgit2_features(void)
#endif
| GIT_FEATURE_HTTP_PARSER
| GIT_FEATURE_REGEX
#ifdef GIT_USE_ICONV
#ifdef GIT_I18N_ICONV
| GIT_FEATURE_I18N
#endif
#if defined(GIT_NTLM) || defined(GIT_WIN32)
@@ -192,8 +192,10 @@ const char *git_libgit2_feature_backend(git_feature_t feature)
break;
case GIT_FEATURE_I18N:
#if defined(GIT_USE_ICONV)
#if defined(GIT_I18N_ICONV)
return "iconv";
#elif defined(GIT_I18N)
GIT_ASSERT_WITH_RETVAL(!"Unknown internationalization backend", NULL);
#endif
break;

View File

@@ -917,7 +917,7 @@ int git_reference__normalize_name(
bool allow_caret_prefix = true;
bool validate = (flags & GIT_REFERENCE_FORMAT__VALIDATION_DISABLE) == 0;
#ifdef GIT_USE_ICONV
#ifdef GIT_I18N_ICONV
git_fs_path_iconv_t ic = GIT_PATH_ICONV_INIT;
#endif
@@ -932,7 +932,7 @@ int git_reference__normalize_name(
if (normalize)
git_str_clear(buf);
#ifdef GIT_USE_ICONV
#ifdef GIT_I18N_ICONV
if ((flags & GIT_REFERENCE_FORMAT__PRECOMPOSE_UNICODE) != 0) {
size_t namelen = strlen(current);
if ((error = git_fs_path_iconv_init_precompose(&ic)) < 0 ||
@@ -1032,7 +1032,7 @@ cleanup:
if (error && normalize)
git_str_dispose(buf);
#ifdef GIT_USE_ICONV
#ifdef GIT_I18N_ICONV
git_fs_path_iconv_clear(&ic);
#endif

View File

@@ -2297,7 +2297,7 @@ static int repo_init_fs_configs(
git_error_clear();
}
#ifdef GIT_USE_ICONV
#ifdef GIT_I18N_ICONV
if ((error = git_config_set_bool(
cfg, "core.precomposeunicode",
git_fs_path_does_decompose_unicode(work_dir))) < 0)

View File

@@ -984,7 +984,7 @@ bool git_fs_path_has_non_ascii(const char *path, size_t pathlen)
return false;
}
#ifdef GIT_USE_ICONV
#ifdef GIT_I18N_ICONV
int git_fs_path_iconv_init_precompose(git_fs_path_iconv_t *ic)
{
@@ -1136,7 +1136,7 @@ int git_fs_path_direach(
DIR *dir;
struct dirent *de;
#ifdef GIT_USE_ICONV
#ifdef GIT_I18N_ICONV
git_fs_path_iconv_t ic = GIT_PATH_ICONV_INIT;
#endif
@@ -1155,7 +1155,7 @@ int git_fs_path_direach(
return -1;
}
#ifdef GIT_USE_ICONV
#ifdef GIT_I18N_ICONV
if ((flags & GIT_FS_PATH_DIR_PRECOMPOSE_UNICODE) != 0)
(void)git_fs_path_iconv_init_precompose(&ic);
#endif
@@ -1167,7 +1167,7 @@ int git_fs_path_direach(
if (git_fs_path_is_dot_or_dotdot(de_path))
continue;
#ifdef GIT_USE_ICONV
#ifdef GIT_I18N_ICONV
if ((error = git_fs_path_iconv(&ic, &de_path, &de_len)) < 0)
break;
#endif
@@ -1191,7 +1191,7 @@ int git_fs_path_direach(
closedir(dir);
#ifdef GIT_USE_ICONV
#ifdef GIT_I18N_ICONV
git_fs_path_iconv_clear(&ic);
#endif
@@ -1395,7 +1395,7 @@ int git_fs_path_diriter_init(
return -1;
}
#ifdef GIT_USE_ICONV
#ifdef GIT_I18N_ICONV
if ((flags & GIT_FS_PATH_DIR_PRECOMPOSE_UNICODE) != 0)
(void)git_fs_path_iconv_init_precompose(&diriter->ic);
#endif
@@ -1432,7 +1432,7 @@ int git_fs_path_diriter_next(git_fs_path_diriter *diriter)
filename = de->d_name;
filename_len = strlen(filename);
#ifdef GIT_USE_ICONV
#ifdef GIT_I18N_ICONV
if ((diriter->flags & GIT_FS_PATH_DIR_PRECOMPOSE_UNICODE) != 0 &&
(error = git_fs_path_iconv(&diriter->ic, &filename, &filename_len)) < 0)
return error;
@@ -1499,7 +1499,7 @@ void git_fs_path_diriter_free(git_fs_path_diriter *diriter)
diriter->dir = NULL;
}
#ifdef GIT_USE_ICONV
#ifdef GIT_I18N_ICONV
git_fs_path_iconv_clear(&diriter->ic);
#endif

View File

@@ -449,7 +449,7 @@ extern bool git_fs_path_has_non_ascii(const char *path, size_t pathlen);
#define GIT_PATH_NATIVE_ENCODING "UTF-8"
#endif
#ifdef GIT_USE_ICONV
#ifdef GIT_I18N_ICONV
#include <iconv.h>
@@ -473,7 +473,7 @@ extern void git_fs_path_iconv_clear(git_fs_path_iconv_t *ic);
*/
extern int git_fs_path_iconv(git_fs_path_iconv_t *ic, const char **in, size_t *inlen);
#endif /* GIT_USE_ICONV */
#endif /* GIT_I18N_ICONV */
extern bool git_fs_path_does_decompose_unicode(const char *root);
@@ -511,7 +511,7 @@ struct git_fs_path_diriter
DIR *dir;
#ifdef GIT_USE_ICONV
#ifdef GIT_I18N_ICONV
git_fs_path_iconv_t ic;
#endif
};

View File

@@ -11,23 +11,25 @@
#cmakedefine GIT_ARCH_64 1
#cmakedefine GIT_ARCH_32 1
#cmakedefine GIT_USE_ICONV 1
#cmakedefine GIT_I18N 1
#cmakedefine GIT_I18N_ICONV 1
#cmakedefine GIT_USE_NSEC 1
#cmakedefine GIT_USE_STAT_MTIM 1
#cmakedefine GIT_USE_STAT_MTIMESPEC 1
#cmakedefine GIT_USE_STAT_MTIME_NSEC 1
#cmakedefine GIT_USE_FUTIMENS 1
#cmakedefine GIT_REGEX_REGCOMP_L
#cmakedefine GIT_REGEX_REGCOMP
#cmakedefine GIT_REGEX_PCRE
#cmakedefine GIT_REGEX_PCRE2
#cmakedefine GIT_REGEX_REGCOMP_L 1
#cmakedefine GIT_REGEX_REGCOMP 1
#cmakedefine GIT_REGEX_PCRE 1
#cmakedefine GIT_REGEX_PCRE2 1
#cmakedefine GIT_REGEX_BUILTIN 1
#cmakedefine GIT_QSORT_BSD
#cmakedefine GIT_QSORT_GNU
#cmakedefine GIT_QSORT_C11
#cmakedefine GIT_QSORT_MSC
#cmakedefine GIT_QSORT_BSD 1
#cmakedefine GIT_QSORT_GNU 1
#cmakedefine GIT_QSORT_C11 1
#cmakedefine GIT_QSORT_MSC 1
#cmakedefine GIT_SSH 1
#cmakedefine GIT_SSH_EXEC 1

View File

@@ -29,7 +29,7 @@ void test_core_features__basic(void)
cl_assert((caps & GIT_FEATURE_HTTP_PARSER) != 0);
cl_assert((caps & GIT_FEATURE_REGEX) != 0);
#if defined(GIT_USE_ICONV)
#if defined(GIT_I18N_ICONV)
cl_assert((caps & GIT_FEATURE_I18N) != 0);
#endif
@@ -156,8 +156,10 @@ void test_core_features__backends(void)
cl_assert(0);
#endif
#if defined(GIT_USE_ICONV)
#if defined(GIT_I18N_ICONV)
cl_assert_equal_s("iconv", i18n);
#elif defined(GIT_I18N)
cl_assert(0);
#else
cl_assert(i18n == NULL);
#endif

View File

@@ -36,7 +36,7 @@ void test_refs_unicode__create_and_lookup(void)
cl_assert_equal_s(REFNAME, git_reference_name(ref2));
git_reference_free(ref2);
#if GIT_USE_ICONV
#if GIT_I18N_ICONV
/* Lookup reference by decomposed unicode name */
#define REFNAME_DECOMPOSED "refs/heads/" "A" "\314\212" "ngstro" "\314\210" "m"

View File

@@ -328,7 +328,7 @@ void test_repo_init__symlinks_posix_detected(void)
void test_repo_init__detect_precompose_unicode_required(void)
{
#ifdef GIT_USE_ICONV
#ifdef GIT_I18N_ICONV
char *composed = "ḱṷṓn", *decomposed = "ḱṷṓn";
struct stat st;
bool found_with_nfd;

View File

@@ -584,7 +584,7 @@ void test_status_renames__zero_byte_file_does_not_fail(void)
git_status_list_free(statuslist);
}
#ifdef GIT_USE_ICONV
#ifdef GIT_I18N_ICONV
static char *nfc = "\xC3\x85\x73\x74\x72\xC3\xB6\x6D";
static char *nfd = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D";
#endif
@@ -597,7 +597,7 @@ static char *nfd = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D";
*/
void test_status_renames__precomposed_unicode_rename(void)
{
#ifdef GIT_USE_ICONV
#ifdef GIT_I18N_ICONV
git_status_list *statuslist;
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
struct status_entry expected0[] = {
@@ -649,7 +649,7 @@ void test_status_renames__precomposed_unicode_rename(void)
void test_status_renames__precomposed_unicode_toggle_is_rename(void)
{
#ifdef GIT_USE_ICONV
#ifdef GIT_I18N_ICONV
git_status_list *statuslist;
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
struct status_entry expected0[] = {

View File

@@ -1,7 +1,7 @@
#include "clar_libgit2.h"
#include "fs_path.h"
#ifdef GIT_USE_ICONV
#ifdef GIT_I18N_ICONV
static git_fs_path_iconv_t ic;
static char *nfc = "\xC3\x85\x73\x74\x72\xC3\xB6\x6D";
static char *nfd = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D";
@@ -9,21 +9,21 @@ static char *nfd = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D";
void test_iconv__initialize(void)
{
#ifdef GIT_USE_ICONV
#ifdef GIT_I18N_ICONV
cl_git_pass(git_fs_path_iconv_init_precompose(&ic));
#endif
}
void test_iconv__cleanup(void)
{
#ifdef GIT_USE_ICONV
#ifdef GIT_I18N_ICONV
git_fs_path_iconv_clear(&ic);
#endif
}
void test_iconv__unchanged(void)
{
#ifdef GIT_USE_ICONV
#ifdef GIT_I18N_ICONV
const char *data = "Ascii data", *original = data;
size_t datalen = strlen(data);
@@ -37,7 +37,7 @@ void test_iconv__unchanged(void)
void test_iconv__decomposed_to_precomposed(void)
{
#ifdef GIT_USE_ICONV
#ifdef GIT_I18N_ICONV
const char *data = nfd;
size_t datalen, nfdlen = strlen(nfd);
@@ -63,7 +63,7 @@ void test_iconv__decomposed_to_precomposed(void)
void test_iconv__precomposed_is_unmodified(void)
{
#ifdef GIT_USE_ICONV
#ifdef GIT_I18N_ICONV
const char *data = nfc;
size_t datalen = strlen(nfc);