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.

228 lines
8.2KB

  1. project (uirc3 C)
  2. cmake_minimum_required (VERSION 2.8.11)
  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
  10. "${CMAKE_C_FLAGS} -std=c99 -Wall -Wextra -Wno-unused-function")
  11. endif ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUC)
  12. # Version
  13. set (project_version "0.9.2")
  14. # Try to append commit ID if it follows a version tag. It might be nicer if
  15. # we could also detect dirty worktrees but that's very hard to get right.
  16. find_package (Git)
  17. set (git_head "${PROJECT_SOURCE_DIR}/.git/HEAD")
  18. if (GIT_FOUND AND EXISTS ${git_head})
  19. configure_file (${git_head} git-head.tag COPYONLY)
  20. execute_process (COMMAND ${GIT_EXECUTABLE} describe --tags --match v*
  21. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  22. RESULT_VARIABLE git_describe_result
  23. OUTPUT_VARIABLE git_describe OUTPUT_STRIP_TRAILING_WHITESPACE)
  24. if (NOT git_describe_result)
  25. string (REGEX REPLACE "^v" "" project_version "${git_describe}")
  26. endif (NOT git_describe_result)
  27. endif (GIT_FOUND AND EXISTS ${git_head})
  28. # Dashes make filenames confusing and upset packaging software
  29. string (REPLACE "-" "+" project_version_safe "${project_version}")
  30. # Dependencies
  31. set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/liberty/cmake)
  32. include (AddThreads)
  33. find_package (Curses)
  34. find_package (PkgConfig REQUIRED)
  35. pkg_check_modules (dependencies REQUIRED libssl libcrypto libffi)
  36. pkg_check_modules (ncursesw ncursesw)
  37. if ("${CMAKE_SYSTEM_NAME}" MATCHES "BSD")
  38. include_directories (/usr/local/include)
  39. link_directories (/usr/local/lib)
  40. # Need this for SIGWINCH in FreeBSD and OpenBSD respectively;
  41. # our POSIX version macros make it undefined
  42. add_definitions (-D__BSD_VISIBLE=1 -D_BSD_SOURCE=1)
  43. endif ("${CMAKE_SYSTEM_NAME}" MATCHES "BSD")
  44. list (APPEND project_libraries ${dependencies_LIBRARIES})
  45. include_directories (${dependencies_INCLUDE_DIRS})
  46. link_directories (${dependencies_LIBRARY_DIRS})
  47. # FIXME: other Lua versions may be acceptable, don't know yet
  48. pkg_search_module (lua lua53 lua5.3 lua-5.3 lua>=5.3)
  49. option (WITH_LUA "Enable experimental support for Lua plugins" ${lua_FOUND})
  50. if (WITH_LUA)
  51. if (NOT lua_FOUND)
  52. message (FATAL_ERROR "Lua library not found")
  53. endif (NOT lua_FOUND)
  54. list (APPEND project_libraries ${lua_LIBRARIES})
  55. include_directories (${lua_INCLUDE_DIRS})
  56. link_directories (${lua_LIBRARY_DIRS})
  57. endif (WITH_LUA)
  58. # -lrt is only for glibc < 2.17
  59. # -liconv may or may not be a part of libc
  60. foreach (extra iconv rt)
  61. find_library (extra_lib_${extra} ${extra})
  62. if (extra_lib_${extra})
  63. list (APPEND project_libraries ${extra})
  64. endif (extra_lib_${extra})
  65. endforeach (extra)
  66. if (ncursesw_FOUND)
  67. list (APPEND project_libraries ${ncursesw_LIBRARIES})
  68. include_directories (${ncursesw_INCLUDE_DIRS})
  69. elseif (CURSES_FOUND)
  70. list (APPEND project_libraries ${CURSES_LIBRARY})
  71. include_directories (${CURSES_INCLUDE_DIR})
  72. else (CURSES_FOUND)
  73. message (SEND_ERROR "Curses not found")
  74. endif (ncursesw_FOUND)
  75. if ((WANT_READLINE AND WANT_LIBEDIT) OR (NOT WANT_READLINE AND NOT WANT_LIBEDIT))
  76. message (SEND_ERROR "You have to choose either GNU Readline or libedit")
  77. elseif (WANT_READLINE)
  78. # OpenBSD's default readline is too old
  79. if ("${CMAKE_SYSTEM_NAME}" MATCHES "OpenBSD")
  80. include_directories (/usr/local/include/ereadline)
  81. list (APPEND project_libraries ereadline)
  82. else ("${CMAKE_SYSTEM_NAME}" MATCHES "OpenBSD")
  83. list (APPEND project_libraries readline)
  84. endif ("${CMAKE_SYSTEM_NAME}" MATCHES "OpenBSD")
  85. elseif (WANT_LIBEDIT)
  86. pkg_check_modules (libedit REQUIRED libedit)
  87. list (APPEND project_libraries ${libedit_LIBRARIES})
  88. include_directories (${libedit_INCLUDE_DIRS})
  89. endif ((WANT_READLINE AND WANT_LIBEDIT) OR (NOT WANT_READLINE AND NOT WANT_LIBEDIT))
  90. # Generate a configuration file
  91. set (HAVE_READLINE "${WANT_READLINE}")
  92. set (HAVE_EDITLINE "${WANT_LIBEDIT}")
  93. set (HAVE_LUA "${WITH_LUA}")
  94. include (GNUInstallDirs)
  95. # ZyklonB is currently an odd duck but degesch follows normal XDG rules
  96. set (zyklonb_plugin_dir ${CMAKE_INSTALL_LIBDIR}/zyklonb/plugins)
  97. configure_file (${PROJECT_SOURCE_DIR}/config.h.in ${PROJECT_BINARY_DIR}/config.h)
  98. include_directories (${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR})
  99. # Project source files
  100. set (common_sources)
  101. set (common_headers ${PROJECT_BINARY_DIR}/config.h)
  102. add_custom_command (OUTPUT kike-replies.c kike.msg
  103. COMMAND ${PROJECT_SOURCE_DIR}/kike-gen-replies.sh
  104. > kike-replies.c < ${PROJECT_SOURCE_DIR}/kike-replies
  105. DEPENDS ${PROJECT_SOURCE_DIR}/kike-replies
  106. COMMENT "Generating files from the list of server numerics")
  107. set_source_files_properties (${PROJECT_BINARY_DIR}/kike-replies.c
  108. PROPERTIES HEADER_FILE_ONLY TRUE)
  109. # Build
  110. add_executable (zyklonb zyklonb.c ${common_sources} ${common_headers})
  111. target_link_libraries (zyklonb ${project_libraries})
  112. add_threads (zyklonb)
  113. add_executable (degesch degesch.c kike-replies.c
  114. ${common_sources} ${common_headers})
  115. target_link_libraries (degesch ${project_libraries})
  116. add_threads (degesch)
  117. add_executable (kike kike.c kike-replies.c ${common_sources} ${common_headers})
  118. target_link_libraries (kike ${project_libraries})
  119. add_threads (kike)
  120. # Tests
  121. function (make_tests_for target_name)
  122. get_target_property (sources ${target_name} SOURCES)
  123. get_target_property (libraries ${target_name} LINK_LIBRARIES)
  124. get_target_property (options ${target_name} COMPILE_OPTIONS)
  125. set (test test-${target_name})
  126. add_executable (${test} ${sources})
  127. target_link_libraries (${test} ${libraries})
  128. set_target_properties (${test} PROPERTIES
  129. COMPILE_DEFINITIONS TESTING
  130. COMPILE_OPTIONS "${options}")
  131. add_test (NAME ${test} COMMAND ${test})
  132. endfunction (make_tests_for)
  133. include (CTest)
  134. if (BUILD_TESTING)
  135. make_tests_for (degesch)
  136. endif (BUILD_TESTING)
  137. # Various clang-based diagnostics, loads of fake positives and spam
  138. file (GLOB clang_tidy_sources *.c)
  139. set (clang_tidy_checks misc-* readability-*
  140. -readability-braces-around-statements
  141. -readability-named-parameter)
  142. string (REPLACE ";" "," clang_tidy_checks "${clang_tidy_checks}")
  143. set (CMAKE_EXPORT_COMPILE_COMMANDS ON)
  144. add_custom_target (clang-tidy
  145. COMMAND clang-tidy -p ${PROJECT_BINARY_DIR} -checks=${clang_tidy_checks}
  146. ${clang_tidy_sources} 1>&2
  147. USES_TERMINAL
  148. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
  149. # Installation
  150. install (TARGETS zyklonb degesch kike DESTINATION ${CMAKE_INSTALL_BINDIR})
  151. install (FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR})
  152. install (DIRECTORY plugins/zyklonb/
  153. DESTINATION ${zyklonb_plugin_dir} USE_SOURCE_PERMISSIONS)
  154. install (DIRECTORY plugins/degesch/
  155. DESTINATION ${CMAKE_INSTALL_DATADIR}/degesch/plugins)
  156. # Generate documentation from program help
  157. find_program (HELP2MAN_EXECUTABLE help2man)
  158. if (NOT HELP2MAN_EXECUTABLE)
  159. message (FATAL_ERROR "help2man not found")
  160. endif (NOT HELP2MAN_EXECUTABLE)
  161. foreach (page zyklonb degesch kike)
  162. set (page_output "${PROJECT_BINARY_DIR}/${page}.1")
  163. list (APPEND project_MAN_PAGES "${page_output}")
  164. add_custom_command (OUTPUT ${page_output}
  165. COMMAND ${HELP2MAN_EXECUTABLE} -N
  166. "${PROJECT_BINARY_DIR}/${page}" -o ${page_output}
  167. DEPENDS ${page}
  168. COMMENT "Generating man page for ${page}" VERBATIM)
  169. endforeach (page)
  170. add_custom_target (docs ALL DEPENDS ${project_MAN_PAGES})
  171. foreach (page ${project_MAN_PAGES})
  172. string (REGEX MATCH "\\.([0-9])" manpage_suffix "${page}")
  173. install (FILES "${page}"
  174. DESTINATION "${CMAKE_INSTALL_MANDIR}/man${CMAKE_MATCH_1}")
  175. endforeach (page)
  176. # CPack
  177. set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Experimental IRC client, daemon and bot")
  178. set (CPACK_PACKAGE_VERSION "${project_version_safe}")
  179. set (CPACK_PACKAGE_VENDOR "Premysl Janouch")
  180. set (CPACK_PACKAGE_CONTACT "Přemysl Janouch <p.janouch@gmail.com>")
  181. set (CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
  182. set (CPACK_GENERATOR "TGZ;ZIP")
  183. set (CPACK_PACKAGE_FILE_NAME
  184. "${PROJECT_NAME}-${project_version_safe}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
  185. set (CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}-${project_version_safe}")
  186. set (CPACK_SOURCE_GENERATOR "TGZ;ZIP")
  187. set (CPACK_SOURCE_IGNORE_FILES "/\\\\.git;/build;/CMakeLists.txt.user")
  188. set (CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${project_version_safe}")
  189. set (CPACK_SET_DESTDIR TRUE)
  190. include (CPack)