diff options
author | Alexis Hildebrandt <afh@surryhill.net> | 2014-02-26 13:55:43 +0100 |
---|---|---|
committer | ashleyh <gh@ashleyh.eu> | 2014-02-27 19:11:48 +0000 |
commit | 05b9e11584c30c03cb911bf909374c86450ee13e (patch) | |
tree | b6ed38e24df01346535aeeac552ce14b6db6eec9 | |
parent | fba074d99440f58d534d18ff8adbd6ca8c7be675 (diff) | |
download | rneovim-05b9e11584c30c03cb911bf909374c86450ee13e.tar.gz rneovim-05b9e11584c30c03cb911bf909374c86450ee13e.tar.bz2 rneovim-05b9e11584c30c03cb911bf909374c86450ee13e.zip |
CMakeLists: Improve handling of libintl
by refactoring it into a separate CMake module
-rw-r--r-- | CMakeLists.txt | 3 | ||||
-rw-r--r-- | cmake/FindLibIntl.cmake | 54 | ||||
-rw-r--r-- | config/CMakeLists.txt | 39 | ||||
-rw-r--r-- | src/CMakeLists.txt | 8 |
4 files changed, 61 insertions, 43 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 32a56f2730..b732a5b07c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,9 @@ endif(NOT CMAKE_USE_PTHREADS_INIT) # the static libuv doesn't but uses clock_gettime. check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME) +find_package(LibIntl) +include_directories(${LibIntl_INCLUDE_DIR}) + # Require libuv find_package(LibUV REQUIRED) include_directories(${LibUV_INCLUDE_DIRS}) diff --git a/cmake/FindLibIntl.cmake b/cmake/FindLibIntl.cmake new file mode 100644 index 0000000000..ef7e3c10fd --- /dev/null +++ b/cmake/FindLibIntl.cmake @@ -0,0 +1,54 @@ +# - Try to find libintl +# Once done, this will define +# +# LibIntl_FOUND - system has libintl +# LibIntl_INCLUDE_DIRS - the libintl include directories +# LibIntl_LIBRARIES - link these to use libintl + +include(CheckCSourceCompiles) +include(LibFindMacros) + +# Append custom gettext path to CMAKE_PREFIX_PATH +# if installed via Mac Hombrew +if (CMAKE_HOST_APPLE) + find_program(HOMEBREW_PROG brew) + if (EXISTS ${HOMEBREW_PROG}) + execute_process(COMMAND ${HOMEBREW_PROG} --prefix gettext + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE HOMEBREW_GETTEXT_PREFIX) + list(APPEND CMAKE_PREFIX_PATH "${HOMEBREW_GETTEXT_PREFIX}") + endif() +endif() + +find_path(LibIntl_INCLUDE_DIR + NAMES libintl.h +) + +find_library(LibIntl_LIBRARY + NAMES intl libintl.a +) + +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_LIBRARY) + set(CMAKE_REQUIRED_LIBRARIES "${LibIntl_LIBRARY}") +endif() + +check_c_source_compiles(" +#include <libintl.h> + +int main(int argc, char** argv) { + gettext(\"foo\"); + bindtextdomain(\"foo\", \"bar\"); + bind_textdomain_codeset(\"foo\", \"bar\"); + textdomain(\"foo\"); +}" HAVE_WORKING_LIBINTL) + +set(LibIntl_PROCESS_INCLUDES LibIntl_INCLUDE_DIR) +set(LibIntl_PROCESS_LIBS LibIntl_LIBRARY) +libfind_process(LibIntl) diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt index e515b5a431..71103738d7 100644 --- a/config/CMakeLists.txt +++ b/config/CMakeLists.txt @@ -1,49 +1,10 @@ include(CheckTypeSize) -include(CheckCSourceCompiles) check_type_size("int" SIZEOF_INT) check_type_size("long" SIZEOF_LONG) check_type_size("time_t" SIZEOF_TIME_T) check_type_size("off_t" SIZEOF_OFF_T) -if (CMAKE_HOST_APPLE) - 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(" -#include <libintl.h> - -int main(int argc, char** argv) { - gettext(\"foo\"); - bindtextdomain(\"foo\", \"bar\"); - bind_textdomain_codeset(\"foo\", \"bar\"); - textdomain(\"foo\"); -}" HAVE_LIBINTL) - # generate configuration header and update include directories configure_file ( "${PROJECT_SOURCE_DIR}/config/config.h.in" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 713114bbab..8c19098f1e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,6 +23,10 @@ if(HAVE_CLOCK_GETTIME) list(APPEND NVIM_LINK_LIBRARIES rt) endif(HAVE_CLOCK_GETTIME) +if (LibIntl_FOUND) + list(APPEND NVIM_LINK_LIBRARIES ${LibIntl_LIBRARY}) +endif() + target_link_libraries (nvim ${NVIM_LINK_LIBRARIES}) include(CheckLibraryExists) @@ -40,10 +44,6 @@ else() endif() endif() -if (HAVE_LIBINTL AND LIBINTL_LIB) - target_link_libraries(nvim ${LIBINTL_LIB}) -endif() - include_directories ("${PROJECT_SOURCE_DIR}/src/proto") install(TARGETS nvim RUNTIME DESTINATION bin) |