diff --git a/CMakeLists.txt b/CMakeLists.txt index e87dc5d42..9ae670536 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -418,18 +418,22 @@ if (STDEXEC_ENABLE_NUMA) target_compile_definitions(stdexec INTERFACE STDEXEC_ENABLE_NUMA) endif() -set(SYSTEM_CONTEXT_SOURCES src/system_context/system_context.cpp) -add_library(system_context ${SYSTEM_CONTEXT_SOURCES}) -target_compile_features(system_context PUBLIC cxx_std_20) -set_target_properties(system_context PROPERTIES - CXX_STANDARD 20 - CXX_STANDARD_REQUIRED ON - CXX_EXTENSIONS OFF) -target_compile_options(system_context PUBLIC - $<$:/Zc:__cplusplus /Zc:preprocessor /Zc:externConstexpr> - ) -add_library(STDEXEC::system_context ALIAS system_context) -target_link_libraries(system_context PUBLIC stdexec) +option(STDEXEC_BUILD_SYSTEM_CONTEXT "Build the system_context compiled library" OFF) + +if(STDEXEC_BUILD_SYSTEM_CONTEXT) + set(SYSTEM_CONTEXT_SOURCES src/system_context/system_context.cpp) + add_library(system_context ${SYSTEM_CONTEXT_SOURCES}) + target_compile_features(system_context PUBLIC cxx_std_20) + set_target_properties(system_context PROPERTIES + CXX_STANDARD 20 + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS OFF) + target_compile_options(system_context PUBLIC + $<$:/Zc:__cplusplus /Zc:preprocessor /Zc:externConstexpr> + ) + add_library(STDEXEC::system_context ALIAS system_context) + target_link_libraries(system_context PUBLIC stdexec) +endif() option(STDEXEC_ENABLE_IO_URING "Enable the use of the io_uring scheduler on Linux" OFF) @@ -495,7 +499,12 @@ endif() include(CPack) -install(TARGETS stdexec system_context +set(stdexec_install_targets stdexec) +if(STDEXEC_BUILD_SYSTEM_CONTEXT) + list(APPEND stdexec_install_targets system_context) +endif() + +install(TARGETS ${stdexec_install_targets} EXPORT stdexec-exports FILE_SET headers FILE_SET version_config) diff --git a/conanfile.py b/conanfile.py index d128d2952..d75bd888d 100644 --- a/conanfile.py +++ b/conanfile.py @@ -14,6 +14,12 @@ class StdexecPackage(ConanFile): license = "Apache 2.0" settings = "os", "arch", "compiler", "build_type" + options = { + "system_context": [True, False], + } + default_options = { + "system_context": False, + } exports_sources = ( "include/*", "src/*", @@ -24,6 +30,12 @@ class StdexecPackage(ConanFile): ) generators = "CMakeToolchain" + def configure(self): + if self.options.system_context: + self.package_type = "static-library" + else: + self.package_type = "header-library" + def validate(self): check_min_cppstd(self, "20") @@ -37,18 +49,21 @@ def layout(self): def build(self): tests = "OFF" if self.conf.get("tools.build:skip_test", default=False) else "ON" + system_context = "ON" if self.options.system_context else "OFF" cmake = CMake(self) cmake.configure(variables={ "STDEXEC_BUILD_TESTS": tests, "STDEXEC_BUILD_EXAMPLES": tests, + "STDEXEC_BUILD_SYSTEM_CONTEXT": system_context, }) cmake.build() cmake.test() def package_id(self): - # Clear settings because this package is header-only. - self.info.clear() + if not self.info.options.system_context: + # Clear settings because this package is header-only. + self.info.clear() def package(self): cmake = CMake(self) @@ -58,4 +73,8 @@ def package_info(self): self.cpp_info.set_property("cmake_file_name", "P2300") self.cpp_info.set_property("cmake_target_name", "P2300::P2300") self.cpp_info.set_property("cmake_target_aliases", ["STDEXEC::stdexec"]) - self.cpp_info.libs = ["system_context"] + if self.options.system_context: + self.cpp_info.components["system_context"].libs = ["system_context"] + self.cpp_info.components["system_context"].set_property( + "cmake_target_name", "STDEXEC::system_context" + ) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7d0eb9dfb..6f3470f9d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -99,17 +99,19 @@ target_link_libraries(test.stdexec PRIVATE common_test_settings) -add_executable(test.system_context_replaceability - test_main.cpp - stdexec/schedulers/test_system_context_replaceability.cpp) -target_link_libraries(test.system_context_replaceability - PUBLIC - STDEXEC::stdexec - STDEXEC::system_context - stdexec_executable_flags - Catch2::Catch2 - PRIVATE - common_test_settings) +if(STDEXEC_BUILD_SYSTEM_CONTEXT) + add_executable(test.system_context_replaceability + test_main.cpp + stdexec/schedulers/test_system_context_replaceability.cpp) + target_link_libraries(test.system_context_replaceability + PUBLIC + STDEXEC::stdexec + STDEXEC::system_context + stdexec_executable_flags + Catch2::Catch2 + PRIVATE + common_test_settings) +endif() add_executable(test.scratch test_main.cpp test_scratch.cpp) target_link_libraries(test.scratch @@ -129,7 +131,7 @@ include(${icm_SOURCE_DIR}/icm_build_failure_testing.cmake) catch_discover_tests(test.stdexec) catch_discover_tests(test.scratch) -if(NOT STDEXEC_ENABLE_CUDA) +if(STDEXEC_BUILD_SYSTEM_CONTEXT AND NOT STDEXEC_ENABLE_CUDA) catch_discover_tests(test.system_context_replaceability) endif() diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt index 37526bd79..d7fe2f6bd 100644 --- a/test_package/CMakeLists.txt +++ b/test_package/CMakeLists.txt @@ -5,5 +5,8 @@ enable_testing() find_package(P2300 REQUIRED) add_executable(test_stdexec test.cpp) -target_link_libraries(test_stdexec STDEXEC::stdexec) +target_link_libraries(test_stdexec STDEXEC::stdexec $) +if(TARGET STDEXEC::system_context) + target_compile_definitions(test_stdexec PRIVATE STDEXEC_TEST_SYSTEM_CONTEXT) +endif() add_test(test_stdexec test_stdexec) diff --git a/test_package/test.cpp b/test_package/test.cpp index a693c9618..667a1afdb 100644 --- a/test_package/test.cpp +++ b/test_package/test.cpp @@ -1,11 +1,20 @@ +#ifdef STDEXEC_TEST_SYSTEM_CONTEXT #include +#else +#include +#endif #include #include int main() { +#ifdef STDEXEC_TEST_SYSTEM_CONTEXT auto x = stdexec::starts_on(exec::get_parallel_scheduler(), stdexec::just(42)); +#else + exec::static_thread_pool pool{1}; + auto x = stdexec::starts_on(pool.get_scheduler(), stdexec::just(42)); +#endif auto [a] = stdexec::sync_wait(std::move(x)).value(); return a == 42 ? EXIT_SUCCESS : EXIT_FAILURE; }