robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
404fdb0f36
master
1include ( CheckCSourceCompiles ) 2include ( CheckVariableExists ) 3 4# Append custom gettext path to CMAKE_PREFIX_PATH 5# if installed via Mac Homebrew 6if ( APPLE) 7find_program ( HOMEBREW_PRG brew ) 8if ( EXISTS ${ HOMEBREW_PRG }) 9execute_process ( COMMAND ${ HOMEBREW_PRG } --prefix gettext 10OUTPUT_STRIP_TRAILING_WHITESPACE 11OUTPUT_VARIABLE HOMEBREW_GETTEXT_PREFIX ) 12list ( APPEND CMAKE_PREFIX_PATH " ${ HOMEBREW_GETTEXT_PREFIX } " ) 13endif () 14endif () 15 16find_path ( LIBINTL_INCLUDE_DIR 17NAMES libintl.h 18PATH_SUFFIXES gettext 19) 20 21find_library ( LIBINTL_LIBRARY 22NAMES intl libintl 23) 24 25if ( LIBINTL_INCLUDE_DIR) 26list ( APPEND CMAKE_REQUIRED_INCLUDES " ${ LIBINTL_INCLUDE_DIR } " ) 27endif () 28# On some systems (linux+glibc) libintl is passively available. 29# So only specify the library if one was found. 30if ( LIBINTL_LIBRARY) 31list ( APPEND CMAKE_REQUIRED_LIBRARIES " ${ LIBINTL_LIBRARY } " ) 32endif () 33if ( MSVC) 34list ( APPEND CMAKE_REQUIRED_LIBRARIES ${ ICONV_LIBRARY }) 35endif () 36 37# On macOS, if libintl is a static library then we also need 38# to link libiconv and CoreFoundation. 39get_filename_component ( LibIntl_EXT " ${ LIBINTL_LIBRARY } " EXT ) 40if ( APPLEAND ( LibIntl_EXTSTREQUAL ".a" )) 41set ( LibIntl_STATIC TRUE ) 42find_library ( CoreFoundation_FRAMEWORK CoreFoundation ) 43list ( APPEND CMAKE_REQUIRED_LIBRARIES " ${ ICONV_LIBRARY } " " ${ CoreFoundation_FRAMEWORK } " ) 44endif () 45 46check_c_source_compiles ( " 47#include <libintl.h> 48 49int main(int argc, char** argv) { 50gettext(\"foo\"); 51ngettext(\"foo\", \"bar\", 1); 52bindtextdomain(\"foo\", \"bar\"); 53bind_textdomain_codeset(\"foo\", \"bar\"); 54textdomain(\"foo\"); 55}" HAVE_WORKING_LIBINTL ) 56if ( MSVC) 57list ( REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${ ICONV_LIBRARY }) 58endif () 59if ( LibIntl_STATIC) 60list ( REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES " ${ ICONV_LIBRARY } " " ${ CoreFoundation_FRAMEWORK } " ) 61endif () 62if ( LIBINTL_INCLUDE_DIR) 63list ( REMOVE_ITEM CMAKE_REQUIRED_INCLUDES " ${ LIBINTL_INCLUDE_DIR } " ) 64endif () 65if ( LIBINTL_LIBRARY) 66list ( REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES " ${ LIBINTL_LIBRARY } " ) 67endif () 68 69set ( REQUIRED_VARIABLES LIBINTL_LIBRARY LIBINTL_INCLUDE_DIR ) 70if ( HAVE_WORKING_LIBINTL) 71# On some systems (linux+glibc) libintl is passively available. 72# If HAVE_WORKING_LIBINTL then we consider the requirement satisfied. 73unset ( REQUIRED_VARIABLES ) 74 75check_variable_exists ( _nl_msg_cat_cntr HAVE_NL_MSG_CAT_CNTR ) 76endif () 77 78find_package_handle_standard_args ( Libintl DEFAULT_MSG 79${ REQUIRED_VARIABLES }) 80mark_as_advanced ( LIBINTL_LIBRARY LIBINTL_INCLUDE_DIR ) 81 82add_library ( libintl INTERFACE ) 83target_include_directories ( libintl SYSTEM BEFORE INTERFACE ${ LIBINTL_INCLUDE_DIR }) 84if ( LIBINTL_LIBRARY) 85target_link_libraries ( libintl INTERFACE ${ LIBINTL_LIBRARY }) 86endif ()