Skip to content

Commit

Permalink
build script cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
klemens-morgenstern committed Oct 17, 2023
1 parent 94acb72 commit 6319f90
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 116 deletions.
237 changes: 145 additions & 92 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,131 +1,184 @@
cmake_minimum_required(VERSION 3.20)

set(BOOST_REQUESTS_VERSION 1)
if(BOOST_SUPERPROJECT_VERSION)
set(BOOST_REQUESTS_VERSION ${BOOST_SUPERPROJECT_VERSION})
endif()

project(boost_cobalt VERSION "${BOOST_COBALT_VERSION}" LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)

set(BOOST_COBALT_IS_ROOT OFF)

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(BOOST_COBALT_IS_ROOT ON)
endif()

if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../../boost.css)
set(BOOST_COBALT_SHOULD_BE_INLINE ON)
else()
set(BOOST_COBALT_SHOULD_BE_INLINE OFF)
set(BOOST_COBALT_SHOULD_USE_CONTAINER OFF)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CLANG_VERSION_MAJOR LESS 16)
set(BOOST_COBALT_SHOULD_USE_CONTAINER ON)
endif()

option(BOOST_COBALT_BUILD_INLINE "Configure as if part of the boost source tree" ${BOOST_COBALT_SHOULD_BE_INLINE})
option(BOOST_COBALT_USE_BOOST_CONTAINER "Use boost.container instead of std::pmr" ${BOOST_COBALT_SHOULD_USE_CONTAINER})

file(GLOB_RECURSE ADOC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.adoc)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/doc/index.html
COMMAND asciidoctor ${CMAKE_CURRENT_SOURCE_DIR}/doc/index.adoc --require asciidoctor-diagram --require asciidoctor-multipage -b multipage_html5 -o ${CMAKE_CURRENT_BINARY_DIR}/doc/index.html
DEPENDS ${ADOC_FILES})

add_custom_target(boost_cobalt_doc DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/doc/index.html)
if (NOT BOOST_COBALT_IS_ROOT)
# Generated by `boostdep --cmake cobalt`
# Copyright 2020, 2021 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# https://www.boost.org/LICENSE_1_0.txt

# 12 for cxx_std_20
cmake_minimum_required(VERSION 3.12...3.20)

if(BOOST_COBALT_IS_ROOT)
#include(CTest)
endif()
if(NOT BOOST_SUPERPROJECT_VERSION)
option(BOOST_COBALT_INSTALL "Install boost::cobalt files" ON)
option(BOOST_COBALT_BUILD_TESTS "Build boost::cobalt tests" ${BUILD_TESTING})
option(BOOST_COBALT_BUILD_EXAMPLES "Build boost::cobalt examples" ${BOOST_COBALT_IS_ROOT})
option(BOOST_COBALT_BUILD_BENCHMARKS "Build boost::cobalt benchmarks" OFF)
else()
set(BOOST_COBALT_BUILD_TESTS ${BUILD_TESTING})
endif()
project(boost_cobalt VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)

set(BOOST_COBALT_SHOULD_USE_CONTAINER OFF)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CLANG_VERSION_MAJOR LESS 16)
set(BOOST_COBALT_SHOULD_USE_CONTAINER ON)
endif()
add_library(boost_cobalt
src/channel.cpp
src/error.cpp
src/main.cpp
src/this_thread.cpp
src/thread.cpp
)

add_library(Boost::cobalt ALIAS boost_cobalt)

target_include_directories(boost_cobalt PUBLIC include)

target_link_libraries(boost_cobalt
PUBLIC
Boost::asio
Boost::circular_buffer
Boost::config
Boost::container
Boost::core
Boost::intrusive
Boost::leaf
Boost::mp11
Boost::preprocessor
Boost::smart_ptr
Boost::system
Boost::throw_exception
Boost::variant2
)

target_compile_definitions(boost_cobalt
PUBLIC BOOST_COBALT_NO_LIB
PRIVATE BOOST_COBALT_SOURCE
)
target_compile_features(boost_cobalt PUBLIC cxx_std_20)

option(BOOST_COBALT_USE_BOOST_CONTAINER "Use boost.container instead of std::pmr" ${BOOST_COBALT_SHOULD_USE_CONTAINER})
if (BOOST_COBALT_USE_BOOST_CONTAINER)
target_link_libraries(boost_cobalt PUBLIC Boost::container)
target_compile_definitions(boost_cobalt PUBLIC BOOST_COBALT_USE_BOOST_CONTAINER_PMR=1 )
endif()

if(BUILD_SHARED_LIBS)
target_compile_definitions(boost_cobalt PUBLIC BOOST_COBALT_DYN_LINK)
else()
target_compile_definitions(boost_cobalt PUBLIC BOOST_COBALT_STATIC_LINK)
endif()

if(BOOST_COBALT_IS_ROOT AND BOOST_COBALT_BUILD_INLINE)
#
# Building inside Boost tree, but as a separate project e.g. on Travis or
# other CI, or when producing Visual Studio Solution and Projects.
if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
add_subdirectory(test)
endif()
else()
if(BOOST_SUPERPROJECT_VERSION)
set(BOOST_COBALT_SHOULD_BE_INLINE ON)
else()
set(BOOST_COBALT_SHOULD_BE_INLINE OFF)
endif()

set(BOOST_INCLUDE_LIBRARIES COBALT)
set(BOOST_EXCLUDE_LIBRARIES COBALT)
option(BOOST_COBALT_BUILD_INLINE "Configure as if part of the boost source tree" ${BOOST_COBALT_SHOULD_BE_INLINE})

set(CMAKE_FOLDER _deps)
add_subdirectory(../.. _deps/boost EXCLUDE_FROM_ALL)
unset(CMAKE_FOLDER)
endif()
file(GLOB_RECURSE ADOC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.adoc)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/doc/index.html
COMMAND asciidoctor ${CMAKE_CURRENT_SOURCE_DIR}/doc/index.adoc --require asciidoctor-diagram --require asciidoctor-multipage -b multipage_html5 -o ${CMAKE_CURRENT_BINARY_DIR}/doc/index.html
DEPENDS ${ADOC_FILES})

if (NOT BOOST_COBALT_BUILD_INLINE)
find_package(Threads REQUIRED)
# Boost 1.82 is the first with a Boost.ASIO with necessary support
find_package(Boost 1.82 REQUIRED COMPONENTS system OPTIONAL_COMPONENTS json context url)
if (BOOST_COBALT_USE_BOOST_CONTAINER)
find_package(Boost REQUIRED container)
add_custom_target(boost_cobalt_doc DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/doc/index.html)


if(BOOST_COBALT_IS_ROOT)
#include(CTest)
endif()
if(NOT BOOST_SUPERPROJECT_VERSION)
option(BOOST_COBALT_INSTALL "Install boost::cobalt files" ON)
option(BOOST_COBALT_BUILD_TESTS "Build boost::cobalt tests" ${BUILD_TESTING})
option(BOOST_COBALT_BUILD_EXAMPLES "Build boost::cobalt examples" ${BOOST_COBALT_IS_ROOT})
option(BOOST_COBALT_BUILD_BENCHMARKS "Build boost::cobalt benchmarks" OFF)
else()
set(BOOST_COBALT_BUILD_TESTS ${BUILD_TESTING})
endif()
include_directories(include)
endif()

find_package(OpenSSL)
if (NOT MSVC)
link_libraries(${OPENSSL_LIBRARIES})
endif()
if(BOOST_COBALT_IS_ROOT AND BOOST_COBALT_BUILD_INLINE)
#
# Building inside Boost tree, but as a separate project e.g. on Travis or
# other CI, or when producing Visual Studio Solution and Projects.

add_library(boost_cobalt
src/detail/exception.cpp
src/detail/util.cpp
src/error.cpp
src/channel.cpp
src/main.cpp
src/this_thread.cpp
src/thread.cpp)
target_include_directories(boost_cobalt PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(boost_cobalt PUBLIC
Boost::system
Threads::Threads)
target_compile_definitions(boost_cobalt PRIVATE BOOST_COBALT_SOURCE=1 )

if (BOOST_COBALT_USE_BOOST_CONTAINER)
target_link_libraries(boost_cobalt PUBLIC Boost::container)
target_compile_definitions(boost_cobalt PUBLIC BOOST_COBALT_USE_BOOST_CONTAINER_PMR=1 )
endif()
set(BOOST_INCLUDE_LIBRARIES COBALT)
set(BOOST_EXCLUDE_LIBRARIES COBALT)

target_compile_features(boost_cobalt PUBLIC cxx_std_20)
set(CMAKE_FOLDER _deps)
add_subdirectory(../.. _deps/boost EXCLUDE_FROM_ALL)
unset(CMAKE_FOLDER)
endif()

if (NOT BOOST_COBALT_BUILD_INLINE)
find_package(Threads REQUIRED)
# Boost 1.82 is the first with a Boost.ASIO with necessary support
find_package(Boost 1.82 REQUIRED COMPONENTS system OPTIONAL_COMPONENTS json context url)
if (BOOST_COBALT_USE_BOOST_CONTAINER)
find_package(Boost REQUIRED container)
endif()
include_directories(include)
endif()

add_library(Boost::cobalt ALIAS boost_cobalt)
add_library(boost_cobalt
src/detail/exception.cpp
src/detail/util.cpp
src/error.cpp
src/channel.cpp
src/main.cpp
src/this_thread.cpp
src/thread.cpp)

target_include_directories(boost_cobalt PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(boost_cobalt PUBLIC
Boost::system
Threads::Threads)
target_compile_definitions(boost_cobalt PRIVATE BOOST_COBALT_SOURCE=1 )

if(BUILD_SHARED_LIBS)
target_compile_definitions(boost_cobalt PUBLIC BOOST_COBALT_DYN_LINK=1)
else()
target_compile_definitions(boost_cobalt PUBLIC BOOST_COBALT_STATIC_LINK=1)
endif()
if (BOOST_COBALT_USE_BOOST_CONTAINER)
target_link_libraries(boost_cobalt PUBLIC Boost::container)
target_compile_definitions(boost_cobalt PUBLIC BOOST_COBALT_USE_BOOST_CONTAINER_PMR=1 )
endif()

if(BOOST_COBALT_INSTALL AND NOT BOOST_SUPERPROJECT_VERSION)
install(TARGETS boost_cobalt
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
endif()
target_compile_features(boost_cobalt PUBLIC cxx_std_20)
add_library(Boost::cobalt ALIAS boost_cobalt)

if(BOOST_COBALT_BUILD_TESTS)
add_subdirectory(test)
endif()
if(BUILD_SHARED_LIBS)
target_compile_definitions(boost_cobalt PUBLIC BOOST_COBALT_DYN_LINK=1)
else()
target_compile_definitions(boost_cobalt PUBLIC BOOST_COBALT_STATIC_LINK=1)
endif()

if(BOOST_COBALT_INSTALL AND NOT BOOST_SUPERPROJECT_VERSION)
install(TARGETS boost_cobalt
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
endif()

if(BOOST_COBALT_BUILD_EXAMPLES)
add_subdirectory(example)
set_target_properties(boost_cobalt PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
if(BOOST_COBALT_BUILD_TESTS)
add_subdirectory(test)
endif()

if(BOOST_COBALT_BUILD_EXAMPLES)
add_subdirectory(example)
set_target_properties(boost_cobalt PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()

if(BOOST_COBALT_BUILD_BENCHMARKS)
add_subdirectory(bench)
if(BOOST_COBALT_BUILD_BENCHMARKS)
add_subdirectory(bench)
endif()
endif()

5 changes: 3 additions & 2 deletions build/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ lib boost_cobalt
[ requires
cpp_concepts_20
]
: usage-requirements <boost.cobalt.pmr>boost-container:<library>/boost//container

: usage-requirements
<link>shared:<define>BOOST_COBALT_DYN_LINK=1
<boost.cobalt.pmr>boost-container:<library>/boost//container
;

boost-install boost_cobalt ;
Expand Down
6 changes: 4 additions & 2 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@

file(GLOB_RECURSE ALL_EXAMPLES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)

find_package(OpenSSL)

foreach(SRC ${ALL_EXAMPLES})
get_filename_component(NAME ${SRC} NAME_WLE )
# ticker requires
if (NAME STREQUAL ticker)
if (TARGET Boost::json)
add_executable(boost_cobalt_example_${NAME} ${SRC} )
target_link_libraries(boost_cobalt_example_${NAME} PUBLIC Boost::cobalt Boost::json Boost::url)
target_link_libraries(boost_cobalt_example_${NAME} PUBLIC Boost::cobalt Boost::json Boost::url ${OPENSSL_LIBRARIES})
target_compile_definitions(boost_cobalt_example_${NAME} PUBLIC)
endif()
continue()
Expand Down Expand Up @@ -39,6 +41,6 @@ foreach(SRC ${ALL_EXAMPLES})
endif()

add_executable(boost_cobalt_example_${NAME} ${SRC})
target_link_libraries(boost_cobalt_example_${NAME} PUBLIC Boost::cobalt)
target_link_libraries(boost_cobalt_example_${NAME} PUBLIC Boost::cobalt ${OPENSSL_LIBRARIES})
target_compile_definitions(boost_cobalt_example_${NAME} PUBLIC)
endforeach()
3 changes: 0 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# boost.cobalt

> [!NOTE]
> This is not yet an official boost library.
This library provides a set of easy to use coroutine primitives & utilities running on top of boost.asio.
These will be of interest for applications that perform a lot of IO that want to not block unnecessarily,
yet still want to have linear & readable code (i..e. avoid callbacks).
Expand Down
25 changes: 8 additions & 17 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
enable_testing()

add_library(static_tests concepts.cpp util.cpp )
target_link_libraries(static_tests Boost::headers)
add_library(boost_cobalt_static_tests concepts.cpp util.cpp)
target_link_libraries(boost_cobalt_static_tests Boost::headers)
target_compile_features(boost_cobalt_static_tests PUBLIC cxx_std_20)


add_executable(boost_cobalt_main main.cpp)
add_executable(boost_cobalt_main_compile main_compile.cpp)
Expand All @@ -10,22 +12,11 @@ add_executable(boost_cobalt_basic_tests
channel.cpp generator.cpp run.cpp task.cpp gather.cpp wait_group.cpp wrappers.cpp left_race.cpp
strand.cpp fork.cpp thread.cpp any_completion_handler.cpp detached.cpp monotonic_resource.cpp sbo_resource.cpp)

target_link_libraries(boost_cobalt_main Boost::cobalt OpenSSL::SSL)
target_link_libraries(boost_cobalt_main_compile Boost::cobalt OpenSSL::SSL)
target_link_libraries(boost_cobalt_basic_tests Boost::cobalt OpenSSL::SSL)
target_link_libraries(boost_cobalt_main Boost::cobalt)
target_link_libraries(boost_cobalt_main_compile Boost::cobalt)
target_link_libraries(boost_cobalt_basic_tests Boost::cobalt)

add_test(NAME boost_cobalt-main COMMAND boost_cobalt_main)
add_test(NAME boost_cobalt-basic_tests COMMAND boost_cobalt_basic_tests)
target_compile_features(boost_cobalt PUBLIC cxx_std_20)

file(GLOB ALL_PUBLIC_HEADERS RELATIVE ${CMAKE_SOURCE_DIR}/include/cobalt ${CMAKE_SOURCE_DIR}/include/boost/cobalt/*.hpp)
set(ALL_PUBLIC_HEADER_TESTS "")
foreach(HEADER ${ALL_PUBLIC_HEADERS})
get_filename_component(NAME ${HEADER} NAME_WLE)
set(FNAME "${CMAKE_CURRENT_BINARY_DIR}/test_include_${NAME}.cpp")
file(GENERATE OUTPUT ${FNAME}
CONTENT "#include <boost/cobalt/${NAME}.hpp>")
list(APPEND ALL_PUBLIC_HEADER_TESTS ${FNAME})
endforeach()

add_library(boost_cobalt_test_all_public_headers_test OBJECT ${ALL_PUBLIC_HEADER_TESTS})
target_link_libraries(boost_cobalt_test_all_public_headers_test PUBLIC Boost::headers)

0 comments on commit 6319f90

Please sign in to comment.