GettextCMakeLists.txt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. cmake_minimum_required(VERSION 2.8.12)
  2. project(gettext C)
  3. # Adds PREFIX to each item in LIST
  4. macro(PREFIX_LIST_ITEMS LIST PREFIX)
  5. string(REPLACE ";" ";${PREFIX}" ${LIST} ";${${LIST}}")
  6. endmacro()
  7. file(READ gettext-runtime/config.h.in CONFIG_CONTENT)
  8. string(REPLACE "#undef HAVE_GETCWD" "#define HAVE_GETCWD 1" CONFIG_CONTENT ${CONFIG_CONTENT})
  9. string(REPLACE "#undef HAVE_ICONV_H" "#define HAVE_ICONV_H 1" CONFIG_CONTENT ${CONFIG_CONTENT})
  10. string(REPLACE "#undef HAVE_ICONV" "#define HAVE_ICONV 1" CONFIG_CONTENT ${CONFIG_CONTENT})
  11. string(REPLACE "#undef ICONV_CONST" "#define ICONV_CONST const" CONFIG_CONTENT ${CONFIG_CONTENT})
  12. string(REPLACE "#undef uintmax_t" "
  13. #if _WIN64
  14. # define intmax_t long long
  15. # define uintmax_t unsigned long long
  16. #elif _WIN32
  17. # define intmax_t long
  18. # define uintmax_t unsigned long
  19. #endif"
  20. CONFIG_CONTENT ${CONFIG_CONTENT})
  21. file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/gettext-runtime/config.h ${CONFIG_CONTENT})
  22. set(HAVE_NEWLOCALE 0)
  23. set(HAVE_POSIX_PRINTF 0)
  24. set(HAVE_SNPRINTF 0)
  25. set(HAVE_ASPRINTF 0)
  26. set(HAVE_WPRINTF 0)
  27. configure_file(gettext-runtime/intl/libgnuintl.in.h
  28. ${CMAKE_CURRENT_BINARY_DIR}/gettext-runtime/intl/libgnuintl.h)
  29. set(LOCALDIR "gettext")
  30. set(LIBDIR "gettext")
  31. set(PKGDATADIR "gettext")
  32. set(PACKAGE_SUFFIX "gettext")
  33. add_definitions(-DLOCALEDIR=\"${LOCALDIR}\"
  34. -DLOCALE_ALIAS_PATH=\"${LOCALDIR}\"
  35. -DLIBDIR=\"${LOCALDIR}\"
  36. -DINSTALLDIR=\"${LOCALDIR}\"
  37. -DEXEEXT=\".exe\"
  38. -DLOCALEDIR=\"${LOCALDIR}\"
  39. -DLIBDIR=\"${LIBDIR}\"
  40. -DPACKAGE_SUFFIX=\"${PACKAGE_SUFFIX}\"
  41. -DGETTEXTDATADIR=\"${PKGDATADIR}\"
  42. -DBISON_LOCALEDIR=\"${LOCALDIR}\"
  43. -DHAVE_CONFIG_H)
  44. set(libintl_SOURCES
  45. bindtextdom.c dcgettext.c dcigettext.c dcngettext.c dgettext.c dngettext.c
  46. explodename.c finddomain.c gettext.c hash-string.c l10nflist.c langprefs.c
  47. loadmsgcat.c localcharset.c localealias.c localename.c lock.c log.c ngettext.c
  48. plural-exp.c plural.c printf.c relocatable.c setlocale.c textdomain.c
  49. threadlib.c version.c)
  50. PREFIX_LIST_ITEMS(libintl_SOURCES "gettext-runtime/intl/")
  51. add_library(libintl ${libintl_SOURCES})
  52. set_property(TARGET libintl APPEND PROPERTY INCLUDE_DIRECTORIES
  53. ${CMAKE_CURRENT_BINARY_DIR}/gettext-runtime
  54. ${CMAKE_CURRENT_BINARY_DIR}/gettext-runtime/intl
  55. ${LIBICONV_INCLUDE_DIRS})
  56. set_property(TARGET libintl APPEND PROPERTY COMPILE_DEFINITIONS
  57. BUILDING_LIBINTL
  58. IN_LIBINTL
  59. ENABLE_RELOCATABLE=1
  60. IN_LIBRARY
  61. NO_XMALLOC
  62. set_relocation_prefix=libintl_set_relocation_prefix
  63. relocate=libintl_relocate
  64. HAVE_CONFIG_H
  65. _CRT_SECURE_NO_WARNINGS)
  66. file(READ gettext-tools/config.h.in CONFIG_CONTENT)
  67. string(REPLACE "#undef ENDIANNESS" "#define ENDIANNESS 0" CONFIG_CONTENT ${CONFIG_CONTENT})
  68. string(REPLACE "#undef GNULIB_FWRITEERROR" "#define GNULIB_FWRITEERROR 1" CONFIG_CONTENT ${CONFIG_CONTENT})
  69. string(REPLACE "#undef HAVE_DECL_STRERROR_R" "#define HAVE_DECL_STRERROR_R 0" CONFIG_CONTENT ${CONFIG_CONTENT})
  70. string(REPLACE "#undef HAVE_DUP2" "#define HAVE_DUP2 1" CONFIG_CONTENT ${CONFIG_CONTENT})
  71. string(REPLACE "#undef HAVE_ICONV_H" "#define HAVE_ICONV_H 1" CONFIG_CONTENT ${CONFIG_CONTENT})
  72. string(REPLACE "#undef HAVE_ICONV" "#define HAVE_ICONV 1" CONFIG_CONTENT ${CONFIG_CONTENT})
  73. string(REPLACE "#undef HAVE_LIBUNISTRING" "#define HAVE_LIBUNISTRING 1" CONFIG_CONTENT ${CONFIG_CONTENT})
  74. string(REPLACE "#undef HAVE_STDINT_H_WITH_UINTMAX" "#define HAVE_STDINT_H_WITH_UINTMAX 1" CONFIG_CONTENT ${CONFIG_CONTENT})
  75. string(REPLACE "#undef HAVE_STDINT_H" "#define HAVE_STDINT_H 1" CONFIG_CONTENT ${CONFIG_CONTENT})
  76. string(REPLACE "#undef HAVE_STRING_H" "#define HAVE_STRING_H 1" CONFIG_CONTENT ${CONFIG_CONTENT})
  77. string(REPLACE "#undef HAVE_SYS_TIMEB_H" "#define HAVE_SYS_TIMEB_H 1" CONFIG_CONTENT ${CONFIG_CONTENT})
  78. string(REPLACE "#undef HAVE__FTIME" "#define HAVE__FTIME 1" CONFIG_CONTENT ${CONFIG_CONTENT})
  79. string(REPLACE "#undef ICONV_CONST" "#define ICONV_CONST const" CONFIG_CONTENT ${CONFIG_CONTENT})
  80. string(REPLACE "#undef PACKAGE" "#define PACKAGE \"gettext\"\n#define gettext_VERSION" CONFIG_CONTENT ${CONFIG_CONTENT})
  81. string(REPLACE "#undef VERSION" "#define VERSION \"\"" CONFIG_CONTENT ${CONFIG_CONTENT})
  82. string(REPLACE "#undef mode_t" "#define mode_t int" CONFIG_CONTENT ${CONFIG_CONTENT})
  83. string(REPLACE "#undef pid_t" "#define pid_t int" CONFIG_CONTENT ${CONFIG_CONTENT})
  84. string(REPLACE "#undef restrict" "#define restrict __restrict" CONFIG_CONTENT ${CONFIG_CONTENT})
  85. string(REPLACE "#undef ssize_t" "#include <BaseTsd.h>\n#define ssize_t SSIZE_T" CONFIG_CONTENT ${CONFIG_CONTENT})
  86. string(REPLACE "#undef uid_t" "#define uid_t int" CONFIG_CONTENT ${CONFIG_CONTENT})
  87. file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/gettext-tools/config.h ${CONFIG_CONTENT})
  88. set(libgettextsrc_COMMON_SOURCE
  89. message.c po-error.c po-xerror.c read-catalog-abstract.c po-lex.c
  90. po-gram-gen.c po-charset.c read-po.c read-properties.c read-stringtable.c
  91. open-catalog.c dir-list.c
  92. str-list.c)
  93. set(libgettextsrc_FORMAT_SOURCE
  94. format.c format-invalid.h format-c.c format-c-parse.h format-sh.c
  95. format-python.c format-python-brace.c format-lisp.c format-elisp.c
  96. format-librep.c format-scheme.c format-java.c format-csharp.c format-awk.c
  97. format-pascal.c format-ycp.c format-tcl.c format-perl.c format-perl-brace.c
  98. format-php.c format-gcc-internal.c format-gfc-internal.c format-qt.c
  99. format-qt-plural.c format-kde.c format-kde-kuit.c format-boost.c format-lua.c
  100. format-javascript.c)
  101. set(libgettextsrc_SOURCES
  102. ${libgettextsrc_COMMON_SOURCE} read-catalog.c color.c write-catalog.c
  103. write-properties.c write-stringtable.c write-po.c msgl-ascii.c msgl-iconv.c
  104. msgl-equal.c msgl-cat.c msgl-header.c msgl-english.c msgl-check.c file-list.c
  105. msgl-charset.c po-time.c plural-exp.c plural-eval.c plural-count.c
  106. plural-table.c quote.h sentence.h sentence.c ${libgettextsrc_FORMAT_SOURCE}
  107. read-desktop.c locating-rule.c its.c search-path.c)
  108. PREFIX_LIST_ITEMS(libgettextsrc_SOURCES "gettext-tools/src/")
  109. set(GLIBC_SOURCE
  110. uniname/uniname.c javaexec.c unsetenv.c classpath.c setenv.c xsetenv.c
  111. sh-quote.c execute.c javaversion.c csharpcomp.c csharpexec.c javacomp.c
  112. gettimeofday.c getdtablesize.c fcntl.c dup-safer-flag.c cloexec.c
  113. fd-safer-flag.c fd-safer.c pipe2.c pipe2-safer.c spawn-pipe.c xmemdup0.c
  114. secure_getenv.c tmpdir.c tempname.c mkdtemp.c fnmatch.c clean-temp.c
  115. gl_array_list.c tputs.c wait-process.c waitpid.c getdelim.c getline.c
  116. sigprocmask.c sigaction.c addext.c argmatch.c backupfile.c basename.c
  117. c-strcasecmp.c c-strncasecmp.c c-strstr.c closeout.c concat-filename.c
  118. error-progname.c error.c exitfail.c file-ostream.c fstrcmp.c full-write.c
  119. fwriteerror.c getopt.c getopt1.c hash.c libxml/buf.c localcharset.c malloca.c
  120. mbchar.c mbslen.c mbsstr.c mbswidth.c obstack.c ostream.c html-ostream.c
  121. fd-ostream.c styled-ostream.c progname.c html-styled-ostream.c printf-args.c
  122. printf-parse.c propername.c quotearg.c rawmemchr.c safe-read.c safe-write.c
  123. stpcpy.c stpncpy.c strchrnul.c striconv.c striconveh.c striconveha.c strnlen1.c
  124. term-ostream.c term-styled-ostream.c tparm.c trim.c gcd.c gl_linkedhash_list.c
  125. uniconv/u8-conv-from-enc.c unictype/ctype_space.c unilbrk/lbrktables.c
  126. unilbrk/u8-possible-linebreaks.c unilbrk/u8-width-linebreaks.c
  127. unilbrk/ulc-common.c unilbrk/ulc-width-linebreaks.c unistr/u16-mbtouc-aux.c
  128. unistr/u16-mbtouc.c unistr/u8-check.c unistr/u8-mblen.c unistr/u8-mbtouc-aux.c
  129. unistr/u8-mbtouc-unsafe-aux.c unistr/u8-mbtouc-unsafe.c unistr/u8-mbtouc.c
  130. unistr/u8-mbtoucr.c unistr/u8-prev.c unistr/u8-uctomb-aux.c unistr/u8-uctomb.c
  131. uniwidth/width.c vasnprintf.c vasprintf.c wcwidth.c xasprintf.c
  132. xconcat-filename.c xerror.c xmalloc.c xstrdup.c xstriconv.c xstriconveh.c xvasprintf.c glib/ghash.c
  133. glib/glist.c glib/gmessages.c glib/gprimes.c glib/gstrfuncs.c glib/gstring.c
  134. libcroco/cr-additional-sel.c libcroco/cr-attr-sel.c libcroco/cr-cascade.c
  135. libcroco/cr-declaration.c libcroco/cr-doc-handler.c libcroco/cr-enc-handler.c
  136. libcroco/cr-fonts.c libcroco/cr-input.c libcroco/cr-num.c
  137. libcroco/cr-om-parser.c libcroco/cr-parser.c libcroco/cr-parsing-location.c
  138. libcroco/cr-prop-list.c libcroco/cr-pseudo.c libcroco/cr-rgb.c
  139. libcroco/cr-sel-eng.c libcroco/cr-selector.c libcroco/cr-simple-sel.c
  140. libcroco/cr-statement.c libcroco/cr-string.c libcroco/cr-style.c
  141. libcroco/cr-stylesheet.c libcroco/cr-term.c libcroco/cr-tknzr.c
  142. libcroco/cr-token.c libcroco/cr-utils.c libxml/DOCBparser.c
  143. libxml/HTMLparser.c libxml/HTMLtree.c libxml/SAX.c libxml/SAX2.c libxml/c14n.c
  144. libxml/catalog.c libxml/chvalid.c libxml/debugXML.c libxml/dict.c
  145. libxml/encoding.c libxml/entities.c libxml/error.c libxml/globals.c
  146. libxml/hash.c libxml/legacy.c libxml/list.c libxml/nanoftp.c libxml/nanohttp.c
  147. libxml/parser.c libxml/parserInternals.c libxml/pattern.c libxml/relaxng.c
  148. libxml/schematron.c libxml/threads.c libxml/tree.c libxml/trionan.c
  149. libxml/uri.c libxml/valid.c libxml/xinclude.c libxml/xlink.c libxml/xmlIO.c
  150. libxml/xmlmemory.c libxml/xmlmodule.c libxml/xmlreader.c libxml/xmlregexp.c
  151. libxml/xmlsave.c libxml/xmlschemas.c libxml/xmlschemastypes.c
  152. libxml/xmlstring.c libxml/xmlunicode.c libxml/xmlwriter.c libxml/xpath.c
  153. libxml/xpointer.c fatal-signal.c copy-file.c)
  154. PREFIX_LIST_ITEMS(GLIBC_SOURCE "gettext-tools/gnulib-lib/")
  155. set(libgettextsrc_SOURCES ${libgettextsrc_SOURCES} ${GLIBC_SOURCE})
  156. set(HEADER_TEMPLATES_PATH "gettext-tools/gnulib-lib")
  157. set(HEADER_TEMPLATES_ABS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${HEADER_TEMPLATES_PATH}")
  158. file(GLOB_RECURSE HEADER_TEMPLATES "${HEADER_TEMPLATES_ABS_PATH}/*.in.h")
  159. list(REMOVE_ITEM HEADER_TEMPLATES "${HEADER_TEMPLATES_ABS_PATH}/stdint.in.h")
  160. list(REMOVE_ITEM HEADER_TEMPLATES "${HEADER_TEMPLATES_ABS_PATH}/wchar.in.h")
  161. foreach(HEADER_TEMPLATE ${HEADER_TEMPLATES})
  162. file(READ ${HEADER_TEMPLATE} HEADER_CONTENT)
  163. string(REPLACE "/* The definition of _GL_ARG_NONNULL is copied here. */" "#include \"arg-nonnull.h\"" HEADER_CONTENT "${HEADER_CONTENT}")
  164. string(REPLACE "/* The definition of _GL_WARN_ON_USE is copied here. */" "#include \"warn-on-use.h\"" HEADER_CONTENT "${HEADER_CONTENT}")
  165. string(REPLACE "/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */" "#include \"c++defs.h\"" HEADER_CONTENT "${HEADER_CONTENT}")
  166. string(REPLACE "@GNULIB_LSTAT@" "1" HEADER_CONTENT "${HEADER_CONTENT}")
  167. string(REPLACE "@GNULIB_MBSINIT@" "1" HEADER_CONTENT "${HEADER_CONTENT}")
  168. string(REPLACE "@GNULIB_SIGACTION@" "1" HEADER_CONTENT "${HEADER_CONTENT}")
  169. string(REPLACE "@GNULIB_SIGPROCMASK@" "1" HEADER_CONTENT "${HEADER_CONTENT}")
  170. string(REPLACE "@GNULIB_STPCPY@" "1" HEADER_CONTENT "${HEADER_CONTENT}")
  171. string(REPLACE "@GNULIB_STPNCPY@" "1" HEADER_CONTENT "${HEADER_CONTENT}")
  172. string(REPLACE "@GNULIB_STRCHRNUL@" "1" HEADER_CONTENT "${HEADER_CONTENT}")
  173. string(REPLACE "@HAVE_ISWCNTRL@" "1" HEADER_CONTENT "${HEADER_CONTENT}")
  174. string(REPLACE "@HAVE_WCTYPE_T@" "1" HEADER_CONTENT "${HEADER_CONTENT}")
  175. string(REPLACE "@PRAGMA_COLUMNS@" "" HEADER_CONTENT "${HEADER_CONTENT}")
  176. string(REGEX REPLACE "^${HEADER_TEMPLATES_ABS_PATH}/" "" HEADER_PATH "${HEADER_TEMPLATE}")
  177. string(REPLACE ".in" "" HEADER_PATH ${HEADER_PATH})
  178. string(REPLACE "_" "/" HEADER_PATH ${HEADER_PATH})
  179. # find_file will create a cache entry for the variable
  180. # SYSTEM_HEADER, so reset it before each call
  181. set(SYSTEM_HEADER "SYSTEM_HEADER-NOTFOUND")
  182. find_file(SYSTEM_HEADER ${HEADER_PATH} PATHS "${LIBICONV_INCLUDE_DIRS}")
  183. if(SYSTEM_HEADER)
  184. # Gnulib uses #include_next to extend system header files,
  185. # but MSVC doesn't support it, so a regular include directive
  186. # with a relative path is used instead
  187. string(REGEX REPLACE ".*/(.*/${HEADER_PATH})" "../\\1"
  188. INCLUDE_PATH "${SYSTEM_HEADER}")
  189. string(REGEX REPLACE "@INCLUDE_NEXT[^@]*@ @NEXT_[^@\n]+@"
  190. "include <${INCLUDE_PATH}>" HEADER_CONTENT "${HEADER_CONTENT}")
  191. endif()
  192. # Default any remaining template variables to 0
  193. string(REGEX REPLACE "@[^@\n]+@" "0" HEADER_CONTENT "${HEADER_CONTENT}")
  194. file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${HEADER_TEMPLATES_PATH}/${HEADER_PATH}" "${HEADER_CONTENT}")
  195. endforeach()
  196. add_library(libgettextsrc ${libgettextsrc_SOURCES})
  197. target_link_libraries(libgettextsrc ${LIBICONV_LIBRARIES})
  198. set(msgmerge_SOURCES
  199. msgmerge.c
  200. msgl-fsearch.c
  201. lang-table.c
  202. )
  203. PREFIX_LIST_ITEMS(msgmerge_SOURCES "gettext-tools/src/")
  204. add_executable(msgmerge ${msgmerge_SOURCES})
  205. target_link_libraries(msgmerge libgettextsrc)
  206. add_dependencies(msgmerge libgettextsrc libintl)
  207. set(msgfmt_SOURCES
  208. msgfmt.c
  209. write-mo.c
  210. write-java.c
  211. write-csharp.c
  212. write-resources.c
  213. write-tcl.c
  214. write-qt.c
  215. write-desktop.c
  216. write-xml.c)
  217. PREFIX_LIST_ITEMS(msgfmt_SOURCES "gettext-tools/src/")
  218. add_executable(msgfmt ${msgfmt_SOURCES} gettext-runtime/intl/hash-string.c)
  219. target_link_libraries(msgfmt libgettextsrc)
  220. add_dependencies(msgfmt libgettextsrc libintl)
  221. set(xgettext_SOURCES
  222. xgettext.c x-c.c x-po.c x-sh.c x-python.c x-lisp.c x-elisp.c x-librep.c
  223. x-scheme.c x-smalltalk.c x-java.c x-csharp.c x-awk.c x-ycp.c x-tcl.c x-perl.c
  224. x-php.c x-rst.c x-lua.c x-javascript.c x-vala.c x-desktop.c)
  225. PREFIX_LIST_ITEMS(xgettext_SOURCES "gettext-tools/src/")
  226. add_executable(xgettext ${xgettext_SOURCES})
  227. target_link_libraries(xgettext libgettextsrc)
  228. add_dependencies(xgettext libgettextsrc libintl)
  229. set_property(TARGET msgmerge msgfmt xgettext libgettextsrc APPEND PROPERTY
  230. INCLUDE_DIRECTORIES
  231. ${CMAKE_CURRENT_SOURCE_DIR}/gettext-runtime/intl
  232. ${CMAKE_CURRENT_SOURCE_DIR}/gettext-tools/libgettextpo
  233. ${CMAKE_CURRENT_SOURCE_DIR}/gettext-tools/gnulib-lib
  234. ${CMAKE_CURRENT_SOURCE_DIR}/gettext-tools/gnulib-lib/libcroco
  235. ${CMAKE_CURRENT_SOURCE_DIR}/build-aux/snippet
  236. ${CMAKE_CURRENT_BINARY_DIR}/gettext-runtime/intl
  237. ${CMAKE_CURRENT_BINARY_DIR}/gettext-tools
  238. ${CMAKE_CURRENT_BINARY_DIR}/gettext-tools/gnulib-lib
  239. ${LIBICONV_INCLUDE_DIRS})
  240. include(GNUInstallDirs)
  241. install(FILES
  242. ${CMAKE_CURRENT_BINARY_DIR}/gettext-runtime/intl/libgnuintl.h
  243. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  244. RENAME libintl.h)
  245. install(TARGETS libintl msgmerge msgfmt xgettext
  246. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  247. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  248. PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  249. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})