From b54bb8014790edfd4ba98766717ae2ddf158040c Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Mon, 13 Nov 2017 13:32:16 +0100 Subject: [PATCH] Rename and cleanup some CMake options --- .travis.yml | 5 ++++- CMakeLists.txt | 43 +++++++++++++++++++++++++++----------- appveyor.yml | 5 ++++- cmake/compiler/clang.cmake | 4 ++-- cmake/compiler/gcc.cmake | 2 +- cmake/compiler/msvc.cmake | 4 ++-- dep/CMakeLists.txt | 26 ++++++++++++----------- 7 files changed, 58 insertions(+), 31 deletions(-) diff --git a/.travis.yml b/.travis.yml index d9b3e9f..3aa3fc5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,7 @@ matrix: env: - COMPILER=g++-6 - NO_EXCEPTIONS=OFF + - WITH_AWAIT=OFF - os: linux compiler: clang @@ -40,6 +41,7 @@ matrix: env: - COMPILER=clang++-5.0 - NO_EXCEPTIONS=OFF + - WITH_AWAIT=OFF - os: linux compiler: clang @@ -57,6 +59,7 @@ matrix: env: - COMPILER=clang++-5.0 - NO_EXCEPTIONS=ON + - WITH_AWAIT=ON install: - export CXX=$COMPILER @@ -74,7 +77,7 @@ install: cd build # Configure the project and build it - cmake -GNinja -DCMAKE_CXX_FLAGS="$CMAKE_CXX_FLAGS -Werror" -DTESTS_NO_EXCEPTIONS=$NO_EXCEPTIONS -DCMAKE_BUILD_TYPE=Debug .. + cmake -GNinja -DCMAKE_CXX_FLAGS="$CMAKE_CXX_FLAGS -Werror" -DCTI_CONTINUABLE_WITH_NO_EXCEPTIONS=$NO_EXCEPTIONS -DCTI_CONTINUABLE_WITH_AWAIT=$WITH_AWAIT -DCMAKE_BUILD_TYPE=Debug .. } script: diff --git a/CMakeLists.txt b/CMakeLists.txt index cea2c18..9e536db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,16 +1,30 @@ cmake_minimum_required(VERSION 3.2) project(continuable VERSION 2.0.0 LANGUAGES C CXX) -# Dependencies +string(COMPARE EQUAL ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR} + IS_TOP_LEVEL_PROJECT) + +option(CTI_CONTINUABLE_WITH_TESTS + "Build the continuable unit tests" + ${IS_TOP_LEVEL_PROJECT}) + +option(CTI_CONTINUABLE_WITH_EXAMPLES + "Build the continuable examples" + ${IS_TOP_LEVEL_PROJECT}) + +option(CTI_CONTINUABLE_WITH_NO_EXCEPTIONS + "Disable exception support" + OFF) + +option(CTI_CONTINUABLE_WITH_AWAIT + "Enable co_await support" + OFF) + +include(cmake/CMakeLists.txt) + set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) -if (NOT DEFINED CONTINUABLE_UNIT_TESTS - AND CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) - set(CONTINUABLE_UNIT_TESTS ON) -endif() - -include(cmake/CMakeLists.txt) add_subdirectory(dep) # continuable-base @@ -73,11 +87,10 @@ set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH}) - include(CPack) -# Testing -if (CONTINUABLE_UNIT_TESTS) +# Testing and examples +if (CTI_CONTINUABLE_WITH_TESTS OR CTI_CONTINUABLE_WITH_EXAMPLES) if (MSVC) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") @@ -88,6 +101,12 @@ if (CONTINUABLE_UNIT_TESTS) enable_testing() add_subdirectory(doc) - add_subdirectory(examples) - add_subdirectory(test) + + if (CTI_CONTINUABLE_WITH_TESTS) + add_subdirectory(test) + endif() + + if (CTI_CONTINUABLE_WITH_EXAMPLES) + add_subdirectory(examples) + endif() endif () diff --git a/appveyor.yml b/appveyor.yml index 738ca1a..7bfcbcb 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -19,7 +19,10 @@ clone_script: - cmd: git submodule update --init --recursive before_build: - - cmd: cmake -H. -Bbuild -A%PLATFORM% -DTESTS_NO_EXCEPTIONS=%NO_EXCEPTIONS% + - cmd: > + cmake -H. -Bbuild -A%PLATFORM% + -DCTI_CONTINUABLE_WITH_NO_EXCEPTIONS=%NO_EXCEPTIONS% + -DCTI_CONTINUABLE_WITH_AWAIT=ON build_script: - cmd: cmake --build build --config %CONFIGURATION% --target ALL_BUILD -- /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" /verbosity:minimal /maxcpucount:2 /nologo diff --git a/cmake/compiler/clang.cmake b/cmake/compiler/clang.cmake index 6abe566..5c964ec 100644 --- a/cmake/compiler/clang.cmake +++ b/cmake/compiler/clang.cmake @@ -5,7 +5,7 @@ target_compile_options(continuable-features-warnings -pedantic -Wextra) -if (WITH_COROUTINES) +if (CTI_CONTINUABLE_WITH_AWAIT) target_compile_options(continuable-coroutines INTERFACE -fcoroutines-ts) @@ -15,7 +15,7 @@ if (WITH_COROUTINES) -DCONTINUABLE_HAS_EXPERIMENTAL_COROUTINE) endif() -if (TESTS_NO_EXCEPTIONS) +if (CTI_CONTINUABLE_WITH_NO_EXCEPTIONS) target_compile_options(continuable-features-noexcept INTERFACE -fno-exceptions) diff --git a/cmake/compiler/gcc.cmake b/cmake/compiler/gcc.cmake index 7eb1f01..4eaefc1 100644 --- a/cmake/compiler/gcc.cmake +++ b/cmake/compiler/gcc.cmake @@ -5,7 +5,7 @@ target_compile_options(continuable-features-warnings -pedantic -Wextra) -if (TESTS_NO_EXCEPTIONS) +if (CTI_CONTINUABLE_WITH_NO_EXCEPTIONS) target_compile_options(continuable-features-noexcept INTERFACE -fno-exceptions) diff --git a/cmake/compiler/msvc.cmake b/cmake/compiler/msvc.cmake index 4ebc810..753469b 100644 --- a/cmake/compiler/msvc.cmake +++ b/cmake/compiler/msvc.cmake @@ -19,7 +19,7 @@ target_compile_options(continuable-features-warnings INTERFACE /W4) -if (WITH_COROUTINES) +if (CTI_CONTINUABLE_WITH_AWAIT) target_compile_options(continuable-coroutines INTERFACE /await) @@ -29,7 +29,7 @@ if (WITH_COROUTINES) -DCONTINUABLE_HAS_EXPERIMENTAL_COROUTINE) endif() -if (TESTS_NO_EXCEPTIONS) +if (CTI_CONTINUABLE_WITH_NO_EXCEPTIONS) target_compile_definitions(continuable-features-noexcept INTERFACE -D_HAS_EXCEPTIONS=0) diff --git a/dep/CMakeLists.txt b/dep/CMakeLists.txt index 4126ad9..5f5344b 100644 --- a/dep/CMakeLists.txt +++ b/dep/CMakeLists.txt @@ -1,15 +1,17 @@ -if(CONTINUABLE_UNIT_TESTS AND NOT TARGET gtest) - add_subdirectory(googletest) -endif() - -if(CONTINUABLE_UNIT_TESTS AND NOT TARGET cxx_function) - add_subdirectory(cxx_function) -endif() - -if(CONTINUABLE_UNIT_TESTS AND NOT TARGET asio) - add_subdirectory(asio) -endif() - if(NOT TARGET function2) add_subdirectory(function2) endif() + +if (CTI_CONTINUABLE_WITH_TESTS OR CTI_CONTINUABLE_WITH_EXAMPLES) + if(NOT TARGET gtest) + add_subdirectory(googletest) + endif() + + if(NOT TARGET cxx_function) + add_subdirectory(cxx_function) + endif() + + if(NOT TARGET asio) + add_subdirectory(asio) + endif() +endif()