larra/CMakeLists.txt

203 lines
5.2 KiB
CMake

cmake_minimum_required(VERSION 3.28)
project(larra
VERSION 0.1
LANGUAGES CXX)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(FMT_MODULE OFF)
set(UTEMPL_MODULE OFF)
set(CXX_EXTENSIONS NO)
set(BOOST_INCLUDE_LIBRARIES "pfr;asio;serialization")
option(CPM_USE_LOCAL_PACKAGES "Use local packages" ON)
option(UTEMPL_USE_LOCAL_PACKAGE "Use utempl local package" OFF)
option(BUILD_EXECUTABLE ON)
set(UTEMPL_URL
"https://helicopter.myftp.org/git/sha512sum/utempl"
CACHE STRING "utempl repository URL")
file(GLOB_RECURSE LIB_SOURCES "library/*.*pp")
file(GLOB_RECURSE SOURCES "src/*.cpp")
file(
DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.40.0/CPM.cmake
${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake
EXPECTED_HASH
SHA256=7b354f3a5976c4626c876850c93944e52c83ec59a159ae5de5be7983f0e17a2a
)
include(${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake)
find_package(OpenSSL REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTKMM gtkmm-4.0)
link_directories(
${GTKMM_LIBRARY_DIRS} )
include_directories(
${GTKMM_INCLUDE_DIRS} )
CPMAddPackage(
NAME Boost
VERSION 1.85.0
URL "https://github.com/boostorg/boost/releases/download/boost-1.85.0/boost-1.85.0-cmake.tar.xz"
EXCLUDE_FROM_ALL ON
OPTIONS "BOOST_SKIP_INSTALL_RULES OFF"
)
CPMAddPackage("gh:zeux/pugixml@1.14")
CPMAddPackage("gh:fmtlib/fmt#10.2.1")
CPMAddPackage(
NAME spdlog
VERSION 1.14.1
GIT_REPOSITORY "https://github.com/gabime/spdlog.git"
EXCLUDE_FROM_ALL ON
OPTIONS "SPDLOG_INSTALL ON"
)
set(TMP ${CPM_USE_LOCAL_PACKAGES})
set(CPM_USE_LOCAL_PACKAGES ${UTEMPL_USE_LOCAL_PACKAGE})
CPMAddPackage(
NAME utempl
URL "${UTEMPL_URL}/archive/refs/heads/main.zip"
EXCLUDE_FROM_ALL ON
OPTIONS "ENABLE_TESTS OFF" "ENABLE_EXAMPLES OFF"
)
set(CPM_USE_LOCAL_PACKAGES ${TMP})
cmake_policy(SET CMP0079 NEW)
include(GNUInstallDirs)
add_library(larra_xmpp ${LIB_SOURCES})
add_library(larra::larra_xmpp ALIAS larra_xmpp)
target_compile_features(larra_xmpp PUBLIC cxx_std_23)
target_compile_options(larra_xmpp PUBLIC -Wno-changes-meaning)
target_include_directories(larra_xmpp PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/library/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
if(TARGET Boost::pfr)
target_link_libraries(larra_xmpp PUBLIC
Boost::asio Boost::serialization utempl::utempl pugixml::pugixml OpenSSL::SSL
OpenSSL::Crypto spdlog)
else()
find_package(Boost 1.85.0 REQUIRED)
target_link_libraries(larra_xmpp PUBLIC
utempl::utempl ${Boost_LIBRARIES} pugixml::pugixml OpenSSL::SSL
OpenSSL::Crypto spdlog)
endif()
if(BUILD_EXECUTABLE)
add_executable(larra)
target_compile_features(larra INTERFACE cxx_std_23)
target_link_libraries(larra larra_xmpp ${GTKMM_LIBRARIES} ${GTKMM_LIBRARIES})
target_include_directories(larra PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
target_sources(larra PRIVATE ${SOURCES})
install(TARGETS larra
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
endif()
install(TARGETS larra_xmpp
EXPORT larraXMPPTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
FILE_SET larraXMPPSet DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/library/include/larra"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.hpp")
include(CMakePackageConfigHelpers)
write_basic_package_version_file("larraXMPPVersionConfig.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/larraXMPPConfig.cmake.in"
"${PROJECT_BINARY_DIR}/larraXMPPConfig.cmake"
INSTALL_DESTINATION
${CMAKE_INSTALL_DATAROOTDIR}/larra/cmake)
install(EXPORT larraXMPPTargets
FILE xmppClientLibTargets.cmake
NAMESPACE larra::
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/larra/cmake)
install(FILES "${PROJECT_BINARY_DIR}/larraXMPPConfig.cmake"
"${PROJECT_BINARY_DIR}/larraXMPPVersionConfig.cmake"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/larra/cmake)
if(ENABLE_TESTS)
CPMAddPackage(
NAME GTest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
enable_testing()
file(GLOB_RECURSE SOURCES "tests/*.cpp" )
add_executable(larra_xmpp_tests)
target_sources(larra_xmpp_tests PUBLIC ${SOURCES})
target_link_libraries(larra_xmpp_tests GTest::gtest_main
larra_xmpp)
set_property(TARGET larra_xmpp_tests PROPERTY CXX_STANDARD 23)
include(GoogleTest)
gtest_discover_tests(larra_xmpp_tests)
endif()
if(ENABLE_EXAMPLES)
file(GLOB EXAMPLES_SRC "examples/src/*.cpp")
foreach(EXAMPLE_SRC ${EXAMPLES_SRC})
get_filename_component(EXAMPLE_NAME ${EXAMPLE_SRC} NAME_WE)
add_executable(${EXAMPLE_NAME} ${EXAMPLE_SRC})
target_link_libraries(${EXAMPLE_NAME} larra_xmpp)
set_property(TARGET ${EXAMPLE_NAME} PROPERTY CXX_STANDARD 23)
set_target_properties(${EXAMPLE_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/examples/output")
endforeach()
endif()