neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

FindLibintl.cmake (2696B)


      1 include(CheckCSourceCompiles)
      2 include(CheckVariableExists)
      3 
      4 # Append custom gettext path to CMAKE_PREFIX_PATH
      5 # if installed via Mac Homebrew
      6 if (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()
     14 endif()
     15 
     16 find_path(LIBINTL_INCLUDE_DIR
     17    NAMES libintl.h
     18    PATH_SUFFIXES gettext
     19 )
     20 
     21 find_library(LIBINTL_LIBRARY
     22    NAMES intl libintl
     23 )
     24 
     25 if (LIBINTL_INCLUDE_DIR)
     26  list(APPEND CMAKE_REQUIRED_INCLUDES "${LIBINTL_INCLUDE_DIR}")
     27 endif()
     28 # On some systems (linux+glibc) libintl is passively available.
     29 # So only specify the library if one was found.
     30 if (LIBINTL_LIBRARY)
     31  list(APPEND CMAKE_REQUIRED_LIBRARIES "${LIBINTL_LIBRARY}")
     32 endif()
     33 if (MSVC)
     34  list(APPEND CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARY})
     35 endif()
     36 
     37 # On macOS, if libintl is a static library then we also need
     38 # to link libiconv and CoreFoundation.
     39 get_filename_component(LibIntl_EXT "${LIBINTL_LIBRARY}" EXT)
     40 if (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}")
     44 endif()
     45 
     46 check_c_source_compiles("
     47 #include <libintl.h>
     48 
     49 int 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)
     56 if (MSVC)
     57  list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARY})
     58 endif()
     59 if (LibIntl_STATIC)
     60  list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES  "${ICONV_LIBRARY}" "${CoreFoundation_FRAMEWORK}")
     61 endif()
     62 if (LIBINTL_INCLUDE_DIR)
     63  list(REMOVE_ITEM CMAKE_REQUIRED_INCLUDES "${LIBINTL_INCLUDE_DIR}")
     64 endif()
     65 if (LIBINTL_LIBRARY)
     66  list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "${LIBINTL_LIBRARY}")
     67 endif()
     68 
     69 set(REQUIRED_VARIABLES LIBINTL_LIBRARY LIBINTL_INCLUDE_DIR)
     70 if (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)
     76 endif()
     77 
     78 find_package_handle_standard_args(Libintl DEFAULT_MSG
     79  ${REQUIRED_VARIABLES})
     80 mark_as_advanced(LIBINTL_LIBRARY LIBINTL_INCLUDE_DIR)
     81 
     82 add_library(libintl INTERFACE)
     83 target_include_directories(libintl SYSTEM BEFORE INTERFACE ${LIBINTL_INCLUDE_DIR})
     84 if (LIBINTL_LIBRARY)
     85  target_link_libraries(libintl INTERFACE ${LIBINTL_LIBRARY})
     86 endif()