From ede6e6958ee050f2583529c216fc49e71507f4ac Mon Sep 17 00:00:00 2001 From: Alexander Karzhenkov Date: Sat, 23 Jan 2021 16:30:47 +0500 Subject: [PATCH 1/3] Add library usage test --- .github/workflows/cmake.yml | 1 + test/CMakeLists.txt | 69 ++++++++++++++++++++++++++++++++ test/use_cppcoro/CMakeLists.txt | 8 ++++ test/use_cppcoro/use_cppcoro.cpp | 17 ++++++++ 4 files changed, 95 insertions(+) create mode 100644 test/use_cppcoro/CMakeLists.txt create mode 100644 test/use_cppcoro/use_cppcoro.cpp diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 4f571745..d8333601 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -176,6 +176,7 @@ jobs: -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ -DCMAKE_CXX_STANDARD=${{ matrix.config.cxxver }} \ -DBUILD_TESTING=ON \ + -DCPPCORO_USAGE_TEST_DIR="${{runner.workspace}}/use_cppcoro" \ -DCMAKE_CXX_FLAGS=${{ matrix.config.cxx_flags }} \ -DCMAKE_EXE_LINKER_FLAGS=${{ matrix.config.exe_linker_flags }} \ -DCMAKE_VERBOSE_MAKEFILE=ON diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f5afecd1..fe05c552 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -60,3 +60,72 @@ foreach(test ${tests}) endif() doctest_discover_tests(${test_name} TEST_PREFIX ${test_prefix}- PROPERTIES TIMEOUT ${${test_name}_TIMEOUT}) endforeach() + +function(add_usage_test variant_name cppcoro_ROOT) + set(APP_BINARY_DIR ${CPPCORO_USAGE_TEST_DIR}/app_build/${variant_name}) + add_test( + NAME app_configure_${variant_name} + COMMAND + ${CMAKE_COMMAND} + -S ${CMAKE_CURRENT_LIST_DIR}/use_cppcoro + -B ${APP_BINARY_DIR} + -G ${CMAKE_GENERATOR} + -D CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -D CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -D CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} + -D cppcoro_ROOT=${cppcoro_ROOT} + ) + add_test( + NAME app_build_${variant_name} + COMMAND + ${CMAKE_COMMAND} + --build ${APP_BINARY_DIR} + --config ${CMAKE_BUILD_TYPE} + ) + set_tests_properties( + app_configure_${variant_name} + PROPERTIES + FIXTURES_SETUP app_build_${variant_name}_requires + TIMEOUT 30 + ) + set_tests_properties( + app_build_${variant_name} + PROPERTIES + FIXTURES_REQUIRED app_build_${variant_name}_requires + TIMEOUT 30 + ) +endfunction() + +if(CPPCORO_USAGE_TEST_DIR) + if(NOT IS_ABSOLUTE ${CPPCORO_USAGE_TEST_DIR}) + set(CPPCORO_USAGE_TEST_DIR ${PROJECT_BINARY_DIR}/${CPPCORO_USAGE_TEST_DIR}) + endif() + + add_usage_test(with_cppcoro_build_tree ${PROJECT_BINARY_DIR}) + + if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.15) + set(CPPCORO_USAGE_TEST_INSTALL_DIR ${CPPCORO_USAGE_TEST_DIR}/cppcoro_install) + + add_usage_test(with_cppcoro_install_dir ${CPPCORO_USAGE_TEST_INSTALL_DIR}) + + add_test( + NAME cppcoro_usage_test_install + COMMAND + ${CMAKE_COMMAND} + --install ${PROJECT_BINARY_DIR} + --config ${CMAKE_BUILD_TYPE} + --prefix ${CPPCORO_USAGE_TEST_INSTALL_DIR} + ) + set_tests_properties( + cppcoro_usage_test_install + PROPERTIES + FIXTURES_SETUP app_configure_with_cppcoro_install_dir_requires + TIMEOUT 30 + ) + set_tests_properties( + app_configure_with_cppcoro_install_dir + PROPERTIES + FIXTURES_REQUIRED app_configure_with_cppcoro_install_dir_requires + ) + endif() +endif() diff --git a/test/use_cppcoro/CMakeLists.txt b/test/use_cppcoro/CMakeLists.txt new file mode 100644 index 00000000..2b51f088 --- /dev/null +++ b/test/use_cppcoro/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.12) +project(use_cppcoro LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 20) +find_package(cppcoro REQUIRED) + +add_executable(use_cppcoro use_cppcoro.cpp) +target_link_libraries(use_cppcoro PRIVATE cppcoro::cppcoro) diff --git a/test/use_cppcoro/use_cppcoro.cpp b/test/use_cppcoro/use_cppcoro.cpp new file mode 100644 index 00000000..53551765 --- /dev/null +++ b/test/use_cppcoro/use_cppcoro.cpp @@ -0,0 +1,17 @@ +#include +#include + +cppcoro::generator sequence() +{ + co_yield 1; + co_yield 22; + co_yield 333; +} + +int main() +{ + for (auto i : sequence()) + { + std::cout << i << std::endl; + } +} From aebd1a2a94456f2572d03308593ba27095752fd9 Mon Sep 17 00:00:00 2001 From: Alexander Karzhenkov Date: Sat, 23 Jan 2021 16:30:48 +0500 Subject: [PATCH 2/3] Allow using cppcore directly from build tree --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ce73ea4..005d0827 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,9 @@ export(EXPORT cppcoroTargets configure_file(cmake/cppcoroConfig.cmake "${PROJECT_BINARY_DIR}/cppcoro/cppcoroConfig.cmake" COPYONLY) +configure_file(cmake/FindCoroutines.cmake + "${PROJECT_BINARY_DIR}/cppcoro/FindCoroutines.cmake" + COPYONLY) set(config_package_location lib/cmake/cppcoro) install(DIRECTORY include/cppcoro From 2f54023f5148ac13bb825c61fc568cb26a61978b Mon Sep 17 00:00:00 2001 From: Alexander Karzhenkov Date: Sat, 23 Jan 2021 16:30:48 +0500 Subject: [PATCH 3/3] Properly configure installed Coroutines module --- CMakeLists.txt | 8 +++++++- cmake/cppcoroConfig.cmake | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 005d0827..d5bbfc57 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,12 +18,18 @@ if(BUILD_TESTING) add_subdirectory(test) endif() +if(CXX_COROUTINES_HEADER STREQUAL coroutine) + set(CXX_COROUTINES_COMPONENT Final) +else() + set(CXX_COROUTINES_COMPONENT Experimental) +endif() + export(EXPORT cppcoroTargets FILE "${PROJECT_BINARY_DIR}/cppcoro/cppcoroTargets.cmake" NAMESPACE cppcoro::) configure_file(cmake/cppcoroConfig.cmake "${PROJECT_BINARY_DIR}/cppcoro/cppcoroConfig.cmake" - COPYONLY) + @ONLY) configure_file(cmake/FindCoroutines.cmake "${PROJECT_BINARY_DIR}/cppcoro/FindCoroutines.cmake" COPYONLY) diff --git a/cmake/cppcoroConfig.cmake b/cmake/cppcoroConfig.cmake index 0b9f9c0b..0ab5ce1c 100644 --- a/cmake/cppcoroConfig.cmake +++ b/cmake/cppcoroConfig.cmake @@ -1,6 +1,6 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}) include(CMakeFindDependencyMacro) -find_dependency(Coroutines QUIET REQUIRED) +find_dependency(Coroutines QUIET REQUIRED COMPONENTS @CXX_COROUTINES_COMPONENT@) include("${CMAKE_CURRENT_LIST_DIR}/cppcoroTargets.cmake")