larra/CMakeLists.txt

257 lines
7 KiB
Text
Raw Normal View History

cmake_minimum_required(VERSION 3.28)
2024-08-25 12:04:55 +00:00
2024-08-26 04:29:16 +00:00
project(larra
2024-08-25 12:04:55 +00:00
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)
2024-08-29 16:42:58 +00:00
set(FMT_MODULE OFF)
set(UTEMPL_MODULE OFF)
2024-08-25 12:04:55 +00:00
set(CXX_EXTENSIONS NO)
2024-09-03 15:36:08 +00:00
set(BOOST_INCLUDE_LIBRARIES "pfr;asio;serialization")
2024-08-25 12:04:55 +00:00
option(CPM_USE_LOCAL_PACKAGES "Use local packages" ON)
2024-08-30 08:46:43 +00:00
option(UTEMPL_USE_LOCAL_PACKAGE "Use utempl local package" OFF)
2024-09-15 03:15:09 +00:00
option(BUILD_EXECUTABLE ON)
2024-09-05 12:27:30 +00:00
set(UTEMPL_URL
2024-09-10 19:38:47 +00:00
"https://helicopter.myftp.org/git/sha512sum/utempl"
2024-09-05 12:27:30 +00:00
CACHE STRING "utempl repository URL")
2024-08-25 12:04:55 +00:00
2024-09-15 03:15:09 +00:00
file(GLOB_RECURSE LIB_SOURCES "library/*.*pp")
2024-08-25 12:04:55 +00:00
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)
2024-09-03 15:36:08 +00:00
find_package(OpenSSL REQUIRED)
find_package(PkgConfig REQUIRED)
2024-08-25 12:04:55 +00:00
2024-09-27 19:28:22 +00:00
pkg_check_modules(GTKMM gtkmm-4.0 REQUIRED)
2024-08-25 12:04:55 +00:00
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"
)
2024-08-27 07:41:40 +00:00
CPMAddPackage("gh:zeux/pugixml@1.14")
2024-09-03 15:36:08 +00:00
CPMAddPackage("gh:fmtlib/fmt#10.2.1")
2024-08-29 16:42:58 +00:00
2024-09-25 19:10:50 +00:00
CPMAddPackage(
NAME spdlog
VERSION 1.14.1
GIT_REPOSITORY "https://github.com/gabime/spdlog.git"
EXCLUDE_FROM_ALL ON
OPTIONS "SPDLOG_INSTALL ON"
)
2024-08-27 07:41:40 +00:00
2024-08-25 12:04:55 +00:00
set(TMP ${CPM_USE_LOCAL_PACKAGES})
2024-08-30 08:46:43 +00:00
set(CPM_USE_LOCAL_PACKAGES ${UTEMPL_USE_LOCAL_PACKAGE})
2024-08-25 12:04:55 +00:00
CPMAddPackage(
NAME utempl
2024-09-05 12:27:30 +00:00
URL "${UTEMPL_URL}/archive/refs/heads/main.zip"
2024-08-25 12:04:55 +00:00
EXCLUDE_FROM_ALL ON
OPTIONS "ENABLE_TESTS OFF" "ENABLE_EXAMPLES OFF"
)
2024-08-29 16:42:58 +00:00
set(CPM_USE_LOCAL_PACKAGES ${TMP})
2024-08-25 12:04:55 +00:00
2024-09-27 19:28:22 +00:00
pkg_check_modules(xmlplusplus libxml++-5.0)
2024-08-25 12:04:55 +00:00
2024-09-27 19:28:22 +00:00
if(xmlplusplus_FOUND)
add_library(xmlplusplus INTERFACE EXCLUDE_FROM_ALL)
target_include_directories(xmlplusplus INTERFACE ${xmlplusplus_INCLUDE_DIRS})
target_link_libraries(xmlplusplus INTERFACE ${xmlplusplus_LINK_LIBRARIES})
install(TARGETS xmlplusplus
EXPORT larraXMPPTargets)
else()
include(ExternalProject)
find_program(Meson_EXECUTABLE meson)
if(NOT Meson_EXECUTABLE)
message(FATAL_ERROR "Meson is required!")
endif()
find_program(Ninja_EXECUTABLE ninja)
if(NOT Ninja_EXECUTABLE)
message(FATAL_ERROR "Ninja is required!")
endif()
set(XMLPLUSPLUS "libxmlplusplus")
set(XMLPLUSPLUS_INSTALL_PREFIX
"${CMAKE_CURRENT_BINARY_DIR}/ext/${XMLPLUSPLUS}")
ExternalProject_Add(${XMLPLUSPLUS}
URL https://github.com/libxmlplusplus/libxmlplusplus/releases/download/5.4.0/libxml++-5.4.0.tar.xz
INSTALL_DIR ${XMLPLUSPLUS_INSTALL_PREFIX}
CONFIGURE_COMMAND env C=${CMAKE_C_COMPILER} CC=${CMAKE_CXX_COMPILER}
${Meson_EXECUTABLE} -Ddefault_library=static --prefix=<INSTALL_DIR> <BINARY_DIR> <SOURCE_DIR>
CONFIGURE_HANDLED_BY_BUILD ON
BUILD_COMMAND ${Ninja_EXECUTABLE} -C <BINARY_DIR>
INSTALL_COMMAND ${Ninja_EXECUTABLE} -C <BINARY_DIR> install
BUILD_BYPRODUCTS
${XMLPLUSPLUS_INSTALL_PREFIX}/lib64/libxml++-5.0.${CMAKE_STATIC_LIBRARY_SUFFIX_CPP}
)
add_library(xmlplusplus STATIC IMPORTED GLOBAL)
add_dependencies(xmlplusplus ${XMLPLUSPLUS})
set_target_properties(
xmlplusplus
PROPERTIES IMPORTED_LOCATION
${XMLPLUSPLUS_INSTALL_PREFIX}/lib64/libxml++-5.0.${CMAKE_STATIC_LIBRARY_SUFFIX_CPP}
INTERFACE_INCLUDE_DIRECTORIES ${XMLPLUSPLUS_INSTALL_PREFIX}/include
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ${XMLPLUSPLUS_INSTALL_PREFIX}/include)
endif()
2024-08-25 12:04:55 +00:00
cmake_policy(SET CMP0079 NEW)
include(GNUInstallDirs)
2024-09-15 03:15:09 +00:00
add_library(larra_xmpp ${LIB_SOURCES})
2024-08-25 12:04:55 +00:00
2024-08-26 04:29:16 +00:00
add_library(larra::larra_xmpp ALIAS larra_xmpp)
2024-08-25 12:04:55 +00:00
2024-08-29 16:42:58 +00:00
target_compile_features(larra_xmpp PUBLIC cxx_std_23)
2024-08-26 04:29:16 +00:00
2024-09-15 03:15:09 +00:00
target_compile_options(larra_xmpp PUBLIC -Wno-changes-meaning)
target_include_directories(larra_xmpp PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/library/include>
2024-09-17 13:45:15 +00:00
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
2024-08-25 12:04:55 +00:00
if(TARGET Boost::pfr)
2024-08-27 07:41:40 +00:00
target_link_libraries(larra_xmpp PUBLIC
Boost::asio Boost::serialization utempl::utempl pugixml::pugixml OpenSSL::SSL
2024-09-27 19:28:22 +00:00
OpenSSL::Crypto spdlog xmlplusplus)
2024-08-25 12:04:55 +00:00
else()
find_package(Boost 1.85.0 REQUIRED)
2024-08-27 07:41:40 +00:00
target_link_libraries(larra_xmpp PUBLIC
2024-09-03 15:36:08 +00:00
utempl::utempl ${Boost_LIBRARIES} pugixml::pugixml OpenSSL::SSL
2024-09-27 19:28:22 +00:00
OpenSSL::Crypto spdlog xmlplusplus)
2024-08-25 12:04:55 +00:00
endif()
2024-09-15 03:15:09 +00:00
if(BUILD_EXECUTABLE)
2024-08-26 04:29:16 +00:00
add_executable(larra)
2024-08-25 12:04:55 +00:00
2024-08-26 04:29:16 +00:00
target_compile_features(larra INTERFACE cxx_std_23)
2024-08-25 12:04:55 +00:00
2024-08-27 07:41:40 +00:00
target_link_libraries(larra larra_xmpp ${GTKMM_LIBRARIES} ${GTKMM_LIBRARIES})
2024-08-25 12:04:55 +00:00
2024-08-29 16:42:58 +00:00
target_include_directories(larra PRIVATE
2024-09-15 03:15:09 +00:00
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
2024-08-29 16:42:58 +00:00
target_sources(larra PRIVATE ${SOURCES})
2024-09-15 03:15:09 +00:00
install(TARGETS larra
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
endif()
2024-08-25 12:04:55 +00:00
2024-09-15 03:15:09 +00:00
install(TARGETS larra_xmpp
EXPORT larraXMPPTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
2024-08-25 12:04:55 +00:00
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
2024-09-15 03:15:09 +00:00
FILE_SET larraXMPPSet DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
2024-08-25 12:04:55 +00:00
)
2024-09-15 03:15:09 +00:00
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/library/include/larra"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.hpp")
2024-08-25 12:04:55 +00:00
include(CMakePackageConfigHelpers)
2024-08-26 04:29:16 +00:00
write_basic_package_version_file("larraXMPPVersionConfig.cmake"
2024-08-25 12:04:55 +00:00
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
configure_package_config_file(
2024-08-26 04:29:16 +00:00
"${PROJECT_SOURCE_DIR}/cmake/larraXMPPConfig.cmake.in"
"${PROJECT_BINARY_DIR}/larraXMPPConfig.cmake"
2024-08-25 12:04:55 +00:00
INSTALL_DESTINATION
2024-09-15 03:15:09 +00:00
${CMAKE_INSTALL_DATAROOTDIR}/larra/cmake)
2024-08-25 12:04:55 +00:00
2024-08-26 04:29:16 +00:00
install(EXPORT larraXMPPTargets
2024-08-25 12:04:55 +00:00
FILE xmppClientLibTargets.cmake
2024-08-26 04:29:16 +00:00
NAMESPACE larra::
2024-09-15 03:15:09 +00:00
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/larra/cmake)
2024-08-25 12:04:55 +00:00
2024-09-15 03:15:09 +00:00
install(FILES "${PROJECT_BINARY_DIR}/larraXMPPConfig.cmake"
"${PROJECT_BINARY_DIR}/larraXMPPVersionConfig.cmake"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/larra/cmake)
2024-08-25 12:04:55 +00:00
if(ENABLE_TESTS)
2024-08-29 16:42:58 +00:00
CPMAddPackage(
NAME GTest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
2024-08-25 12:04:55 +00:00
enable_testing()
file(GLOB_RECURSE SOURCES "tests/*.cpp" )
2024-08-26 04:29:16 +00:00
add_executable(larra_xmpp_tests)
2024-08-29 16:42:58 +00:00
target_sources(larra_xmpp_tests PUBLIC ${SOURCES})
2024-08-26 04:29:16 +00:00
target_link_libraries(larra_xmpp_tests GTest::gtest_main
2024-08-27 10:09:34 +00:00
larra_xmpp)
2024-08-26 04:29:16 +00:00
set_property(TARGET larra_xmpp_tests PROPERTY CXX_STANDARD 23)
2024-08-25 12:04:55 +00:00
include(GoogleTest)
2024-08-26 04:29:16 +00:00
gtest_discover_tests(larra_xmpp_tests)
2024-08-25 12:04:55 +00:00
endif()
2024-09-03 15:36:08 +00:00
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")
2024-09-03 15:36:08 +00:00
endforeach()
endif()