tAdd basic libintl cmake support. - vaccinewars - be a doctor and try to vaccin… | |
git clone git://src.adamsgaard.dk/vaccinewars | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 0d8c00739cb6642496839bad83d7a8f62cccde1d | |
parent 30d09236e1d23542ce98d663057b2ae87c04ee57 | |
Author: Ben Webb <[email protected]> | |
Date: Sun, 21 Jun 2015 17:51:01 -0700 | |
Add basic libintl cmake support. | |
Diffstat: | |
M CMakeLists.txt | 6 ++++++ | |
A cmake_modules/FindLibIntl.cmake | 60 +++++++++++++++++++++++++++++… | |
A cmake_modules/LibFindMacros.cmake | 111 ++++++++++++++++++++++++++++++ | |
3 files changed, 177 insertions(+), 0 deletions(-) | |
--- | |
diff --git a/CMakeLists.txt b/CMakeLists.txt | |
t@@ -56,6 +56,12 @@ else() | |
include_directories(${GLIB_INCLUDE_DIRS}) | |
endif() | |
+find_package(LibIntl) | |
+if (LibIntl_FOUND) | |
+ set(EXTRA_LIBS ${EXTRA_LIBS} ${LibIntl_LIBRARIES}) | |
+ include_directories(${LibIntl_INCLUDE_DIRS}) | |
+endif() | |
+ | |
if (CURSES_CLIENT) | |
find_package(Curses) | |
if (CURSES_FOUND) | |
diff --git a/cmake_modules/FindLibIntl.cmake b/cmake_modules/FindLibIntl.cmake | |
t@@ -0,0 +1,60 @@ | |
+# - 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(CheckVariableExists) | |
+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 | |
+ PATH_SUFFIXES gettext | |
+) | |
+ | |
+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) | |
+ | |
+if (HAVE_WORKING_LIBINTL) | |
+ check_variable_exists(_nl_msg_cat_cntr HAVE_NL_MSG_CAT_CNTR) | |
+endif() | |
+ | |
+set(LibIntl_PROCESS_INCLUDES LibIntl_INCLUDE_DIR) | |
+set(LibIntl_PROCESS_LIBS LibIntl_LIBRARY) | |
+libfind_process(LibIntl) | |
diff --git a/cmake_modules/LibFindMacros.cmake b/cmake_modules/LibFindMacros.cm… | |
t@@ -0,0 +1,111 @@ | |
+# Version 1.0 (2013-04-12) | |
+# Public Domain, originally written by Lasse Kärkkäinen <[email protected]> | |
+# Published at http://www.cmake.org/Wiki/CMake:How_To_Find_Libraries | |
+ | |
+# If you improve the script, please modify the forementioned wiki page because | |
+# I no longer maintain my scripts (hosted as static files at zi.fi). Feel free | |
+# to remove this entire header if you use real version control instead. | |
+ | |
+# Changelog: | |
+# 2013-04-12 Added version number (1.0) and this header, no other changes | |
+# 2009-10-08 Originally published | |
+ | |
+ | |
+# Works the same as find_package, but forwards the "REQUIRED" and "QUIET" argu… | |
+# used for the current package. For this to work, the first parameter must be … | |
+# prefix of the current package, then the prefix of the new package etc, which… | |
+# passed to find_package. | |
+macro (libfind_package PREFIX) | |
+ set (LIBFIND_PACKAGE_ARGS ${ARGN}) | |
+ if (${PREFIX}_FIND_QUIETLY) | |
+ set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET) | |
+ endif (${PREFIX}_FIND_QUIETLY) | |
+ if (${PREFIX}_FIND_REQUIRED) | |
+ set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED) | |
+ endif (${PREFIX}_FIND_REQUIRED) | |
+ find_package(${LIBFIND_PACKAGE_ARGS}) | |
+endmacro (libfind_package) | |
+ | |
+# CMake developers made the UsePkgConfig system deprecated in the same release… | |
+# where they added pkg_check_modules. Consequently I need to support both in m… | |
+# to avoid those deprecated warnings. Here's a helper that does just that. | |
+# Works identically to pkg_check_modules, except that no checks are needed pri… | |
+macro (libfind_pkg_check_modules PREFIX PKGNAME) | |
+ if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) | |
+ include(UsePkgConfig) | |
+ pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFI… | |
+ else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) | |
+ find_package(PkgConfig) | |
+ if (PKG_CONFIG_FOUND) | |
+ pkg_check_modules(${PREFIX} ${PKGNAME}) | |
+ endif (PKG_CONFIG_FOUND) | |
+ endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) | |
+endmacro (libfind_pkg_check_modules) | |
+ | |
+# Do the final processing once the paths have been detected. | |
+# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to cont… | |
+# all the variables, each of which contain one include directory. | |
+# Ditto for ${PREFIX}_PROCESS_LIBS and library files. | |
+# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES. | |
+# Also handles errors in case library detection was required, etc. | |
+macro (libfind_process PREFIX) | |
+ # Skip processing if already processed during this run | |
+ if (NOT ${PREFIX}_FOUND) | |
+ # Start with the assumption that the library was found | |
+ set (${PREFIX}_FOUND TRUE) | |
+ | |
+ # Process all includes and set _FOUND to false if any are missing | |
+ foreach (i ${${PREFIX}_PROCESS_INCLUDES}) | |
+ if (${i}) | |
+ set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}}) | |
+ mark_as_advanced(${i}) | |
+ else (${i}) | |
+ set (${PREFIX}_FOUND FALSE) | |
+ endif (${i}) | |
+ endforeach (i) | |
+ | |
+ # Process all libraries and set _FOUND to false if any are missing | |
+ foreach (i ${${PREFIX}_PROCESS_LIBS}) | |
+ if (${i}) | |
+ set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}}) | |
+ mark_as_advanced(${i}) | |
+ else (${i}) | |
+ set (${PREFIX}_FOUND FALSE) | |
+ endif (${i}) | |
+ endforeach (i) | |
+ | |
+ # Print message and/or exit on fatal error | |
+ if (${PREFIX}_FOUND) | |
+ if (NOT ${PREFIX}_FIND_QUIETLY) | |
+ message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}") | |
+ endif (NOT ${PREFIX}_FIND_QUIETLY) | |
+ else (${PREFIX}_FOUND) | |
+ if (${PREFIX}_FIND_REQUIRED) | |
+ foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS}) | |
+ message("${i}=${${i}}") | |
+ endforeach (i) | |
+ message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall t… | |
+ endif (${PREFIX}_FIND_REQUIRED) | |
+ endif (${PREFIX}_FOUND) | |
+ endif (NOT ${PREFIX}_FOUND) | |
+endmacro (libfind_process) | |
+ | |
+macro(libfind_library PREFIX basename) | |
+ set(TMP "") | |
+ if(MSVC80) | |
+ set(TMP -vc80) | |
+ endif(MSVC80) | |
+ if(MSVC90) | |
+ set(TMP -vc90) | |
+ endif(MSVC90) | |
+ set(${PREFIX}_LIBNAMES ${basename}${TMP}) | |
+ if(${ARGC} GREATER 2) | |
+ set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2}) | |
+ string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES}) | |
+ set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP}) | |
+ endif(${ARGC} GREATER 2) | |
+ find_library(${PREFIX}_LIBRARY | |
+ NAMES ${${PREFIX}_LIBNAMES} | |
+ PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS} | |
+ ) | |
+endmacro(libfind_library) |