Better handle libintl dependencies

pull/700/head
Hleb Valoshka 2020-04-12 10:24:00 +03:00
parent 91c3e618c2
commit 72bf923741
2 changed files with 38 additions and 0 deletions

View File

@ -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.")

7
checks/intl.cpp 100644
View File

@ -0,0 +1,7 @@
#include <libintl.h>
int main()
{
gettext("test");
return 0;
}