ranczo-io/CMakeLists.txt

122 lines
3.7 KiB
CMake

cmake_minimum_required(VERSION 3.20)
project(Ranczo-IO)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# add_compile_options(-g -fsanitize=address,undefined,float-divide-by-zero,float-cast-overflow,null -fsanitize-address-use-after-scope -fno-sanitize-recover=all -fno-sanitize=alignment -fno-omit-frame-pointer)
# add_link_options(-g -fsanitize=address,undefined,float-divide-by-zero,float-cast-overflow,null -fsanitize-address-use-after-scope -fno-sanitize-recover=all -fno-sanitize=alignment -fno-omit-frame-pointer)
include(CheckIPOSupported)
check_ipo_supported(RESULT supported OUTPUT error)
if( supported )
message(STATUS "IPO / LTO enabled")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(STATUS "IPO / LTO not supported: <${error}>")
endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
find_package(Boost REQUIRED COMPONENTS system json)
include(FetchContent)
# Create a Boost-style interface target for a header-only library
function(create_boost_header_only_target target_name)
string(TOLOWER ${target_name} target_key)
set(interface_target ${target_key}_interface)
set(header_subdir ${target_key})
set(target_name_full Boost::${target_name})
if(NOT TARGET ${target_name_full})
message(STATUS "Creating Boost::${target_name} as header-only interface target")
add_library(${interface_target} INTERFACE)
# Add include dir if not explicitly set
if(DEFINED Boost_INCLUDE_DIRS)
target_include_directories(${interface_target} INTERFACE ${Boost_INCLUDE_DIRS})
else()
message(WARNING "Boost_INCLUDE_DIRS not defined when creating Boost::${target_name}")
endif()
# Optional preprocessor tweaks per library
if(${target_name} STREQUAL "asio")
target_compile_definitions(${interface_target} INTERFACE BOOST_ASIO_NO_DEPRECATED)
endif()
# Create alias for consistency with imported targets
add_library(${target_name_full} ALIAS ${interface_target})
else()
message(STATUS "${target_name_full} already exists")
endif()
endfunction()
create_boost_header_only_target(asio)
create_boost_header_only_target(assert)
create_boost_header_only_target(core)
create_boost_header_only_target(endian)
create_boost_header_only_target(fusion)
create_boost_header_only_target(optional)
create_boost_header_only_target(random)
create_boost_header_only_target(range)
create_boost_header_only_target(smart_ptr)
create_boost_header_only_target(spirit)
create_boost_header_only_target(type_traits)
# spdlog
FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog
GIT_TAG v1.14.1
GIT_SHALLOW TRUE
)
FetchContent_Declare(
sml
GIT_REPOSITORY https://github.com/boost-ext/sml.git
GIT_TAG v1.1.12
GIT_SHALLOW TRUE
)
FetchContent_GetProperties(spdlog)
if(NOT spdlog_POPULATED)
FetchContent_Populate(spdlog)
# set(SPDLOG_FMT_EXTERNAL_HO ON)
set(SPDLOG_USE_STD_FORMAT ON)
endif()
add_subdirectory(
${spdlog_SOURCE_DIR}
${spdlog_BINARY_DIR}
)
FetchContent_Declare(
asyncmqtt5
GIT_REPOSITORY https://github.com/boostorg/mqtt5
GIT_TAG master
GIT_SHALLOW TRUE
)
set(MQTT_BUILD_TESTS OFF)
set(MQTT_BUILD_EXAMPLES OFF)
set(async-mqtt5_INCLUDES_WITH_SYSTEM OFF)
FetchContent_MakeAvailable(asyncmqtt5 sml)
# c++20 format library, super usefull, super fast
set(FMT_TEST OFF CACHE INTERNAL "disabling fmt tests")
FetchContent_Declare(fmt
URL https://github.com/fmtlib/fmt/archive/refs/tags/10.2.1.zip
URL_MD5 1bba4e8bdd7b0fa98f207559ffa380a3
)
FetchContent_MakeAvailable(fmt)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
# add_compile_definitions(BOOST_ASIO_ENABLE_HANDLER_TRACKING)
add_subdirectory(libs)
add_subdirectory(services)
add_subdirectory(tests)