LibiconvCMakeLists.txt 4.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. cmake_minimum_required(VERSION 2.8.12)
  2. project(libiconv C)
  3. include_directories(
  4. ${CMAKE_CURRENT_SOURCE_DIR}
  5. ${CMAKE_CURRENT_SOURCE_DIR}/srclib
  6. ${CMAKE_CURRENT_BINARY_DIR}
  7. ${CMAKE_CURRENT_BINARY_DIR}/srclib
  8. ${CMAKE_CURRENT_SOURCE_DIR}/build-aux/snippet)
  9. configure_file(config.h.in config.h)
  10. file(READ "${CMAKE_CURRENT_BINARY_DIR}/config.h" CONFIG_CONTENT)
  11. string(REPLACE "#undef EILSEQ" "" CONFIG_CONTENT "${CONFIG_CONTENT}")
  12. string(REPLACE "#undef HAVE_MBRTOWC" "#define HAVE_MBRTOWC 1" CONFIG_CONTENT "${CONFIG_CONTENT}")
  13. string(REPLACE "#undef HAVE_MBSINIT" "#define HAVE_MBSINIT 1" CONFIG_CONTENT "${CONFIG_CONTENT}")
  14. string(REPLACE "#undef HAVE_WCRTOMB" "#define HAVE_WCRTOMB 1" CONFIG_CONTENT "${CONFIG_CONTENT}")
  15. string(REPLACE "#undef HAVE_DECL___ARGV" "#define HAVE_DECL___ARGV 1" CONFIG_CONTENT "${CONFIG_CONTENT}")
  16. string(REPLACE "#undef HAVE_WORKING_O_NOFOLLOW" "#define HAVE_WORKING_O_NOFOLLOW 0" CONFIG_CONTENT "${CONFIG_CONTENT}")
  17. string(REPLACE "#undef ICONV_CONST" "#define ICONV_CONST const" CONFIG_CONTENT "${CONFIG_CONTENT}")
  18. string(REPLACE "#undef WORDS_LITTLEENDIAN" "#define WORDS_LITTLEENDIAN 1" CONFIG_CONTENT "${CONFIG_CONTENT}")
  19. string(REPLACE "#undef HAVE_DECL_STRERROR_R" "#define HAVE_DECL_STRERROR_R 0" CONFIG_CONTENT "${CONFIG_CONTENT}")
  20. string(REPLACE "#undef mode_t" "#define mode_t int" CONFIG_CONTENT "${CONFIG_CONTENT}")
  21. string(REPLACE "#undef ssize_t" "#include <BaseTsd.h>\n#define ssize_t SSIZE_T" CONFIG_CONTENT "${CONFIG_CONTENT}")
  22. file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/config.h" "${CONFIG_CONTENT}")
  23. set(BROKEN_WCHAR_H 0)
  24. set(HAVE_VISIBILITY 0)
  25. set(HAVE_WCHAR_T 1)
  26. set(ICONV_CONST "const")
  27. set(USE_MBSTATE_T 0)
  28. configure_file(libcharset/include/localcharset.h.build.in localcharset.h)
  29. configure_file(include/iconv.h.build.in iconv.h)
  30. add_definitions(-DLIBDIR -D_CRT_SECURE_NO_WARNINGS)
  31. add_library(libcharset libcharset/lib/localcharset.c)
  32. add_library(libiconv lib/iconv.c)
  33. target_link_libraries(libiconv libcharset)
  34. add_executable(iconv src/iconv.c srclib/progname.c srclib/getprogname.c
  35. srclib/safe-read.c srclib/uniwidth/width.c srclib/error.c srclib/xmalloc.c
  36. srclib/basename-lgpl.c)
  37. target_link_libraries(iconv libiconv)
  38. set(HEADER_TEMPLATES_PATH "srclib")
  39. set(HEADER_TEMPLATES_ABS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${HEADER_TEMPLATES_PATH}")
  40. file(GLOB_RECURSE HEADER_TEMPLATES "${HEADER_TEMPLATES_ABS_PATH}/*.in.h")
  41. list(REMOVE_ITEM HEADER_TEMPLATES "${HEADER_TEMPLATES_ABS_PATH}/stdint.in.h")
  42. list(REMOVE_ITEM HEADER_TEMPLATES "${HEADER_TEMPLATES_ABS_PATH}/wchar.in.h")
  43. foreach(HEADER_TEMPLATE ${HEADER_TEMPLATES})
  44. file(READ ${HEADER_TEMPLATE} HEADER_CONTENT)
  45. string(REPLACE "/* The definition of _GL_ARG_NONNULL is copied here. */" "#include \"arg-nonnull.h\"" HEADER_CONTENT "${HEADER_CONTENT}")
  46. string(REPLACE "/* The definition of _GL_WARN_ON_USE is copied here. */" "#include \"warn-on-use.h\"" HEADER_CONTENT "${HEADER_CONTENT}")
  47. string(REPLACE "/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */" "#include \"c++defs.h\"" HEADER_CONTENT "${HEADER_CONTENT}")
  48. string(REPLACE "@GNULIB_LSTAT@" "1" HEADER_CONTENT "${HEADER_CONTENT}")
  49. string(REPLACE "@GNULIB_SIGACTION@" "1" HEADER_CONTENT "${HEADER_CONTENT}")
  50. string(REPLACE "@GNULIB_SIGPROCMASK@" "1" HEADER_CONTENT "${HEADER_CONTENT}")
  51. string(REPLACE "@HAVE_ISWCNTRL@" "1" HEADER_CONTENT "${HEADER_CONTENT}")
  52. string(REPLACE "@HAVE_WCTYPE_T@" "1" HEADER_CONTENT "${HEADER_CONTENT}")
  53. string(REPLACE "@PRAGMA_COLUMNS@" "" HEADER_CONTENT "${HEADER_CONTENT}")
  54. string(REGEX REPLACE "^${HEADER_TEMPLATES_ABS_PATH}/" "" HEADER_PATH "${HEADER_TEMPLATE}")
  55. string(REPLACE ".in" "" HEADER_PATH ${HEADER_PATH})
  56. string(REPLACE "_" "/" HEADER_PATH ${HEADER_PATH})
  57. # find_file will create a cache entry for the variable
  58. # SYSTEM_HEADER, so reset it before each call
  59. set(SYSTEM_HEADER "SYSTEM_HEADER-NOTFOUND")
  60. find_file(SYSTEM_HEADER ${HEADER_PATH} PATHS "${LIBICONV_INCLUDE_DIRS}")
  61. if(SYSTEM_HEADER)
  62. # Gnulib uses #include_next to extend system header files,
  63. # but MSVC doesn't support it, so a regular include directive
  64. # with a relative path is used instead
  65. string(REGEX REPLACE ".*/(.*/${HEADER_PATH})" "../\\1"
  66. INCLUDE_PATH "${SYSTEM_HEADER}")
  67. string(REGEX REPLACE "@INCLUDE_NEXT[^@]*@ @NEXT_[^@\n]+@"
  68. "include <${INCLUDE_PATH}>" HEADER_CONTENT "${HEADER_CONTENT}")
  69. endif()
  70. # Default any remaining template variables to 0
  71. string(REGEX REPLACE "@[^@\n]+@" "0" HEADER_CONTENT "${HEADER_CONTENT}")
  72. file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${HEADER_TEMPLATES_PATH}/${HEADER_PATH}" "${HEADER_CONTENT}")
  73. endforeach()
  74. include(GNUInstallDirs)
  75. install(FILES
  76. ${CMAKE_CURRENT_BINARY_DIR}/iconv.h
  77. ${CMAKE_CURRENT_BINARY_DIR}/localcharset.h
  78. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
  79. install(TARGETS libcharset libiconv iconv
  80. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
  81. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  82. PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  83. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})