C++ wrapper for the Mastodon API
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 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. cmake_minimum_required (VERSION 3.6)
  2. project (mastodon-cpp
  3. VERSION 0.20.0
  4. LANGUAGES CXX
  5. )
  6. include(GNUInstallDirs)
  7. find_package(PkgConfig REQUIRED)
  8. find_package(PkgConfig REQUIRED)
  9. pkg_check_modules(CURLPP REQUIRED curlpp)
  10. if(NOT WITHOUT_EASY)
  11. pkg_check_modules(JSONCPP REQUIRED jsoncpp)
  12. endif()
  13. set(CMAKE_CXX_STANDARD 14)
  14. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  15. set(CMAKE_CXX_EXTENSIONS OFF)
  16. set(CMAKE_CXX_FLAGS_DEBUG
  17. "${CMAKE_CXX_FLAGS_DEBUG} -Wall -pedantic -Wextra -g -Og")
  18. # Do not complain about compatibility-wrapper
  19. if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
  20. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
  21. endif()
  22. include_directories(${PROJECT_SOURCE_DIR}/src)
  23. include_directories(${PROJECT_BINARY_DIR})
  24. include_directories(${CURL_INCLUDE_DIRS})
  25. include_directories(${CURLPP_INCLUDE_DIRS})
  26. include_directories(${JSONCPP_INCLUDE_DIRS})
  27. link_directories(${CURL_LIBRARY_DIRS})
  28. link_directories(${CURLPP_LIBRARY_DIRS})
  29. link_directories(${JSONCPP_LIBRARY_DIRS})
  30. # Write version in header
  31. configure_file (
  32. "${PROJECT_SOURCE_DIR}/src/version.hpp.in"
  33. "${PROJECT_BINARY_DIR}/version.hpp"
  34. )
  35. # Announce that we are compiling mastodon-cpp (used to figure out where the
  36. # headers are)
  37. add_definitions(-DMASTODON_CPP=1)
  38. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  39. add_definitions(-DDEBUG=1)
  40. endif()
  41. if(WITHOUT_EASY)
  42. add_definitions(-DWITHOUT_EASY=1)
  43. endif()
  44. # Compile library
  45. if(WITHOUT_EASY)
  46. file(GLOB sources src/*.cpp src/api/*.cpp)
  47. else()
  48. file(GLOB sources src/*.cpp src/api/*.cpp
  49. src/easy/*.cpp src/easy/entities/*.cpp)
  50. endif()
  51. add_library(mastodon-cpp SHARED ${sources})
  52. set_target_properties(mastodon-cpp PROPERTIES
  53. VERSION ${PROJECT_VERSION}
  54. SOVERSION ${mastodon-cpp_VERSION_MAJOR}
  55. )
  56. if(WITHOUT_EASY)
  57. target_link_libraries(mastodon-cpp ${CURLPP_LIBRARIES})
  58. else()
  59. target_link_libraries(mastodon-cpp ${CURLPP_LIBRARIES} ${JSONCPP_LIBRARIES})
  60. endif()
  61. if(WITH_STATIC)
  62. add_library(mastodon-cpp_static STATIC ${sources})
  63. set_target_properties(mastodon-cpp_static PROPERTIES
  64. OUTPUT_NAME mastodon-cpp)
  65. endif()
  66. # Compile examples
  67. if(WITH_EXAMPLES)
  68. file(GLOB sources_examples examples/*.cpp)
  69. foreach(src ${sources_examples})
  70. get_filename_component(bin ${src} NAME_WE)
  71. add_executable(${bin} ${src})
  72. target_link_libraries(${bin} pthread ${JSONCPP_LIBRARIES} mastodon-cpp)
  73. endforeach()
  74. endif()
  75. # Compile tests
  76. if(WITH_TESTS)
  77. include(CTest)
  78. file(GLOB sources_tests tests/test_*.cpp)
  79. foreach(src ${sources_tests})
  80. get_filename_component(bin ${src} NAME_WE)
  81. add_executable(${bin} ${src})
  82. target_link_libraries(${bin} mastodon-cpp)
  83. add_test(${bin} ${bin})
  84. endforeach()
  85. endif()
  86. # Install library and header files
  87. install(TARGETS mastodon-cpp LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
  88. if(WITH_STATIC)
  89. install(TARGETS mastodon-cpp_static LIBRARY
  90. DESTINATION ${CMAKE_INSTALL_LIBDIR})
  91. endif()
  92. install(FILES src/mastodon-cpp.hpp
  93. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mastodon-cpp)
  94. if(NOT WITHOUT_EASY)
  95. file(GLOB easy_header src/easy/*.hpp)
  96. install(FILES ${easy_header}
  97. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mastodon-cpp/easy)
  98. file(GLOB easy_entities_header src/easy/entities/*.hpp)
  99. install(FILES ${easy_entities_header}
  100. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mastodon-cpp/easy/entities)
  101. endif()
  102. # Compile & install documentation
  103. if(WITH_DOC)
  104. execute_process(COMMAND ./build_doc.sh
  105. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
  106. install(DIRECTORY ${PROJECT_SOURCE_DIR}/doc/html
  107. DESTINATION ${CMAKE_INSTALL_DOCDIR}/mastodon-cpp-${PROJECT_VERSION})
  108. file(GLOB examples examples/example*.cpp)
  109. install(FILES ${examples}
  110. DESTINATION ${CMAKE_INSTALL_DOCDIR}/mastodon-cpp-${PROJECT_VERSION}/examples)
  111. endif()
  112. # Packages
  113. set(CPACK_PACKAGE_NAME ${CMAKE_PROJECT_NAME})
  114. set(CPACK_PACKAGE_VERSION_MAJOR ${mastodon-cpp_VERSION_MAJOR})
  115. set(CPACK_PACKAGE_VERSION_MINOR ${mastodon-cpp_VERSION_MINOR})
  116. set(CPACK_PACKAGE_VERSION_PATCH ${mastodon-cpp_VERSION_PATCH})
  117. set(CPACK_PACKAGE_VERSION ${mastodon-cpp_VERSION})
  118. set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "C++ wrapper for the Mastodon API")
  119. set(CPACK_PACKAGE_CONTACT "tastytea <tastytea@tastytea.de>")
  120. set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
  121. set(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README.md")
  122. list(APPEND CPACK_SOURCE_IGNORE_FILES "/\\\\.git"
  123. "/.gitignore"
  124. "/build/"
  125. "/doc/"
  126. "\\\\.sublime-"
  127. "/update_doc.sh"
  128. "/.drone.yml"
  129. "/ISSUE_TEMPLATE.md$")
  130. execute_process(COMMAND uname -m
  131. OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE
  132. OUTPUT_STRIP_TRAILING_WHITESPACE)
  133. set(CPACK_PACKAGE_FILE_NAME
  134. "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}_${CPACK_PACKAGE_ARCHITECTURE}")
  135. set(CPACK_GENERATOR "TGZ")
  136. set(CPACK_SOURCE_GENERATOR "TGZ")
  137. if (WITH_DEB)
  138. set(CPACK_PACKAGE_NAME "lib${CMAKE_PROJECT_NAME}")
  139. set(CPACK_GENERATOR "DEB")
  140. set(CPACK_SOURCE_GENERATOR "DEB")
  141. set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://schlomp.space/tastytea/mastodon-cpp")
  142. set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
  143. execute_process(COMMAND dpkg --print-architecture
  144. OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
  145. OUTPUT_STRIP_TRAILING_WHITESPACE)
  146. set(CPACK_PACKAGE_FILE_NAME
  147. "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}-0_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
  148. set(CPACK_SOURCE_PACKAGE_FILE_NAME
  149. "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}-0_src")
  150. endif()
  151. if (WITH_RPM)
  152. set(CPACK_PACKAGE_NAME "lib${CMAKE_PROJECT_NAME}")
  153. set(CPACK_GENERATOR "RPM")
  154. set(CPACK_SOURCE_GENERATOR "RPM")
  155. set(CPACK_RPM_PACKAGE_LICENSE "GPL-3")
  156. set(CPACK_RPM_PACKAGE_URL "https://schlomp.space/tastytea/mastodon-cpp")
  157. set(CPACK_RPM_PACKAGE_REQUIRES "curlpp >= 0.8.1 jsoncpp, >= 1.7.4")
  158. set(CPACK_PACKAGE_FILE_NAME
  159. "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-0.${CPACK_PACKAGE_ARCHITECTURE}")
  160. set(CPACK_SOURCE_PACKAGE_FILE_NAME
  161. "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-0.src")
  162. endif()
  163. include(CPack)