robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

dundargocbuild: cmake fixes404fdb0f36

master
2.6 KiB86 linesraw
1include(CheckCSourceCompiles)
2include(CheckVariableExists)
3
4# Append custom gettext path to CMAKE_PREFIX_PATH
5# if installed via Mac Homebrew
6if (APPLE)
7    find_program(HOMEBREW_PRG brew)
8    if (EXISTS ${HOMEBREW_PRG})
9        execute_process(COMMAND ${HOMEBREW_PRG} --prefix gettext
10            OUTPUT_STRIP_TRAILING_WHITESPACE
11            OUTPUT_VARIABLE HOMEBREW_GETTEXT_PREFIX)
12        list(APPEND CMAKE_PREFIX_PATH "${HOMEBREW_GETTEXT_PREFIX}")
13    endif()
14endif()
15
16find_path(LIBINTL_INCLUDE_DIR
17    NAMES libintl.h
18    PATH_SUFFIXES gettext
19)
20
21find_library(LIBINTL_LIBRARY
22    NAMES intl libintl
23)
24
25if (LIBINTL_INCLUDE_DIR)
26  list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBINTL_INCLUDE_DIR}")
27endif()
28# On some systems (linux+glibc) libintl is passively available.
29# So only specify the library if one was found.
30if (LIBINTL_LIBRARY)
31  list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBINTL_LIBRARY}")
32endif()
33if (MSVC)
34  list(APPEND CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARY})
35endif()
36
37# On macOS, if libintl is a static library then we also need
38# to link libiconv and CoreFoundation.
39get_filename_component(LibIntl_EXT "${LIBINTL_LIBRARY}" EXT)
40if (APPLE AND (LibIntl_EXT STREQUAL ".a"))
41  set(LibIntl_STATIC TRUE)
42  find_library(CoreFoundation_FRAMEWORK CoreFoundation)
43  list(APPEND CMAKE_REQUIRED_LIBRARIES "${ICONV_LIBRARY}" "${CoreFoundation_FRAMEWORK}")
44endif()
45
46check_c_source_compiles("
47#include <libintl.h>
48
49int main(int argc, char** argv) {
50  gettext(\"foo\");
51  ngettext(\"foo\", \"bar\", 1);
52  bindtextdomain(\"foo\", \"bar\");
53  bind_textdomain_codeset(\"foo\", \"bar\");
54  textdomain(\"foo\");
55}" HAVE_WORKING_LIBINTL)
56if (MSVC)
57  list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARY})
58endif()
59if (LibIntl_STATIC)
60  list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES  "${ICONV_LIBRARY}" "${CoreFoundation_FRAMEWORK}")
61endif()
62if (LIBINTL_INCLUDE_DIR)
63  list(REMOVE_ITEM CMAKE_REQUIRED_INCLUDES "${LIBINTL_INCLUDE_DIR}")
64endif()
65if (LIBINTL_LIBRARY)
66  list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "${LIBINTL_LIBRARY}")
67endif()
68
69set(REQUIRED_VARIABLES LIBINTL_LIBRARY LIBINTL_INCLUDE_DIR)
70if (HAVE_WORKING_LIBINTL)
71  # On some systems (linux+glibc) libintl is passively available.
72  # If HAVE_WORKING_LIBINTL then we consider the requirement satisfied.
73  unset(REQUIRED_VARIABLES)
74
75  check_variable_exists(_nl_msg_cat_cntr HAVE_NL_MSG_CAT_CNTR)
76endif()
77
78find_package_handle_standard_args(Libintl DEFAULT_MSG
79  ${REQUIRED_VARIABLES})
80mark_as_advanced(LIBINTL_LIBRARY LIBINTL_INCLUDE_DIR)
81
82add_library(libintl INTERFACE)
83target_include_directories(libintl SYSTEM BEFORE INTERFACE ${LIBINTL_INCLUDE_DIR})
84if (LIBINTL_LIBRARY)
85  target_link_libraries(libintl INTERFACE ${LIBINTL_LIBRARY})
86endif()