diff --git a/CMakeLists.txt b/CMakeLists.txt index 473b2dd46..5791f5682 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,6 +104,37 @@ if(ENABLE_NLS) find_package(Intl REQUIRED) include_directories(${Intl_INCLUDE_DIRS}) link_libraries(${Intl_LIBRARIES}) + + # begin static libintl support + # libintl.a may depend on libiconv.a and libcharset.a + # this is the case of vcpkg + mingw, for example + macro(try_compile_intl) + set(_argv ${ARGV}) + try_compile(INTLLIB ${CMAKE_BINARY_DIR} + "${CMAKE_SOURCE_DIR}/checks/intl.cpp" + LINK_LIBRARIES ${_argv} + CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${Intl_INCLUDE_DIRS}") + endmacro() + + try_compile_intl(${Intl_LIBRARIES}) + if (NOT INTLLIB) + message(STATUS "Checking for libiconv and libcharset dependencies of libintl") + find_package(Iconv REQUIRED) + link_libraries(${Iconv_LIBRARIES}) + + try_compile_intl(${Intl_LIBRARIES} ${Iconv_LIBRARIES}) + if (NOT INTLLIB) + find_library(Charset_LIBRARY NAMES libcharset charset HINTS Charset_DIR) + try_compile_intl(${Intl_LIBRARIES} ${Iconv_LIBRARIES} ${Charset_LIBRARY}) + if (NOT INTLLIB) + message(FATAL_ERROR "LibIntl has unknown dependencies") + else() + link_libraries(${Charset_LIBRARY}) + endif() + endif() + endif() + # end static libintl support + add_definitions(-DENABLE_NLS) else() message(STATUS "NLS is disabled. Not looking for gettext and libintl.") diff --git a/checks/intl.cpp b/checks/intl.cpp new file mode 100644 index 000000000..28a89b6f5 --- /dev/null +++ b/checks/intl.cpp @@ -0,0 +1,7 @@ +#include + +int main() +{ + gettext("test"); + return 0; +}