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.

CMakeLists.txt 9.1KB

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