A shell for running JSON-RPC 2.0 queries
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.
 
 
 
 

138 lines
4.8 KiB

  1. cmake_minimum_required (VERSION 3.0)
  2. project (json-rpc-shell VERSION 1.1.0 LANGUAGES C)
  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 (CMAKE_C_FLAGS
  10. "${CMAKE_C_FLAGS} -std=c99 -Wall -Wextra -Wno-unused-function")
  11. endif ()
  12. # For custom modules
  13. set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
  14. # Dependencies
  15. find_package (Curses)
  16. find_package (PkgConfig REQUIRED)
  17. pkg_check_modules (dependencies REQUIRED libcurl jansson)
  18. # Note that cURL can link to a different version of libssl than we do,
  19. # in which case the results are undefined
  20. pkg_check_modules (libssl REQUIRED libssl libcrypto)
  21. find_package (LibEV REQUIRED)
  22. pkg_check_modules (ncursesw ncursesw)
  23. set (project_libraries ${dependencies_LIBRARIES}
  24. ${libssl_LIBRARIES} ${LIBEV_LIBRARIES})
  25. include_directories (${dependencies_INCLUDE_DIRS}
  26. ${libssl_INCLUDE_DIRS} ${LIBEV_INCLUDE_DIRS})
  27. # -liconv may or may not be a part of libc
  28. find_library (iconv_LIBRARIES iconv)
  29. if (iconv_LIBRARIES)
  30. list (APPEND project_libraries ${iconv_LIBRARIES})
  31. endif ()
  32. if ("${CMAKE_SYSTEM_NAME}" MATCHES "BSD")
  33. # Need this for SIGWINCH in FreeBSD and OpenBSD respectively;
  34. # our POSIX version macros make it undefined
  35. add_definitions (-D__BSD_VISIBLE=1 -D_BSD_SOURCE=1)
  36. endif ()
  37. if (ncursesw_FOUND)
  38. list (APPEND project_libraries ${ncursesw_LIBRARIES})
  39. include_directories (${ncursesw_INCLUDE_DIRS})
  40. elseif (CURSES_FOUND)
  41. list (APPEND project_libraries ${CURSES_LIBRARY})
  42. include_directories (${CURSES_INCLUDE_DIR})
  43. else ()
  44. message (SEND_ERROR "Curses not found")
  45. endif ()
  46. if ((WANT_READLINE AND WANT_LIBEDIT) OR (NOT WANT_READLINE AND NOT WANT_LIBEDIT))
  47. message (SEND_ERROR "You have to choose either GNU Readline or libedit")
  48. elseif (WANT_READLINE)
  49. # OpenBSD's default readline is too old
  50. if ("${CMAKE_SYSTEM_NAME}" MATCHES "OpenBSD")
  51. include_directories (${OPENBSD_LOCALBASE}/include/ereadline)
  52. list (APPEND project_libraries ereadline)
  53. else ()
  54. list (APPEND project_libraries readline)
  55. endif ()
  56. elseif (WANT_LIBEDIT)
  57. pkg_check_modules (libedit REQUIRED libedit)
  58. list (APPEND project_libraries ${libedit_LIBRARIES})
  59. include_directories (${libedit_INCLUDE_DIRS})
  60. endif ()
  61. # Generate a configuration file
  62. set (HAVE_READLINE "${WANT_READLINE}")
  63. set (HAVE_EDITLINE "${WANT_LIBEDIT}")
  64. configure_file (${PROJECT_SOURCE_DIR}/config.h.in ${PROJECT_BINARY_DIR}/config.h)
  65. include_directories (${PROJECT_BINARY_DIR})
  66. # Build the main executable and link it
  67. add_executable (${PROJECT_NAME} ${PROJECT_NAME}.c http-parser/http_parser.c)
  68. target_link_libraries (${PROJECT_NAME} ${project_libraries})
  69. # Development tools
  70. find_package (LibMagic)
  71. if (LIBMAGIC_FOUND)
  72. include_directories (${LIBMAGIC_INCLUDE_DIRS})
  73. add_executable (json-rpc-test-server
  74. json-rpc-test-server.c http-parser/http_parser.c)
  75. target_link_libraries (json-rpc-test-server
  76. ${project_libraries} ${LIBMAGIC_LIBRARIES})
  77. endif ()
  78. # The files to be installed
  79. include (GNUInstallDirs)
  80. install (TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
  81. install (PROGRAMS json-format.pl DESTINATION ${CMAKE_INSTALL_BINDIR})
  82. install (FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR})
  83. # Generate documentation from text markup
  84. find_program (ASCIIDOCTOR_EXECUTABLE asciidoctor)
  85. if (NOT ASCIIDOCTOR_EXECUTABLE)
  86. message (FATAL_ERROR "asciidoctor not found")
  87. endif ()
  88. foreach (page ${PROJECT_NAME})
  89. set (page_output "${PROJECT_BINARY_DIR}/${page}.1")
  90. list (APPEND project_MAN_PAGES "${page_output}")
  91. add_custom_command (OUTPUT ${page_output}
  92. COMMAND ${ASCIIDOCTOR_EXECUTABLE} -b manpage
  93. -a release-version=${PROJECT_VERSION}
  94. "${PROJECT_SOURCE_DIR}/${page}.adoc"
  95. -o "${page_output}"
  96. DEPENDS ${page}.adoc
  97. COMMENT "Generating man page for ${page}" VERBATIM)
  98. endforeach ()
  99. add_custom_target (docs ALL DEPENDS ${project_MAN_PAGES})
  100. foreach (page ${project_MAN_PAGES})
  101. string (REGEX MATCH "\\.([0-9])$" manpage_suffix "${page}")
  102. install (FILES "${page}"
  103. DESTINATION "${CMAKE_INSTALL_MANDIR}/man${CMAKE_MATCH_1}")
  104. endforeach ()
  105. # CPack
  106. set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "A shell for JSON-RPC 2.0")
  107. set (CPACK_PACKAGE_VENDOR "Premysl Eric Janouch")
  108. set (CPACK_PACKAGE_CONTACT "Přemysl Eric Janouch <p@janouch.name>")
  109. set (CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
  110. set (CPACK_GENERATOR "TGZ;ZIP")
  111. set (CPACK_PACKAGE_FILE_NAME
  112. "${PROJECT_NAME}-${PROJECT_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
  113. set (CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}-${PROJECT_VERSION}")
  114. set (CPACK_SOURCE_GENERATOR "TGZ;ZIP")
  115. set (CPACK_SOURCE_IGNORE_FILES "/\\\\.git;/build;/CMakeLists.txt.user")
  116. set (CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}")
  117. include (CPack)