Experimental IRC client, daemon and bot
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

188 lines
6.7KB

  1. project (uirc3 C)
  2. cmake_minimum_required (VERSION 2.8.5)
  3. # Options
  4. option (WANT_READLINE "Use GNU Readline for the UI (better)" ON)
  5. option (WANT_LIBEDIT "Use BSD libedit for the UI" OFF)
  6. # Moar warnings
  7. if ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUC)
  8. # -Wunused-function is pretty annoying here, as everything is static
  9. set (CMAKE_C_FLAGS "-std=c99 -Wall -Wextra -Wno-unused-function")
  10. endif ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUC)
  11. # Version
  12. set (project_VERSION_MAJOR "0")
  13. set (project_VERSION_MINOR "9")
  14. set (project_VERSION_PATCH "1")
  15. set (project_VERSION "${project_VERSION_MAJOR}")
  16. set (project_VERSION "${project_VERSION}.${project_VERSION_MINOR}")
  17. set (project_VERSION "${project_VERSION}.${project_VERSION_PATCH}")
  18. # Dependencies
  19. find_package (Curses)
  20. find_package (PkgConfig REQUIRED)
  21. pkg_check_modules (libssl REQUIRED libssl libcrypto)
  22. pkg_check_modules (ncursesw ncursesw)
  23. if ("${CMAKE_SYSTEM_NAME}" MATCHES "BSD")
  24. include_directories(/usr/local/include)
  25. link_directories(/usr/local/lib)
  26. # Need this for SIGWINCH in FreeBSD and OpenBSD respectively;
  27. # our POSIX version macros make it undefined
  28. add_definitions (-D__BSD_VISIBLE=1 -D_BSD_SOURCE=1)
  29. endif ("${CMAKE_SYSTEM_NAME}" MATCHES "BSD")
  30. list (APPEND project_libraries ${libssl_LIBRARIES})
  31. include_directories (${libssl_INCLUDE_DIRS})
  32. link_directories (${libssl_LIBRARY_DIRS})
  33. # FIXME: other Lua versions may be acceptable, don't know yet
  34. pkg_search_module (lua lua5.3 lua-5.3 lua>=5.3)
  35. option (WITH_LUA "Enable experimental support for Lua plugins" ${lua_FOUND})
  36. if (WITH_LUA)
  37. if (NOT lua_FOUND)
  38. message (FATAL_ERROR "Lua library not found")
  39. endif (NOT lua_FOUND)
  40. list (APPEND project_libraries ${lua_LIBRARIES})
  41. include_directories (${lua_INCLUDE_DIRS})
  42. link_directories (${lua_LIBRARY_DIRS})
  43. endif (WITH_LUA)
  44. # -lpthread is only there for debugging (gdb & errno)
  45. # -lrt is only for glibc < 2.17
  46. # -liconv may or may not be a part of libc
  47. foreach (extra iconv rt pthread)
  48. find_library (extra_lib_${extra} ${extra})
  49. if (extra_lib_${extra})
  50. list (APPEND project_libraries ${extra})
  51. endif (extra_lib_${extra})
  52. endforeach (extra)
  53. if (ncursesw_FOUND)
  54. list (APPEND project_libraries ${ncursesw_LIBRARIES})
  55. include_directories (${ncursesw_INCLUDE_DIRS})
  56. elseif (CURSES_FOUND)
  57. list (APPEND project_libraries ${CURSES_LIBRARY})
  58. include_directories (${CURSES_INCLUDE_DIR})
  59. else (CURSES_FOUND)
  60. message (SEND_ERROR "Curses not found")
  61. endif (ncursesw_FOUND)
  62. if ((WANT_READLINE AND WANT_LIBEDIT) OR (NOT WANT_READLINE AND NOT WANT_LIBEDIT))
  63. message (SEND_ERROR "You have to choose either GNU Readline or libedit")
  64. elseif (WANT_READLINE)
  65. # OpenBSD's default readline is too old
  66. if ("${CMAKE_SYSTEM_NAME}" MATCHES "OpenBSD")
  67. include_directories (/usr/local/include/ereadline)
  68. list (APPEND project_libraries ereadline)
  69. else ("${CMAKE_SYSTEM_NAME}" MATCHES "OpenBSD")
  70. list (APPEND project_libraries readline)
  71. endif ("${CMAKE_SYSTEM_NAME}" MATCHES "OpenBSD")
  72. elseif (WANT_LIBEDIT)
  73. pkg_check_modules (libedit REQUIRED libedit)
  74. list (APPEND project_libraries ${libedit_LIBRARIES})
  75. include_directories (${libedit_INCLUDE_DIRS})
  76. endif ((WANT_READLINE AND WANT_LIBEDIT) OR (NOT WANT_READLINE AND NOT WANT_LIBEDIT))
  77. # Generate a configuration file
  78. set (HAVE_READLINE "${WANT_READLINE}")
  79. set (HAVE_EDITLINE "${WANT_LIBEDIT}")
  80. set (HAVE_LUA "${WITH_LUA}")
  81. include (GNUInstallDirs)
  82. set (plugin_dir ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME})
  83. configure_file (${PROJECT_SOURCE_DIR}/config.h.in ${PROJECT_BINARY_DIR}/config.h)
  84. include_directories (${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR})
  85. # Project source files
  86. set (common_sources)
  87. set (common_headers ${PROJECT_BINARY_DIR}/config.h)
  88. add_custom_command (OUTPUT kike-replies.c kike.msg
  89. COMMAND ${PROJECT_SOURCE_DIR}/kike-gen-replies.sh
  90. > kike-replies.c < ${PROJECT_SOURCE_DIR}/kike-replies
  91. DEPENDS ${PROJECT_SOURCE_DIR}/kike-replies
  92. COMMENT "Generating files from the list of server numerics")
  93. set_source_files_properties (${PROJECT_BINARY_DIR}/kike-replies.c
  94. PROPERTIES HEADER_FILE_ONLY TRUE)
  95. # Build
  96. add_executable (zyklonb zyklonb.c ${common_sources} ${common_headers})
  97. target_link_libraries (zyklonb ${project_libraries})
  98. add_executable (degesch degesch.c kike-replies.c
  99. ${common_sources} ${common_headers})
  100. target_link_libraries (degesch ${project_libraries})
  101. add_executable (kike kike.c kike-replies.c ${common_sources} ${common_headers})
  102. target_link_libraries (kike ${project_libraries})
  103. # Various clang-based diagnostics, loads of fake positives and spam
  104. file (GLOB clang_tidy_sources *.c)
  105. set (clang_tidy_checks misc-* readability-*
  106. -readability-braces-around-statements
  107. -readability-named-parameter)
  108. string (REPLACE ";" "," clang_tidy_checks "${clang_tidy_checks}")
  109. set (CMAKE_EXPORT_COMPILE_COMMANDS ON)
  110. add_custom_target (clang-tidy
  111. COMMAND clang-tidy -p ${PROJECT_BINARY_DIR} -checks=${clang_tidy_checks}
  112. ${clang_tidy_sources} 1>&2
  113. USES_TERMINAL
  114. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
  115. # Installation
  116. install (TARGETS zyklonb degesch kike DESTINATION ${CMAKE_INSTALL_BINDIR})
  117. install (FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR})
  118. foreach (plugin coin eval script youtube ${plugins})
  119. install (FILES plugins/${plugin} DESTINATION ${plugin_dir})
  120. endforeach (plugin)
  121. # Generate documentation from program help
  122. find_program (HELP2MAN_EXECUTABLE help2man)
  123. if (NOT HELP2MAN_EXECUTABLE)
  124. message (FATAL_ERROR "help2man not found")
  125. endif (NOT HELP2MAN_EXECUTABLE)
  126. foreach (page zyklonb degesch kike)
  127. set (page_output "${PROJECT_BINARY_DIR}/${page}.1")
  128. list (APPEND project_MAN_PAGES "${page_output}")
  129. add_custom_command (OUTPUT ${page_output}
  130. COMMAND ${HELP2MAN_EXECUTABLE} -N
  131. "${PROJECT_BINARY_DIR}/${page}" -o ${page_output}
  132. DEPENDS ${page}
  133. COMMENT "Generating man page for ${page}" VERBATIM)
  134. endforeach (page)
  135. add_custom_target (docs ALL DEPENDS ${project_MAN_PAGES})
  136. foreach (page ${project_MAN_PAGES})
  137. string (REGEX MATCH "\\.([0-9])" manpage_suffix "${page}")
  138. install (FILES "${page}"
  139. DESTINATION "${CMAKE_INSTALL_MANDIR}/man${CMAKE_MATCH_1}")
  140. endforeach (page)
  141. # CPack
  142. set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Experimental IRC client, daemon and bot")
  143. set (CPACK_PACKAGE_VERSION ${project_VERSION})
  144. set (CPACK_PACKAGE_VENDOR "Premysl Janouch")
  145. set (CPACK_PACKAGE_CONTACT "Přemysl Janouch <p.janouch@gmail.com>")
  146. set (CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
  147. set (CPACK_GENERATOR "TGZ;ZIP")
  148. set (CPACK_PACKAGE_FILE_NAME
  149. "${PROJECT_NAME}-${project_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
  150. set (CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}-${project_VERSION}")
  151. set (CPACK_SOURCE_GENERATOR "TGZ;ZIP")
  152. set (CPACK_SOURCE_IGNORE_FILES "/\\\\.git;/build;/CMakeLists.txt.user")
  153. set (CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${project_VERSION}")
  154. set (CPACK_SET_DESTDIR TRUE)
  155. include (CPack)