diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..ae7372d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,110 @@ +project(sdcv) + +# Older versions have a different signature for CMAKE_MINIMUM_REQUIRED, +# check it manually just to make sure +if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} LESS 2.8) + message(FATAL_ERROR "${PROJECT_NAME} requires at least CMake v2.8." + " You are running v${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}." + " Please upgrade." ) +endif(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} LESS 2.8) + +# If we get this far, use the modern signature. This will also cause newer +# CMake versions to try to be backwards-compatible with the desired version +cmake_minimum_required(VERSION 2.8 FATAL_ERROR) +cmake_policy(VERSION 2.8) + +set(ZLIB_FIND_REQUIRED True) +include(FindZLIB) + +set(GLIB2_REQ "'glib-2.0 >= 2.6.1'") +set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") +include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindGLIB2.cmake") + +if (NOT GLIB2_FOUND) + message(FATAL_ERROR "sdcv require ${GLIB2_REQ}, " + "make sure that you install it") +endif() + +find_path(READLINE_INCLUDE_DIR readline/readline.h) +find_library(READLINE_LIBRARY NAMES readline) +if (READLINE_INCLUDE_DIR AND READLINE_LIBRARY) + set(WITH_READLINE TRUE) +endif () + +find_package(GettextTools REQUIRED) +set(gettext_stockDir "${CMAKE_CURRENT_SOURCE_DIR}/po") +set(gettext_langDir "${CMAKE_CURRENT_BINARY_DIR}/lang") +set(gettext_outDir "${CMAKE_CURRENT_BINARY_DIR}/locale") + +set(sdcv_SRCS + src/sdcv.cpp + src/readline.cpp + src/readline.hpp + src/libwrapper.cpp + src/libwrapper.hpp + src/utils.cpp + src/utils.hpp + + src/lib/lib.cpp + src/lib/lib.h + src/lib/dictziplib.cpp + src/lib/dictziplib.hpp + src/lib/distance.cpp + src/lib/distance.h + src/lib/mapfile.hpp + src/lib/file.hpp +) + +gettext_make_target("lang" + HIERARCHY "{1}/{2}/{3}/{4}.mo" + KEYWORDS "_" + DOMAIN "sdcv-dom" + STOCK_DIR ${gettext_stockDir} + LANG_DIR ${gettext_langDir} + OUT_DIR ${gettext_outDir} + SOURCE ${sdcv_SRCS}) + +list(APPEND makeCleanFiles ${gettext_outDir}) + +include(CheckFunctionExists) +check_function_exists(mmap HAVE_MMAP) + +include(CheckIncludeFile) +check_include_file(locale.h HAVE_LOCALE_H) + +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake + ${CMAKE_CURRENT_BINARY_DIR}/config.h) + + +include_directories( + ${ZLIB_INCLUDE_DIR} + ${GLIB2_INCLUDE_DIRS} + ${CMAKE_CURRENT_SOURCE_DIR}/src/lib + ${CMAKE_CURRENT_BINARY_DIR} +) + +# +# Packing stuff +# +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "console version of StarDict program") +set(CPACK_PACKAGE_VENDOR "Evgeniy Dushistov ") +set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README") +set(CPACK_PACKAGE_VERSION_MAJOR "0") +set(CPACK_PACKAGE_VERSION_MINOR "5") +set(CPACK_PACKAGE_VERSION_PATCH "0-beta1") + +set(sdcv_VERSION + "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") + +add_definitions(-DVERSION="${sdcv_VERSION}" -DHAVE_CONFIG_H) + +add_executable(sdcv ${sdcv_SRCS}) + +target_link_libraries(sdcv + ${GLIB2_LIBRARIES} + ${ZLIB_LIBRARIES} + ${READLINE_LIBRARY} +) +set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "locale") + +include(CPack) diff --git a/cmake/FindGLIB2.cmake b/cmake/FindGLIB2.cmake new file mode 100644 index 0000000..db8d759 --- /dev/null +++ b/cmake/FindGLIB2.cmake @@ -0,0 +1,217 @@ +# - Try to find GLib2 +# Once done this will define +# +# GLIB2_FOUND - system has GLib2 +# GLIB2_INCLUDE_DIRS - the GLib2 include directory +# GLIB2_LIBRARIES - Link these to use GLib2 +# +# HAVE_GLIB_GREGEX_H glib has gregex.h header and +# supports g_regex_match_simple +# +# Copyright (c) 2006 Andreas Schneider +# Copyright (c) 2006 Philippe Bernery +# Copyright (c) 2007 Daniel Gollub +# Copyright (c) 2007 Alban Browaeys +# Copyright (c) 2008 Michael Bell +# Copyright (c) 2008 Bjoern Ricks +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# + + +IF (GLIB2_LIBRARIES AND GLIB2_INCLUDE_DIRS ) + # in cache already + SET(GLIB2_FOUND TRUE) +ELSE (GLIB2_LIBRARIES AND GLIB2_INCLUDE_DIRS ) + + INCLUDE(FindPkgConfig) + + ## Glib + IF ( GLIB2_FIND_REQUIRED ) + SET( _pkgconfig_REQUIRED "REQUIRED" ) + ELSE ( GLIB2_FIND_REQUIRED ) + SET( _pkgconfig_REQUIRED "" ) + ENDIF ( GLIB2_FIND_REQUIRED ) + + IF ( GLIB2_MIN_VERSION ) + PKG_SEARCH_MODULE( GLIB2 ${_pkgconfig_REQUIRED} glib-2.0>=${GLIB2_MIN_VERSION} ) + ELSE ( GLIB2_MIN_VERSION ) + PKG_SEARCH_MODULE( GLIB2 ${_pkgconfig_REQUIRED} glib-2.0 ) + ENDIF ( GLIB2_MIN_VERSION ) + IF ( PKG_CONFIG_FOUND ) + IF ( GLIB2_FOUND ) + SET ( GLIB2_CORE_FOUND TRUE ) + ELSE ( GLIB2_FOUND ) + SET ( GLIB2_CORE_FOUND FALSE ) + ENDIF ( GLIB2_FOUND ) + ENDIF ( PKG_CONFIG_FOUND ) + + # Look for glib2 include dir and libraries w/o pkgconfig + IF ( NOT GLIB2_FOUND AND NOT PKG_CONFIG_FOUND ) + FIND_PATH( + _glibconfig_include_DIR + NAMES + glibconfig.h + PATHS + /opt/gnome/lib64 + /opt/gnome/lib + /opt/lib/ + /opt/local/lib + /sw/lib/ + /usr/lib64 + /usr/lib + /usr/local/include + ${CMAKE_LIBRARY_PATH} + PATH_SUFFIXES + glib-2.0/include + ) + + FIND_PATH( + _glib2_include_DIR + NAMES + glib.h + PATHS + /opt/gnome/include + /opt/local/include + /sw/include + /usr/include + /usr/local/include + PATH_SUFFIXES + glib-2.0 + ) + + #MESSAGE(STATUS "Glib headers: ${_glib2_include_DIR}") + + FIND_LIBRARY( + _glib2_link_DIR + NAMES + glib-2.0 + glib + PATHS + /opt/gnome/lib + /opt/local/lib + /sw/lib + /usr/lib + /usr/local/lib + ) + IF ( _glib2_include_DIR AND _glib2_link_DIR ) + SET ( _glib2_FOUND TRUE ) + ENDIF ( _glib2_include_DIR AND _glib2_link_DIR ) + + + IF ( _glib2_FOUND ) + SET ( GLIB2_INCLUDE_DIRS ${_glib2_include_DIR} ${_glibconfig_include_DIR} ) + SET ( GLIB2_LIBRARIES ${_glib2_link_DIR} ) + SET ( GLIB2_CORE_FOUND TRUE ) + ELSE ( _glib2_FOUND ) + SET ( GLIB2_CORE_FOUND FALSE ) + ENDIF ( _glib2_FOUND ) + + # Handle dependencies + # libintl + IF ( NOT LIBINTL_FOUND ) + FIND_PATH(LIBINTL_INCLUDE_DIR + NAMES + libintl.h + PATHS + /opt/gnome/include + /opt/local/include + /sw/include + /usr/include + /usr/local/include + ) + + FIND_LIBRARY(LIBINTL_LIBRARY + NAMES + intl + PATHS + /opt/gnome/lib + /opt/local/lib + /sw/lib + /usr/local/lib + /usr/lib + ) + + IF (LIBINTL_LIBRARY AND LIBINTL_INCLUDE_DIR) + SET (LIBINTL_FOUND TRUE) + ENDIF (LIBINTL_LIBRARY AND LIBINTL_INCLUDE_DIR) + ENDIF ( NOT LIBINTL_FOUND ) + + # libiconv + IF ( NOT LIBICONV_FOUND ) + FIND_PATH(LIBICONV_INCLUDE_DIR + NAMES + iconv.h + PATHS + /opt/gnome/include + /opt/local/include + /opt/local/include + /sw/include + /sw/include + /usr/local/include + /usr/include + PATH_SUFFIXES + glib-2.0 + ) + + FIND_LIBRARY(LIBICONV_LIBRARY + NAMES + iconv + PATHS + /opt/gnome/lib + /opt/local/lib + /sw/lib + /usr/lib + /usr/local/lib + ) + + IF (LIBICONV_LIBRARY AND LIBICONV_INCLUDE_DIR) + SET (LIBICONV_FOUND TRUE) + ENDIF (LIBICONV_LIBRARY AND LIBICONV_INCLUDE_DIR) + ENDIF ( NOT LIBICONV_FOUND ) + + IF (LIBINTL_FOUND) + SET (GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${LIBINTL_LIBRARY}) + SET (GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${LIBINTL_INCLUDE_DIR}) + ENDIF (LIBINTL_FOUND) + + IF (LIBICONV_FOUND) + SET (GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${LIBICONV_LIBRARY}) + SET (GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${LIBICONV_INCLUDE_DIR}) + ENDIF (LIBICONV_FOUND) + + ENDIF ( NOT GLIB2_FOUND AND NOT PKG_CONFIG_FOUND ) + ## + + IF (GLIB2_CORE_FOUND AND GLIB2_INCLUDE_DIRS AND GLIB2_LIBRARIES) + SET (GLIB2_FOUND TRUE) + ENDIF (GLIB2_CORE_FOUND AND GLIB2_INCLUDE_DIRS AND GLIB2_LIBRARIES) + + IF (GLIB2_FOUND) + IF (NOT GLIB2_FIND_QUIETLY) + MESSAGE (STATUS "Found GLib2: ${GLIB2_LIBRARIES} ${GLIB2_INCLUDE_DIRS}") + ENDIF (NOT GLIB2_FIND_QUIETLY) + ELSE (GLIB2_FOUND) + IF (GLIB2_FIND_REQUIRED) + MESSAGE (SEND_ERROR "Could not find GLib2") + ENDIF (GLIB2_FIND_REQUIRED) + ENDIF (GLIB2_FOUND) + + # show the GLIB2_INCLUDE_DIRS and GLIB2_LIBRARIES variables only in the advanced view + MARK_AS_ADVANCED(GLIB2_INCLUDE_DIRS GLIB2_LIBRARIES) + MARK_AS_ADVANCED(LIBICONV_INCLUDE_DIR LIBICONV_LIBRARY) + MARK_AS_ADVANCED(LIBINTL_INCLUDE_DIR LIBINTL_LIBRARY) + +ENDIF (GLIB2_LIBRARIES AND GLIB2_INCLUDE_DIRS) + +IF ( GLIB2_FOUND ) + # Check if system has a newer version of glib + # which supports g_regex_match_simple + INCLUDE( CheckIncludeFiles ) + SET( CMAKE_REQUIRED_INCLUDES ${GLIB2_INCLUDE_DIRS} ) + CHECK_INCLUDE_FILES ( glib/gregex.h HAVE_GLIB_GREGEX_H ) + # Reset CMAKE_REQUIRED_INCLUDES + SET( CMAKE_REQUIRED_INCLUDES "" ) +ENDIF( GLIB2_FOUND ) diff --git a/cmake/FindGettextTools.cmake b/cmake/FindGettextTools.cmake new file mode 100644 index 0000000..231813b --- /dev/null +++ b/cmake/FindGettextTools.cmake @@ -0,0 +1,152 @@ +# - Finds GNU gettext and provides tools +# This module looks for the GNU gettext tools. This module defines the +# following values: +# GETTEXT_XGETTEXT_EXECUTABLE: The full path to the xgettext tool. +# GETTEXT_MSGMERGE_EXECUTABLE: The full path to the msgmerge tool. +# GETTEXT_MSGFMT_EXECUTABLE: The full path to the msgfmt tool. +# GETTEXT_FOUND: True if gettext has been found. +# GETTEXT_VERSION_STRING: The version of gettext found (since CMake 2.8.8) +# +# It provides the following macro: +# +# GETTEXT_MAKE_TARGET ( +# targetName +# HIERARCHY +# KEYWORDS keyword1 ... keywordN +# DOMAIN +# STOCK_DIR +# LANG_DIR +# OUT_DIR +# SOURCE sourceFile1 ... sourceFileN ) +# +# Creates a target that will take a set of translatable source files, +# create a Gettext pot file then copy stock translations in to the build +# directory to allow user editing, then compiles them in to mo files in a +# directory hierarchy to be used in the application. +# +# USAGE: +# targetName (e.g., "lang") +# The name of the target that will be created to generate translations. +# +# HIERARCHY (e.g., "{1}/{2}/{3}/{4}.mo") +# This is the format in which compiled message catalogs are placed. +# {1}: The path prefix. (e.g., "/my-repo/build/locale/") +# {2}: The language name. (e.g., "en") +# {3}: The catalog category. (e.g., "LC_MESSAGES") +# {4}: The domain. (e.g., "my-app") +# +# KEYWORDS (e.g., "_") +# A list of keywords used by xgettext to find translatable strings in the +# source files. +# +# DOMAIN (e.g., "my-app") +# The Gettext domain. It should be unique to your application. +# +# STOCK_DIR (e.g., "/my-repo/stock-lang/") +# The path to the initial translations to be copied to the LANG_DIR. +# If you have a set of official translations in your source repository, +# you'd want to set STOCK_DIR to this. +# +# LANG_DIR (e.g., "lang") +# The name of the directory to be created in the build folder, containing +# editable translations and updated templates. +# +# OUT_DIR (e.g., "locale") +# The directory that compiled catalogs will be placed in, according to +# the HIERARCHY format. +# +# SOURCE (e.g., "main.c") +# A list of source files to read translatable strings from. Usually this +# could be the same list you pass to add_executable. +# +# If you use the examples above and have a structure like this: +# /my-repo/stock-lang/en.po +# +# You may end up with this structure: +# /my-repo/stock-lang/en.po +# /my-repo/build/lang/my-app.pot +# /my-repo/build/lang/en.po +# /my-repo/build/locale/en/LC_MESSAGES/my-app.mo + +# This nasty set of tools is divided up in to three files: +# FindGettextTools.cmake +# This is the file you're reading right now. It provides a neat macro. +# FindGettextTools/config.cmake.in +# This is used as the bridge to transfer arguments from the macro to the +# actual script used to do Gettext stuff. A copy is created and filled in by +# FindGettextTools.cmake and read by FindGettextTools/script.cmake. +# The copy is found in the target's directory in the CMakeFiles directory +# under the name 'gettext.cmake'. +# FindGettextTools/script.cmake +# Does Gettext things based on the bridge config file whenever the target +# created using FindGettextTools.cmake is run. + +FIND_PROGRAM(GETTEXT_XGETTEXT_EXECUTABLE xgettext) +FIND_PROGRAM(GETTEXT_MSGMERGE_EXECUTABLE msgmerge) +FIND_PROGRAM(GETTEXT_MSGFMT_EXECUTABLE msgfmt) + +SET(_gettextScript "${CMAKE_CURRENT_LIST_DIR}/FindGettextTools/script.cmake") +SET(_gettextConfig "${CMAKE_CURRENT_LIST_DIR}/FindGettextTools/config.cmake.in") + +IF(GETTEXT_XGETTEXT_EXECUTABLE) + EXECUTE_PROCESS(COMMAND ${GETTEXT_XGETTEXT_EXECUTABLE} --version + OUTPUT_VARIABLE gettext_version + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + IF(gettext_version MATCHES "^xgettext \\(.*\\) [0-9]") + STRING(REGEX REPLACE "^xgettext \\([^\\)]*\\) ([0-9\\.]+[^ \n]*).*" "\\1" + GETTEXT_VERSION_STRING "${gettext_version}") + ENDIF() + SET(gettext_version) +ENDIF() + +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Gettext + REQUIRED_VARS + GETTEXT_XGETTEXT_EXECUTABLE + GETTEXT_MSGMERGE_EXECUTABLE + GETTEXT_MSGFMT_EXECUTABLE + VERSION_VAR GETTEXT_VERSION_STRING) + +INCLUDE(CMakeParseArguments) + +FUNCTION(GETTEXT_MAKE_TARGET _targetName) + SET(_oneValueArgs HIERARCHY DOMAIN STOCK_DIR LANG_DIR OUT_DIR) + SET(_multiValueArgs KEYWORDS SOURCE) + + CMAKE_PARSE_ARGUMENTS(_parsedArguments + "" + "${_oneValueArgs}" + "${_multiValueArgs}" + "${ARGN}") + + IF(NOT ( + _parsedArguments_HIERARCHY AND + _parsedArguments_KEYWORDS AND + _parsedArguments_DOMAIN AND + _parsedArguments_STOCK_DIR AND + _parsedArguments_LANG_DIR AND + _parsedArguments_OUT_DIR AND + _parsedArguments_SOURCE)) + MESSAGE(FATAL_ERROR "Wrong usage!") + ENDIF() + + SET(_config + "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${_targetName}.dir/gettext.cmake") + + CONFIGURE_FILE(${_gettextConfig} ${_config}) + + ADD_CUSTOM_TARGET(${_targetName} ${CMAKE_COMMAND} "-P" ${_gettextScript} + ${_config}) +ENDFUNCTION() + +IF(GETTEXT_MSGMERGE_EXECUTABLE AND + GETTEXT_MSGFMT_EXECUTABLE AND + GETTEXT_XGETTEXT_EXECUTABLE) + SET(GETTEXT_FOUND TRUE) +ELSE() + SET(GETTEXT_FOUND FALSE) + IF(GETTEXT_REQUIRED) + MESSAGE(FATAL_ERROR "Gettext not found") + ENDIF() +ENDIF() diff --git a/cmake/FindGettextTools/config.cmake.in b/cmake/FindGettextTools/config.cmake.in new file mode 100644 index 0000000..57e3739 --- /dev/null +++ b/cmake/FindGettextTools/config.cmake.in @@ -0,0 +1,14 @@ +# This file is automatically generated by GettextTools. +# It WILL be overwritten by CMake, so editing it is futile. Sorry! + +set(hierarchy "${_parsedArguments_HIERARCHY}") +set(keywords "${_parsedArguments_KEYWORDS}") +set(domain "${_parsedArguments_DOMAIN}") +set(sourcePrefix "${CMAKE_CURRENT_SOURCE_DIR}") +set(stockDir "${_parsedArguments_STOCK_DIR}") +set(langDir "${_parsedArguments_LANG_DIR}") +set(outDir "${_parsedArguments_OUT_DIR}") +set(XGETTEXT_EXECUTABLE "${GETTEXT_XGETTEXT_EXECUTABLE}") +set(MSGMERGE_EXECUTABLE "${GETTEXT_MSGMERGE_EXECUTABLE}") +set(MSGFMT_EXECUTABLE "${GETTEXT_MSGFMT_EXECUTABLE}") +set(sourceFiles "${_parsedArguments_SOURCE}") diff --git a/cmake/FindGettextTools/script.cmake b/cmake/FindGettextTools/script.cmake new file mode 100644 index 0000000..364c5ea --- /dev/null +++ b/cmake/FindGettextTools/script.cmake @@ -0,0 +1,103 @@ +# ----- Set up variables. + +# Read variables from the generated config. +include(${CMAKE_ARGV3}) + +# Transform keywords in to flags. +set(keywordArgs "") +foreach(keyword ${keywords}) + list(APPEND keywordArgs "--keyword=${keyword}") +endforeach() + +# ----- Make the pot file. + +message("Creating translation template...") + +file(MAKE_DIRECTORY ${langDir}) + +set(potFile "${langDir}/${domain}.pot") + +execute_process(COMMAND ${XGETTEXT_EXECUTABLE} + "--output=${potFile}" + "--omit-header" "--add-comments" + ${keywordArgs} + ${sourceFiles} + WORKING_DIRECTORY ${sourcePrefix}) + +message(" '${domain}.pot' done.") + +# ----- Copy and merge across the po files that come with the source. + +message("Copying and updating stock translations...") + +file(GLOB poFiles "${stockDir}/*.po") + +foreach(file ${poFiles}) + # Get the language name, like en_US or zh_CN from the name of the po file, so + # 'en_US.po' or 'zh_CN.po' become 'en_US' or 'zh_CN.po' + get_filename_component(langName ${file} NAME_WE) + + set(newFile "${langDir}/${langName}.po") + + if(NOT EXISTS ${newFile}) + execute_process(COMMAND ${MSGMERGE_EXECUTABLE} + "--output-file" ${newFile} ${file} ${potFile} + OUTPUT_QUIET ERROR_VARIABLE error RESULT_VARIABLE ret) + + if(ret) # Have to do this hack as msgmerge prints to stderr. + message(SEND_ERROR "${error}") + endif() + + message(" '${langName}' copied.") + elseif(${file} IS_NEWER_THAN ${newFile}) + execute_process(COMMAND ${MSGMERGE_EXECUTABLE} + "--update" ${newFile} ${file} + OUTPUT_QUIET ERROR_VARIABLE error RESULT_VARIABLE ret) + + if(ret) # Have to do this hack as msgmerge prints to stderr. + message(SEND_ERROR "${error}") + endif() + + message(" '${langName}' merged.") + endif() +endforeach() + +# ----- Process the files in to mo files. + +message("Compiling translations...") + +file(GLOB localPoFiles "${langDir}/*.po") + +foreach(file ${localPoFiles}) + execute_process(COMMAND ${MSGMERGE_EXECUTABLE} + "--update" ${file} ${potFile} + OUTPUT_QUIET ERROR_VARIABLE error RESULT_VARIABLE ret) + + if(ret) # Have to do this hack as msgmerge prints to stderr. + message(SEND_ERROR "${error}") + endif() + + get_filename_component(langName ${file} NAME_WE) + + set(binaryFile "${hierarchy}") + string(REPLACE "{1}" "${outDir}" binaryFile "${binaryFile}") + string(REPLACE "{2}" "${langName}" binaryFile "${binaryFile}") + string(REPLACE "{3}" "LC_MESSAGES" binaryFile "${binaryFile}") + string(REPLACE "{4}" "${domain}" binaryFile "${binaryFile}") + + if(${file} IS_NEWER_THAN ${binaryFile}) + get_filename_component(binaryDir ${binaryFile} PATH) + + file(MAKE_DIRECTORY ${binaryDir}) + + execute_process(COMMAND ${MSGFMT_EXECUTABLE} + ${file} "--output-file" ${binaryFile} + OUTPUT_QUIET ERROR_VARIABLE error RESULT_VARIABLE ret) + + if(ret) # Have to do this hack as msgfmt prints to stderr. + message(SEND_ERROR "${error}") + endif() + + message(" '${langName}' done.") + endif() +endforeach() diff --git a/cmake/FindIconv.cmake b/cmake/FindIconv.cmake new file mode 100644 index 0000000..092b357 --- /dev/null +++ b/cmake/FindIconv.cmake @@ -0,0 +1,64 @@ +# - Try to find Iconv +# Once done this will define +# +# ICONV_FOUND - system has Iconv +# ICONV_INCLUDE_DIR - the Iconv include directory +# ICONV_LIBRARIES - Link these to use Iconv +# ICONV_SECOND_ARGUMENT_IS_CONST - the second argument for iconv() is const +# +include(CheckCCompilerFlag) +include(CheckCSourceCompiles) + +IF (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) + # Already in cache, be silent + SET(ICONV_FIND_QUIETLY TRUE) +ENDIF (ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) + +FIND_PATH(ICONV_INCLUDE_DIR iconv.h HINTS /sw/include/ PATHS /opt/local) + +FIND_LIBRARY(ICONV_LIBRARIES NAMES iconv libiconv c PATHS /opt/local) + +IF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) + SET(ICONV_FOUND TRUE) +ENDIF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) + +set(CMAKE_REQUIRED_INCLUDES ${ICONV_INCLUDE_DIR}) +set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES}) +IF(ICONV_FOUND) + check_c_compiler_flag("-Werror" ICONV_HAVE_WERROR) + set (CMAKE_C_FLAGS_BACKUP "${CMAKE_C_FLAGS}") + if(ICONV_HAVE_WERROR) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") + endif(ICONV_HAVE_WERROR) + check_c_source_compiles(" + #include + int main(){ + iconv_t conv = 0; + const char* in = 0; + size_t ilen = 0; + char* out = 0; + size_t olen = 0; + iconv(conv, &in, &ilen, &out, &olen); + return 0; + } +" ICONV_SECOND_ARGUMENT_IS_CONST ) + set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS_BACKUP}") +ENDIF(ICONV_FOUND) +set(CMAKE_REQUIRED_INCLUDES) +set(CMAKE_REQUIRED_LIBRARIES) + +IF(ICONV_FOUND) + IF(NOT ICONV_FIND_QUIETLY) + MESSAGE(STATUS "Found Iconv: ${ICONV_LIBRARIES}") + ENDIF(NOT ICONV_FIND_QUIETLY) +ELSE(ICONV_FOUND) + IF(Iconv_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could not find Iconv") + ENDIF(Iconv_FIND_REQUIRED) +ENDIF(ICONV_FOUND) + +MARK_AS_ADVANCED( + ICONV_INCLUDE_DIR + ICONV_LIBRARIES + ICONV_SECOND_ARGUMENT_IS_CONST +) diff --git a/cmake/FindLibintl.cmake b/cmake/FindLibintl.cmake new file mode 100644 index 0000000..7fec58b --- /dev/null +++ b/cmake/FindLibintl.cmake @@ -0,0 +1,56 @@ +# Try to find the libintl library. Explicit searching is currently +# only required for Win32, though it might be useful for some UNIX +# variants, too. Therefore code for searching common UNIX include +# directories is included, too. +# +# Once done this will define +# +# LIBINTL_FOUND - system has libintl +# LIBINTL_LIBRARIES - libraries needed for linking + +IF (LIBINTL_FOUND) + SET(LIBINTL_FIND_QUIETLY TRUE) +ENDIF () + +# for Windows we rely on the environement variables +# %INCLUDE% and %LIB%; FIND_LIBRARY checks %LIB% +# automatically on Windows +IF(WIN32) + FIND_LIBRARY(LIBINTL_LIBRARIES + NAMES intl + ) + IF(LIBINTL_LIBRARIES) + SET(LIBINTL_FOUND TRUE) + ELSE(LIBINTL_LIBRARIES) + SET(LIBINTL_FOUND FALSE) + ENDIF(LIBINTL_LIBRARIES) +ELSE() + include(CheckFunctionExists) + check_function_exists(dgettext LIBINTL_LIBC_HAS_DGETTEXT) + if (LIBINTL_LIBC_HAS_DGETTEXT) + find_library(LIBINTL_LIBRARIES NAMES c) + set(LIBINTL_FOUND TRUE) + else (LIBINTL_LIBC_HAS_DGETTEXT) + find_library(LIBINTL_LIBRARIES + NAMES intl libintl + PATHS /usr/lib /usr/local/lib + ) + IF(LIBINTL_LIBRARIES) + SET(LIBINTL_FOUND TRUE) + ELSE(LIBINTL_LIBRARIES) + SET(LIBINTL_FOUND FALSE) + ENDIF(LIBINTL_LIBRARIES) + ENDIF (LIBINTL_LIBC_HAS_DGETTEXT) +ENDIF() + +IF (LIBINTL_FOUND) + IF (NOT LIBINTL_FIND_QUIETLY) + MESSAGE(STATUS "Found libintl: ${LIBINTL_LIBRARIES}") + ENDIF () +ELSE () + IF (LIBINTL_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "Could NOT find libintl") + ENDIF () +ENDIF () + +MARK_AS_ADVANCED(LIBINTL_LIBRARIES LIBINTL_LIBC_HAS_DGETTEXT) diff --git a/cmake/FindPackageHandleStandardArgs.cmake b/cmake/FindPackageHandleStandardArgs.cmake new file mode 100644 index 0000000..151d812 --- /dev/null +++ b/cmake/FindPackageHandleStandardArgs.cmake @@ -0,0 +1,58 @@ +# FIND_PACKAGE_HANDLE_STANDARD_ARGS(NAME (DEFAULT_MSG|"Custom failure message") VAR1 ... ) +# This macro is intended to be used in FindXXX.cmake modules files. +# It handles the REQUIRED and QUIET argument to FIND_PACKAGE() and +# it also sets the _FOUND variable. +# The package is found if all variables listed are TRUE. +# Example: +# +# FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2 DEFAULT_MSG LIBXML2_LIBRARIES LIBXML2_INCLUDE_DIR) +# +# LibXml2 is considered to be found, if both LIBXML2_LIBRARIES and +# LIBXML2_INCLUDE_DIR are valid. Then also LIBXML2_FOUND is set to TRUE. +# If it is not found and REQUIRED was used, it fails with FATAL_ERROR, +# independent whether QUIET was used or not. +# If it is found, the location is reported using the VAR1 argument, so +# here a message "Found LibXml2: /usr/lib/libxml2.so" will be printed out. +# If the second argument is DEFAULT_MSG, the message in the failure case will +# be "Could NOT find LibXml2", if you don't like this message you can specify +# your own custom failure message there. + +MACRO(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FAIL_MSG _VAR1 ) + + IF("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG") + IF (${_NAME}_FIND_REQUIRED) + SET(_FAIL_MESSAGE "Could not find REQUIRED package ${_NAME}") + ELSE (${_NAME}_FIND_REQUIRED) + SET(_FAIL_MESSAGE "Could not find OPTIONAL package ${_NAME}") + ENDIF (${_NAME}_FIND_REQUIRED) + ELSE("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG") + SET(_FAIL_MESSAGE "${_FAIL_MSG}") + ENDIF("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG") + + STRING(TOUPPER ${_NAME} _NAME_UPPER) + + SET(${_NAME_UPPER}_FOUND TRUE) + IF(NOT ${_VAR1}) + SET(${_NAME_UPPER}_FOUND FALSE) + ENDIF(NOT ${_VAR1}) + + FOREACH(_CURRENT_VAR ${ARGN}) + IF(NOT ${_CURRENT_VAR}) + SET(${_NAME_UPPER}_FOUND FALSE) + ENDIF(NOT ${_CURRENT_VAR}) + ENDFOREACH(_CURRENT_VAR) + + IF (${_NAME_UPPER}_FOUND) + IF (NOT ${_NAME}_FIND_QUIETLY) + MESSAGE(STATUS "Found ${_NAME}: ${${_VAR1}}") + ENDIF (NOT ${_NAME}_FIND_QUIETLY) + ELSE (${_NAME_UPPER}_FOUND) + IF (${_NAME}_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "${_FAIL_MESSAGE}") + ELSE (${_NAME}_FIND_REQUIRED) + IF (NOT ${_NAME}_FIND_QUIETLY) + MESSAGE(STATUS "${_FAIL_MESSAGE}") + ENDIF (NOT ${_NAME}_FIND_QUIETLY) + ENDIF (${_NAME}_FIND_REQUIRED) + ENDIF (${_NAME_UPPER}_FOUND) +ENDMACRO(FIND_PACKAGE_HANDLE_STANDARD_ARGS) diff --git a/config.h.cmake b/config.h.cmake new file mode 100644 index 0000000..36c2d37 --- /dev/null +++ b/config.h.cmake @@ -0,0 +1,3 @@ +#cmakedefine HAVE_MMAP 1 +#cmakedefine HAVE_LOCALE_H 1 +#cmakedefine WITH_READLINE 1 \ No newline at end of file