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 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. cmake_minimum_required (VERSION 3.6)
  2. project (mastodon-cpp
  3. VERSION 0.105.1
  4. LANGUAGES CXX
  5. )
  6. set(WITH_EASY "YES" CACHE STRING "WITH_EASY defaults to \"YES\"")
  7. set(WITH_EXAMPLES "NO" CACHE STRING "WITH_EXAMPLES defaults to \"NO\"")
  8. set(WITH_TESTS "NO" CACHE STRING "WITH_TESTS defaults to \"NO\"")
  9. set(WITH_DOC "YES" CACHE STRING "WITH_DOC defaults to \"YES\"")
  10. set(WITH_DEB "NO" CACHE STRING "WITH_DEB defaults to \"NO\"")
  11. set(WITH_RPM "NO" CACHE STRING "WITH_RPM defaults to \"NO\"")
  12. include(GNUInstallDirs)
  13. find_package(PkgConfig REQUIRED)
  14. find_package(PkgConfig REQUIRED)
  15. pkg_check_modules(CURLPP REQUIRED curlpp)
  16. if(WITH_EASY)
  17. pkg_check_modules(JSONCPP REQUIRED jsoncpp)
  18. endif()
  19. set(CMAKE_CXX_STANDARD 14)
  20. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  21. set(CMAKE_CXX_EXTENSIONS OFF)
  22. set(CMAKE_CXX_FLAGS_DEBUG
  23. "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -Wpedantic -ftrapv -fsanitize=undefined -g -Og -fno-omit-frame-pointer")
  24. # Do not complain about compatibility-wrapper
  25. if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
  26. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
  27. endif()
  28. include_directories(${PROJECT_SOURCE_DIR}/src)
  29. include_directories(${PROJECT_BINARY_DIR})
  30. include_directories(${CURL_INCLUDE_DIRS})
  31. include_directories(${CURLPP_INCLUDE_DIRS})
  32. include_directories(${JSONCPP_INCLUDE_DIRS})
  33. link_directories(${CURL_LIBRARY_DIRS})
  34. link_directories(${CURLPP_LIBRARY_DIRS})
  35. link_directories(${JSONCPP_LIBRARY_DIRS})
  36. # Write version in header
  37. configure_file (
  38. "${PROJECT_SOURCE_DIR}/src/version.hpp.in"
  39. "${PROJECT_BINARY_DIR}/version.hpp"
  40. )
  41. # Announce that we are compiling mastodon-cpp (used to figure out where the
  42. # headers are)
  43. add_definitions(-DMASTODON_CPP=1)
  44. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  45. add_definitions(-DDEBUG=1)
  46. endif()
  47. if(NOT WITH_EASY)
  48. add_definitions(-DWITHOUT_EASY=1)
  49. endif()
  50. # Compile library
  51. if(WITH_EASY)
  52. file(GLOB sources src/*.cpp src/api/*.cpp
  53. src/easy/*.cpp src/easy/entities/*.cpp)
  54. else()
  55. file(GLOB sources src/*.cpp src/api/*.cpp)
  56. endif()
  57. add_library(${PROJECT_NAME} SHARED ${sources})
  58. set_target_properties(${PROJECT_NAME} PROPERTIES
  59. VERSION ${PROJECT_VERSION}
  60. SOVERSION ${${PROJECT_NAME}_VERSION_MAJOR}
  61. )
  62. if(WITH_EASY)
  63. target_link_libraries(${PROJECT_NAME}
  64. ${CURLPP_LIBRARIES} pthread ${JSONCPP_LIBRARIES})
  65. else()
  66. target_link_libraries(${PROJECT_NAME}
  67. ${CURLPP_LIBRARIES} pthread)
  68. endif()
  69. # Compile examples
  70. if(WITH_EXAMPLES)
  71. file(GLOB sources_examples examples/*.cpp)
  72. foreach(src ${sources_examples})
  73. get_filename_component(bin ${src} NAME_WE)
  74. add_executable(${bin} ${src})
  75. target_link_libraries(${bin} pthread ${JSONCPP_LIBRARIES} ${PROJECT_NAME})
  76. endforeach()
  77. endif()
  78. # Compile tests
  79. if(WITH_TESTS)
  80. configure_file("tests/test.gif" "${CMAKE_CURRENT_BINARY_DIR}" COPYONLY)
  81. include(tests.CMakeLists.txt)
  82. endif()
  83. # Install library and header files
  84. install(TARGETS ${PROJECT_NAME} LIBRARY
  85. DESTINATION ${CMAKE_INSTALL_LIBDIR})
  86. install(FILES src/mastodon-cpp.hpp src/return_types.hpp src/types.hpp
  87. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
  88. if(WITH_EASY)
  89. file(GLOB easy_header src/easy/*.hpp)
  90. install(FILES ${easy_header}
  91. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/easy)
  92. file(GLOB easy_entities_header src/easy/entities/*.hpp)
  93. install(FILES ${easy_entities_header}
  94. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/easy/entities)
  95. endif()
  96. # Compile & install documentation
  97. if(WITH_DOC)
  98. add_custom_command(OUTPUT ${PROJECT_SOURCE_DIR}/doc/html
  99. COMMAND ./build_doc.sh WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
  100. add_custom_target(doc DEPENDS doc/html)
  101. add_dependencies(${PROJECT_NAME} doc)
  102. install(DIRECTORY ${PROJECT_SOURCE_DIR}/doc/html
  103. DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/doc/${PROJECT_NAME}-${PROJECT_VERSION})
  104. file(GLOB examples examples/example*.cpp)
  105. install(FILES ${examples}
  106. DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/doc/${PROJECT_NAME}-${PROJECT_VERSION}/examples)
  107. endif()
  108. # Packages
  109. include(packages.CMakeLists.txt)