Improve libintl detection and linking.

This makes it so that a self-installed libintl is now detected and used.
It also attempts to locate a homebrew version of the library, if that
exists.
This commit is contained in:
John Szakmeister 2014-02-24 22:22:56 -05:00 committed by ashleyh
parent e728ce95ef
commit 95db76e280
2 changed files with 28 additions and 18 deletions

View File

@ -7,14 +7,31 @@ check_type_size("time_t" SIZEOF_TIME_T)
check_type_size("off_t" SIZEOF_OFF_T)
if (CMAKE_HOST_APPLE)
execute_process(COMMAND brew --prefix gettext
OUTPUT_VARIABLE _TMP_HOMEBREW_GETTEXT_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(HOMEBREW_GETTEXT_PREFIX ${_TMP_HOMEBREW_GETTEXT_PREFIX}
CACHE PATH "homebrew gettext directory (${_TMP_HOMEBREW_GETTEXT_PREFIX})")
set(CMAKE_REQUIRED_LIBRARIES intl)
set(CMAKE_REQUIRED_INCLUDES "${HOMEBREW_GETTEXT_PREFIX}/include")
set(CMAKE_REQUIRED_FLAGS "-L${HOMEBREW_GETTEXT_PREFIX}/lib")
find_program(HAVE_HOMEBREW brew)
if (HAVE_HOMEBREW)
execute_process(COMMAND brew --prefix gettext
OUTPUT_VARIABLE _TMP_HOMEBREW_GETTEXT_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(HOMEBREW_GETTEXT_PREFIX ${_TMP_HOMEBREW_GETTEXT_PREFIX}
CACHE
PATH "homebrew gettext directory (${_TMP_HOMEBREW_GETTEXT_PREFIX})")
list(APPEND CMAKE_PREFIX_PATH "${HOMEBREW_GETTEXT_PREFIX}")
endif()
endif()
find_path(LIBINTL_INCLUDE_DIR libintl.h)
find_library(LIBINTL_LIB intl)
get_filename_component(LIBINTL_LIB_DIR "${LIBINTL_LIB}" NAME)
if (LIBINTL_INCLUDE_DIR)
set(CMAKE_REQUIRED_INCLUDES "${LIBINTL_INCLUDE_DIR}")
endif()
# This is required because some operating systems don't have a separate
# libintl--it is built into glibc. So we only need to specify the library if
# one was actually found.
if (LIBINTL_LIB)
set(CMAKE_REQUIRED_LIBRARIES "${LIBINTL_LIB}")
endif()
check_c_source_compiles("
@ -25,7 +42,7 @@ int main(int argc, char** argv) {
bindtextdomain(\"foo\", \"bar\");
bind_textdomain_codeset(\"foo\", \"bar\");
textdomain(\"foo\");
}" HAVE_WORKING_LIBINTL)
}" HAVE_LIBINTL)
# generate configuration header and update include directories
configure_file (

View File

@ -40,15 +40,8 @@ else()
endif()
endif()
if (CMAKE_HOST_APPLE AND HAVE_WORKING_LIBINTL)
check_library_exists(intl gettext "${HOMEBREW_GETTEXT_PREFIX}/lib" HAVE_LIBINTL)
if (HAVE_LIBINTL)
include_directories("${HOMEBREW_GETTEXT_PREFIX}/include")
find_library(INTL_LIBRARY NAMES intl PATHS "${HOMEBREW_GETTEXT_PREFIX}/lib")
target_link_libraries(vim ${INTL_LIBRARY})
else()
message(FATAL_ERROR "can't find something resembling -lintl")
endif()
if (HAVE_LIBINTL AND LIBINTL_LIB)
target_link_libraries(vim ${LIBINTL_LIB})
endif()
include_directories ("${PROJECT_SOURCE_DIR}/src/proto")