Skip to content

Commit 9de774c

Browse files
committed
Merge: Properly configure Coroutines cmake module
andreasbuhr#34
2 parents 294b8bf + 2f54023 commit 9de774c

File tree

6 files changed

+105
-1
lines changed

6 files changed

+105
-1
lines changed

.github/workflows/cmake.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ jobs:
178178
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
179179
-DCMAKE_CXX_STANDARD=${{ matrix.config.cxxver }} \
180180
-DBUILD_TESTING=ON \
181+
-DCPPCORO_USAGE_TEST_DIR="${{runner.workspace}}/use_cppcoro" \
181182
-DCMAKE_CXX_FLAGS=${{ matrix.config.cxx_flags }} \
182183
-DCMAKE_EXE_LINKER_FLAGS=${{ matrix.config.exe_linker_flags }} \
183184
-DCMAKE_VERBOSE_MAKEFILE=ON

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,20 @@ if(BUILD_TESTING)
1818
add_subdirectory(test)
1919
endif()
2020

21+
if(CXX_COROUTINES_HEADER STREQUAL coroutine)
22+
set(CXX_COROUTINES_COMPONENT Final)
23+
else()
24+
set(CXX_COROUTINES_COMPONENT Experimental)
25+
endif()
26+
2127
export(EXPORT cppcoroTargets
2228
FILE "${PROJECT_BINARY_DIR}/cppcoro/cppcoroTargets.cmake"
2329
NAMESPACE cppcoro::)
2430
configure_file(cmake/cppcoroConfig.cmake
2531
"${PROJECT_BINARY_DIR}/cppcoro/cppcoroConfig.cmake"
32+
@ONLY)
33+
configure_file(cmake/FindCoroutines.cmake
34+
"${PROJECT_BINARY_DIR}/cppcoro/FindCoroutines.cmake"
2635
COPYONLY)
2736

2837
set(config_package_location lib/cmake/cppcoro)

cmake/cppcoroConfig.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
22

33
include(CMakeFindDependencyMacro)
4-
find_dependency(Coroutines QUIET REQUIRED)
4+
find_dependency(Coroutines QUIET REQUIRED COMPONENTS @CXX_COROUTINES_COMPONENT@)
55

66
include("${CMAKE_CURRENT_LIST_DIR}/cppcoroTargets.cmake")

test/CMakeLists.txt

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,72 @@ foreach(test ${tests})
7979
endif()
8080
doctest_discover_tests(${test_name} TEST_PREFIX ${test_prefix}- PROPERTIES TIMEOUT ${${test_name}_TIMEOUT})
8181
endforeach()
82+
83+
function(add_usage_test variant_name cppcoro_ROOT)
84+
set(APP_BINARY_DIR ${CPPCORO_USAGE_TEST_DIR}/app_build/${variant_name})
85+
add_test(
86+
NAME app_configure_${variant_name}
87+
COMMAND
88+
${CMAKE_COMMAND}
89+
-S ${CMAKE_CURRENT_LIST_DIR}/use_cppcoro
90+
-B ${APP_BINARY_DIR}
91+
-G ${CMAKE_GENERATOR}
92+
-D CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
93+
-D CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
94+
-D CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
95+
-D cppcoro_ROOT=${cppcoro_ROOT}
96+
)
97+
add_test(
98+
NAME app_build_${variant_name}
99+
COMMAND
100+
${CMAKE_COMMAND}
101+
--build ${APP_BINARY_DIR}
102+
--config ${CMAKE_BUILD_TYPE}
103+
)
104+
set_tests_properties(
105+
app_configure_${variant_name}
106+
PROPERTIES
107+
FIXTURES_SETUP app_build_${variant_name}_requires
108+
TIMEOUT 30
109+
)
110+
set_tests_properties(
111+
app_build_${variant_name}
112+
PROPERTIES
113+
FIXTURES_REQUIRED app_build_${variant_name}_requires
114+
TIMEOUT 30
115+
)
116+
endfunction()
117+
118+
if(CPPCORO_USAGE_TEST_DIR)
119+
if(NOT IS_ABSOLUTE ${CPPCORO_USAGE_TEST_DIR})
120+
set(CPPCORO_USAGE_TEST_DIR ${PROJECT_BINARY_DIR}/${CPPCORO_USAGE_TEST_DIR})
121+
endif()
122+
123+
add_usage_test(with_cppcoro_build_tree ${PROJECT_BINARY_DIR})
124+
125+
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.15)
126+
set(CPPCORO_USAGE_TEST_INSTALL_DIR ${CPPCORO_USAGE_TEST_DIR}/cppcoro_install)
127+
128+
add_usage_test(with_cppcoro_install_dir ${CPPCORO_USAGE_TEST_INSTALL_DIR})
129+
130+
add_test(
131+
NAME cppcoro_usage_test_install
132+
COMMAND
133+
${CMAKE_COMMAND}
134+
--install ${PROJECT_BINARY_DIR}
135+
--config ${CMAKE_BUILD_TYPE}
136+
--prefix ${CPPCORO_USAGE_TEST_INSTALL_DIR}
137+
)
138+
set_tests_properties(
139+
cppcoro_usage_test_install
140+
PROPERTIES
141+
FIXTURES_SETUP app_configure_with_cppcoro_install_dir_requires
142+
TIMEOUT 30
143+
)
144+
set_tests_properties(
145+
app_configure_with_cppcoro_install_dir
146+
PROPERTIES
147+
FIXTURES_REQUIRED app_configure_with_cppcoro_install_dir_requires
148+
)
149+
endif()
150+
endif()

test/use_cppcoro/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
project(use_cppcoro LANGUAGES CXX)
3+
4+
set(CMAKE_CXX_STANDARD 20)
5+
find_package(cppcoro REQUIRED)
6+
7+
add_executable(use_cppcoro use_cppcoro.cpp)
8+
target_link_libraries(use_cppcoro PRIVATE cppcoro::cppcoro)

test/use_cppcoro/use_cppcoro.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <iostream>
2+
#include <cppcoro/generator.hpp>
3+
4+
cppcoro::generator<int> sequence()
5+
{
6+
co_yield 1;
7+
co_yield 22;
8+
co_yield 333;
9+
}
10+
11+
int main()
12+
{
13+
for (auto i : sequence())
14+
{
15+
std::cout << i << std::endl;
16+
}
17+
}

0 commit comments

Comments
 (0)