Newer
Older
CMAKE_TOOLCHAIN_FILE
"${CMAKE_CURRENT_LIST_DIR}/toolchain.cmake"
CACHE
FILEPATH
"Default toolchain"
)
set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard")
set(CMAKE_CXX_STANDARD_REQUIRED ON CACHE BOOL "Require C++ standard to be supported")
set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "compile as PIC by default")
option(HUNTER_ENABLED "Enable Hunter package manager" OFF)
include("cmake/HunterGate.cmake")
HunterGate(
URL "https://github.com/cpp-pm/hunter/archive/v0.23.260.tar.gz"
SHA1 "13775235910a3fa85644568d1c5be8271de72e1c"
)
option(USE_BUNDLED_BOOST "Use the bundled version of Boost." ${HUNTER_ENABLED})
option(USE_BUNDLED_SPDLOG "Use the bundled version of spdlog."
option(USE_BUNDLED_OLM "Use the bundled version of libolm." ${HUNTER_ENABLED})
option(USE_BUNDLED_GTEST "Use the bundled version of Google Test."
option(USE_BUNDLED_JSON "Use the bundled version of nlohmann json."
option(USE_BUNDLED_OPENSSL "Use the bundled version of OpenSSL."
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.12)
DESCRIPTION "Client API library for Matrix, built on top of Boost.Asio"
DESCRIPTION "Client API library for Matrix, built on top of Boost.Asio")
endif()
option(ASAN "Compile with address sanitizers" OFF)
option(BUILD_LIB_TESTS "Build tests" ON)
option(BUILD_LIB_EXAMPLES "Build examples" ON)
option(COVERAGE "Calculate test coverage" OFF)
option(IWYU "Check headers with include-what-you-use" OFF)
option(BUILD_SHARED_LIBS "Specifies whether to build mtxclient as a shared library lib or not" ON)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
if(NOT MSVC)
set(
CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} \
-Wall \
-Wextra \
-pipe \
-pedantic \
-fsized-deallocation \
-fdiagnostics-color=always \
-Wunreachable-code"
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj -bigobj")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address,undefined")
if(NOT MSVC AND NOT APPLE)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
endif()
set_package_properties(OpenSSL PROPERTIES
DESCRIPTION "Open source SSL and TLS implementation and cryptographic library"
URL "https://www.openssl.org/"
TYPE REQUIRED
)
if(USE_BUNDLED_OLM)
include(FetchContent)
FetchContent_Declare(
Olm
GIT_REPOSITORY https://gitlab.matrix.org/matrix-org/olm.git
GIT_TAG 3.1.4
)
FetchContent_MakeAvailable(Olm)
else()
find_package(Olm 3)
set_package_properties(Olm PROPERTIES
DESCRIPTION "An implementation of the Double Ratchet cryptographic ratchet"
URL "https://git.matrix.org/git/olm/about/"
TYPE REQUIRED
)
find_package(nlohmann_json 3.2.0 CONFIG REQUIRED)
set_package_properties(nlohmann_json PROPERTIES
DESCRIPTION "JSON for Modern C++, a C++11 header-only JSON class"
URL "https://nlohmann.github.io/json/"
TYPE REQUIRED
)
hunter_add_package(Boost COMPONENTS iostreams system thread)
find_package(Boost 1.70 COMPONENTS REQUIRED iostreams system thread)
set_package_properties(Boost PROPERTIES
DESCRIPTION "Free peer-reviewed portable C++ source libraries"
URL "https://www.boost.org/"
TYPE REQUIRED
)
add_library(matrix_client)
target_sources(matrix_client
PRIVATE
lib/http/client.cpp
lib/http/session.cpp
lib/crypto/client.cpp
lib/utils.cpp
lib/log.cpp
lib/structs/common.cpp
lib/structs/errors.cpp
lib/structs/events.cpp
lib/structs/user_interactive.cpp
lib/structs/events/aliases.cpp
lib/structs/events/avatar.cpp
lib/structs/events/canonical_alias.cpp
lib/structs/events/collections.cpp
lib/structs/events/create.cpp
lib/structs/events/encrypted.cpp
lib/structs/events/encryption.cpp
lib/structs/events/guest_access.cpp
lib/structs/events/history_visibility.cpp
lib/structs/events/join_rules.cpp
lib/structs/events/member.cpp
lib/structs/events/name.cpp
lib/structs/events/pinned_events.cpp
lib/structs/events/power_levels.cpp
lib/structs/events/redaction.cpp
lib/structs/events/tag.cpp
lib/structs/events/tombstone.cpp
lib/structs/events/topic.cpp
lib/structs/events/nheko_extensions/hidden_events.cpp
lib/structs/events/messages/audio.cpp
lib/structs/events/messages/emote.cpp
lib/structs/events/messages/file.cpp
lib/structs/events/messages/image.cpp
lib/structs/events/messages/notice.cpp
lib/structs/events/messages/text.cpp
lib/structs/events/messages/video.cpp
lib/structs/responses/common.cpp
lib/structs/responses/create_room.cpp
lib/structs/responses/crypto.cpp
lib/structs/responses/empty.cpp
lib/structs/responses/login.cpp
lib/structs/responses/media.cpp
lib/structs/responses/messages.cpp
lib/structs/responses/notifications.cpp
lib/structs/responses/profile.cpp
lib/structs/responses/register.cpp
lib/structs/responses/sync.cpp
lib/structs/responses/version.cpp
lib/structs/responses/well-known.cpp)
add_library(MatrixClient::MatrixClient ALIAS matrix_client)
set_property(TARGET matrix_client PROPERTY CXX_STANDARD 17)
set_property(TARGET matrix_client PROPERTY CXX_EXTENSIONS OFF)
target_include_directories(
matrix_client
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_link_libraries(matrix_client
PUBLIC
Boost::iostreams
Boost::system
Boost::thread
OpenSSL::Crypto
OpenSSL::SSL
Olm::Olm
nlohmann_json::nlohmann_json)
if(NOT MSVC AND NOT APPLE)
target_link_libraries(matrix_client PUBLIC Threads::Threads)
include(CodeCoverage)
add_custom_target(ctest COMMAND ${CMAKE_CTEST_COMMAND})
target_compile_options(matrix_client PUBLIC
-O0 # no optimization
-g # generate debug info
--coverage # sets all required flags
-fprofile-arcs -ftest-coverage # just to be sure, for clang!
)
target_link_options(matrix_client PUBLIC --coverage)
setup_target_for_coverage(test_coverage ctest coverage)
if(IWYU)
find_program(iwyu_path NAMES include-what-you-use iwyu)
if(iwyu_path)
set_property(TARGET matrix_client
PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path})
else()
message(WARNING "Could not find the program include-what-you-use")
endif()
if(BUILD_LIB_EXAMPLES)
endif()
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
#
# Installation & Target configuration.
#
include(GNUInstallDirs)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/MatrixClient)
install(TARGETS matrix_client
EXPORT matrix_client-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
set_target_properties(matrix_client PROPERTIES EXPORT_NAME MatrixClient)
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(EXPORT matrix_client-targets
FILE
MatrixClientTargets.cmake
NAMESPACE
MatrixClient::
DESTINATION
${INSTALL_CONFIGDIR})
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/MatrixClientConfigVersion.cmake
VERSION
${PROJECT_VERSION}
COMPATIBILITY
AnyNewerVersion)
${CMAKE_CURRENT_LIST_DIR}/cmake/MatrixClientConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/MatrixClientConfig.cmake
INSTALL_DESTINATION
${INSTALL_CONFIGDIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/MatrixClientConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/MatrixClientConfigVersion.cmake
DESTINATION
${INSTALL_CONFIGDIR})
matrix_client-targets
FILE
${CMAKE_CURRENT_BINARY_DIR}/MatrixClientTargets.cmake
NAMESPACE
MatrixClient::)
set_property(TARGET matrix_client PROPERTY SOVERSION ${PROJECT_VERSION})
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
enable_testing()
if(USE_BUNDLED_GTEST)
hunter_add_package(GTest)
endif()
find_package(GTest REQUIRED)
file(COPY tests/fixtures DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
add_executable(client_api tests/client_api.cpp)
target_link_libraries(client_api
MatrixClient::MatrixClient
GTest::GTest
GTest::Main)
target_include_directories(client_api PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/tests)
add_executable(media_api tests/media_api.cpp)
target_link_libraries(media_api
MatrixClient::MatrixClient
GTest::GTest
GTest::Main)
target_include_directories(media_api PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/tests)
add_executable(e2ee tests/e2ee.cpp)
target_link_libraries(e2ee
MatrixClient::MatrixClient
GTest::GTest
GTest::Main)
target_include_directories(e2ee PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests)
add_executable(utils tests/utils.cpp)
target_link_libraries(utils
MatrixClient::MatrixClient
GTest::GTest
GTest::Main)
target_include_directories(utils PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests)
add_executable(pushrules tests/pushrules.cpp)
target_link_libraries(pushrules
MatrixClient::MatrixClient
GTest::GTest
GTest::Main)
target_include_directories(pushrules PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests)
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
add_executable(connection tests/connection.cpp)
target_link_libraries(connection
MatrixClient::MatrixClient
GTest::GTest
GTest::Main)
target_include_directories(connection PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/tests)
add_executable(identifiers tests/identifiers.cpp)
target_link_libraries(identifiers
MatrixClient::MatrixClient
GTest::GTest
GTest::Main)
add_executable(events tests/events.cpp)
target_link_libraries(events
MatrixClient::MatrixClient
GTest::GTest
GTest::Main)
add_executable(messages tests/messages.cpp)
target_link_libraries(messages
MatrixClient::MatrixClient
GTest::GTest
GTest::Main)
add_executable(responses tests/responses.cpp)
target_link_libraries(responses
MatrixClient::MatrixClient
GTest::GTest
GTest::Main)
add_executable(requests tests/requests.cpp)
target_link_libraries(requests
MatrixClient::MatrixClient
GTest::GTest
GTest::Main)
add_executable(errors tests/errors.cpp)
target_link_libraries(errors
MatrixClient::MatrixClient
GTest::GTest
GTest::Main)
add_executable(crypto tests/crypto.cpp)
target_link_libraries(crypto
MatrixClient::MatrixClient
GTest::GTest
GTest::Main)
add_test(BasicConnectivity connection)
add_test(ClientAPI client_api)
add_test(MediaAPI media_api)
add_test(Encryption e2ee)
add_test(Utilities utils)
add_test(Identifiers identifiers)
add_test(Errors errors)
add_test(CryptoStructs crypto)
add_test(StateEvents events)
add_test(RoomEvents messages)
add_test(Responses responses)
add_test(Requests requests)