diff --git a/.gitignore b/.gitignore index a829fe81..ea42cf23 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /.vs +.cache/ /build-*/ /build/* !/build/Jamfile diff --git a/CMakeLists.txt b/CMakeLists.txt index 033c3c2b..8ce984e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,12 +10,6 @@ # Official repository: https://github.com/cppalliance/capy # -#------------------------------------------------- -# -# Project -# -#------------------------------------------------- - cmake_minimum_required(VERSION 3.8...3.31) set(BOOST_CAPY_VERSION 1) @@ -29,23 +23,14 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) endif () set(__ignore__ ${CMAKE_C_COMPILER}) -#------------------------------------------------- -# -# Options -# -#------------------------------------------------- -if (BOOST_CAPY_IS_ROOT) +option(BOOST_CAPY_BUILD_TESTS "Build boost::capy tests" ${BOOST_CAPY_IS_ROOT}) +if (BOOST_CAPY_BUILD_TESTS) include(CTest) endif () -option(BOOST_CAPY_BUILD_TESTS "Build boost::capy tests" ${BUILD_TESTING}) option(BOOST_CAPY_BUILD_EXAMPLES "Build boost::capy examples" ${BOOST_CAPY_IS_ROOT}) +option(BOOST_CAPY_BUILD_BENCH "Build boost::capy benchmarks" ${BOOST_CAPY_IS_ROOT}) option(BOOST_CAPY_MRDOCS_BUILD "Build the target for MrDocs: see mrdocs.yml" OFF) -#------------------------------------------------- -# -# Library -# -#------------------------------------------------- set_property(GLOBAL PROPERTY USE_FOLDERS ON) file(GLOB_RECURSE BOOST_CAPY_HEADERS CONFIGURE_DEPENDS include/boost/*.hpp include/boost/*.natvis) @@ -57,8 +42,11 @@ source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src PREFIX "src" FILES ${BOOST_CAP function(boost_capy_setup_properties target) target_compile_features(${target} PUBLIC cxx_std_20) - target_include_directories(${target} PUBLIC "${PROJECT_SOURCE_DIR}/include") - target_include_directories(${target} PRIVATE "${PROJECT_SOURCE_DIR}") + target_include_directories(${target} PUBLIC + $ + $) + target_include_directories(${target} PRIVATE + $) target_compile_definitions(${target} PUBLIC BOOST_CAPY_NO_LIB) target_compile_definitions(${target} PRIVATE BOOST_CAPY_SOURCE) if (BUILD_SHARED_LIBS) @@ -84,32 +72,57 @@ boost_capy_setup_properties(boost_capy) # Disable IPO/LTCG - causes LNK2016 errors with MSVC set_target_properties(boost_capy PROPERTIES + EXPORT_NAME capy INTERPROCEDURAL_OPTIMIZATION OFF INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO OFF INTERPROCEDURAL_OPTIMIZATION_MINSIZEREL OFF) -#------------------------------------------------- -# -# Benchmarks -# -#------------------------------------------------- -add_subdirectory(bench) +if(BOOST_SUPERPROJECT_VERSION AND NOT CMAKE_VERSION VERSION_LESS 3.13) + boost_install( + TARGETS boost_capy + VERSION ${BOOST_SUPERPROJECT_VERSION} + HEADER_DIRECTORY include) +else() + include(GNUInstallDirs) + include(CMakePackageConfigHelpers) + + set(BOOST_CAPY_INSTALL_CMAKEDIR + ${CMAKE_INSTALL_LIBDIR}/cmake/boost_capy) + + install(TARGETS boost_capy + EXPORT boost_capy-targets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + install(DIRECTORY include/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + install(EXPORT boost_capy-targets + NAMESPACE Boost:: + DESTINATION ${BOOST_CAPY_INSTALL_CMAKEDIR}) + + configure_package_config_file( + cmake/boost_capy-config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/boost_capy-config.cmake + INSTALL_DESTINATION ${BOOST_CAPY_INSTALL_CMAKEDIR}) + write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/boost_capy-config-version.cmake + COMPATIBILITY SameMajorVersion) + + install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/boost_capy-config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/boost_capy-config-version.cmake + DESTINATION ${BOOST_CAPY_INSTALL_CMAKEDIR}) +endif() + +if(BOOST_CAPY_BUILD_BENCH) + add_subdirectory(bench) +endif() -#------------------------------------------------- -# -# Examples (before tests so Boost::asio is available) -# -#------------------------------------------------- if (BOOST_CAPY_BUILD_EXAMPLES) add_subdirectory(example) endif () -#------------------------------------------------- -# -# Tests -# -#------------------------------------------------- if (BOOST_CAPY_BUILD_TESTS) add_subdirectory(test) endif () diff --git a/CMakePresets.json b/CMakePresets.json deleted file mode 100644 index eafecbdf..00000000 --- a/CMakePresets.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "version": 6, - "cmakeMinimumRequired": { - "major": 3, - "minor": 20, - "patch": 0 - }, - "configurePresets": [ - { - "name": "standalone", - "displayName": "Standalone Build", - "description": "Build capy standalone (no Boost tree required)", - "generator": "Ninja", - "binaryDir": "${sourceDir}/out/${presetName}", - "cacheVariables": { - "CMAKE_CXX_STANDARD": "20", - "CMAKE_BUILD_TYPE": "Release", - "BOOST_CAPY_BUILD_TESTS": "OFF", - "BOOST_CAPY_BUILD_EXAMPLES": "OFF" - } - } - ], - "buildPresets": [ - { - "name": "standalone", - "configurePreset": "standalone" - } - ] -} diff --git a/README.md b/README.md index caf6ff02..cffa4277 100644 --- a/README.md +++ b/README.md @@ -11,16 +11,30 @@ This library provides facilities which use C++20 coroutines to perform I/O. It i ## Quick Start -Clone and build with CMake: +### Standalone build ```bash git clone https://github.com/cppalliance/capy.git cd capy -cmake --preset standalone -cmake --build --preset standalone +cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release +cmake --build build ``` -The library is built to `out/standalone/`. +### Consume via CMake + +Use `FetchContent` or `add_subdirectory` to add capy to your project, +then link against `Boost::capy`: + +```cmake +include(FetchContent) +FetchContent_Declare(capy + GIT_REPOSITORY https://github.com/cppalliance/capy.git + GIT_TAG develop + GIT_SHALLOW TRUE) +FetchContent_MakeAvailable(capy) + +target_link_libraries(my_app Boost::capy) +``` ## Related Libraries diff --git a/cmake/boost_capy-config.cmake.in b/cmake/boost_capy-config.cmake.in new file mode 100644 index 00000000..4d76299a --- /dev/null +++ b/cmake/boost_capy-config.cmake.in @@ -0,0 +1,3 @@ +@PACKAGE_INIT@ +include("${CMAKE_CURRENT_LIST_DIR}/boost_capy-targets.cmake") +check_required_components(boost_capy)