Skip to content

Commit

Permalink
Merge: Properly configure Coroutines cmake module
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurzam committed Oct 25, 2021
2 parents 294b8bf + 2f54023 commit 9de774c
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,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
Expand Down
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,20 @@ 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"
@ONLY)
configure_file(cmake/FindCoroutines.cmake
"${PROJECT_BINARY_DIR}/cppcoro/FindCoroutines.cmake"
COPYONLY)

set(config_package_location lib/cmake/cppcoro)
Expand Down
2 changes: 1 addition & 1 deletion cmake/cppcoroConfig.cmake
Original file line number Diff line number Diff line change
@@ -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")
69 changes: 69 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,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()
8 changes: 8 additions & 0 deletions test/use_cppcoro/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 17 additions & 0 deletions test/use_cppcoro/use_cppcoro.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <iostream>
#include <cppcoro/generator.hpp>

cppcoro::generator<int> sequence()
{
co_yield 1;
co_yield 22;
co_yield 333;
}

int main()
{
for (auto i : sequence())
{
std::cout << i << std::endl;
}
}

0 comments on commit 9de774c

Please sign in to comment.