From 0e879aa34b200b7d583befdbd3ea366a8ff09cc7 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Fri, 31 Jul 2015 08:02:09 +0200 Subject: [PATCH] Added libintl checks & linking for ENABLE_NLS --- .cmake/Modules/FindLibintl.cmake | 62 ++++++++++++++++++++++++++++++++ CMakeLists.txt | 7 +++- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 .cmake/Modules/FindLibintl.cmake diff --git a/.cmake/Modules/FindLibintl.cmake b/.cmake/Modules/FindLibintl.cmake new file mode 100644 index 0000000..dad2634 --- /dev/null +++ b/.cmake/Modules/FindLibintl.cmake @@ -0,0 +1,62 @@ +# Try to find Libintl functionality +# Once done this will define +# +# LIBINTL_FOUND - system has Libintl +# LIBINTL_INCLUDE_DIR - Libintl include directory +# LIBINTL_LIBRARIES - Libraries needed to use Libintl +# +# TODO: This will enable translations only if Gettext functionality is +# present in libc. Must have more robust system for release, where Gettext +# functionality can also reside in standalone Gettext library, or the one +# embedded within kdelibs (cf. gettext.m4 from Gettext source). + +# Copyright (c) 2006, Chusslove Illich, +# Copyright (c) 2007, Alexander Neundorf, +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + + +SET(LIBINTL_SEARCH_PATHS + /usr/local/opt/ + /usr/local/ + /usr/ +) + +if(LIBINTL_INCLUDE_DIR AND LIBINTL_LIB_FOUND) + set(Libintl_FIND_QUIETLY TRUE) +endif(LIBINTL_INCLUDE_DIR AND LIBINTL_LIB_FOUND) + +find_path(LIBINTL_INCLUDE_DIR libintl.h + HINTS + PATH_SUFFIXES gettext/include + PATHS ${LIBINTL_SEARCH_PATHS} +) + +set(LIBINTL_LIB_FOUND FALSE) + +if(LIBINTL_INCLUDE_DIR) + include(CheckFunctionExists) + check_function_exists(dgettext LIBINTL_LIBC_HAS_DGETTEXT) + + if (LIBINTL_LIBC_HAS_DGETTEXT) + set(LIBINTL_LIBRARIES) + set(LIBINTL_LIB_FOUND TRUE) + else (LIBINTL_LIBC_HAS_DGETTEXT) + find_library(LIBINTL_LIBRARIES + NAMES intl + HINTS + PATH_SUFFIXES gettext/lib + PATHS ${LIBINTL_SEARCH_PATHS} + ) + if(LIBINTL_LIBRARIES) + set(LIBINTL_LIB_FOUND TRUE) + endif(LIBINTL_LIBRARIES) + endif (LIBINTL_LIBC_HAS_DGETTEXT) + +endif(LIBINTL_INCLUDE_DIR) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Libintl DEFAULT_MSG LIBINTL_INCLUDE_DIR LIBINTL_LIB_FOUND) + +mark_as_advanced(LIBINTL_INCLUDE_DIR LIBINTL_LIBRARIES LIBINTL_LIBC_HAS_DGETTEXT LIBINTL_LIB_FOUND) diff --git a/CMakeLists.txt b/CMakeLists.txt index b36e3dc..503d13e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,8 @@ endif() # Find dependencies find_package(Gettext) -if (GETTEXT_FOUND) +find_package(Libintl) +if (GETTEXT_FOUND AND Libintl_FOUND) include(GettextTranslate) add_subdirectory(po) set(ENABLE_NLS 1) @@ -110,6 +111,10 @@ if (PCRE_FOUND) target_link_libraries(criterion ${PCRE_LIBRARIES}) endif() +if (LIBINTL_FOUND) + target_link_libraries(criterion ${LIBINTL_LIBRARIES}) +endif() + if (COVERALLS) coveralls_setup("${SOURCE_FILES}" ${COVERALLS_UPLOAD}) endif()