diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt index c7cf555830..e515b5a431 100644 --- a/config/CMakeLists.txt +++ b/config/CMakeLists.txt @@ -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 ( diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3b00076e04..119e38ed96 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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")