Skip to content

Commit

Permalink
Better Cmake script (#14)
Browse files Browse the repository at this point in the history
* better cmake script

* yaml syntax

* valid CI config
  • Loading branch information
FrancoisChabot authored Jun 10, 2019
1 parent 8217485 commit ad2e59b
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 41 deletions.
42 changes: 38 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 2
version: 2.1
jobs:
build:
debug_build:
docker:
- image: francoischabot/easy_grpc_buildenv:latest

Expand All @@ -12,7 +12,7 @@ jobs:
command: |
mkdir _bld
cd _bld
cmake -DCMAKE_BUILD_TYPE=Debug -DCOVERAGE=1 ..
cmake -DVAR_FUTURES_BUILD_EXAMPLES=ON -DVAR_FUTURES_BUILD_TESTS=ON -DVAR_FUTURES_TEST_COVERAGE=ON -DCMAKE_BUILD_TYPE=Debug ..
- run:
name: Build
Expand All @@ -31,4 +31,38 @@ jobs:
command: |
cd _bld
make coverage
bash <(curl -s https://codecov.io/bash) -f coverage.info || echo "Codecov did not collect coverage reports"
bash <(curl -s https://codecov.io/bash) -f coverage.info || echo "Codecov did not collect coverage reports"
release_build:
docker:
- image: francoischabot/easy_grpc_buildenv:latest

steps:
- checkout

- run:
name: Create build script
command: |
mkdir _bld
cd _bld
cmake -DVAR_FUTURES_BUILD_EXAMPLES=ON -DVAR_FUTURES_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release ..
- run:
name: Build
command: |
cd _bld
make -j $(nproc)
- run:
name: Test
command: |
cd _bld
ctest -j $(nproc) -T memcheck
workflows:
version: 2
build_and_test:
jobs:
- debug_build
- release_build

112 changes: 79 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
cmake_minimum_required(VERSION 3.10)

project(easy_grpc VERSION 0.0.1)
project(var_future VERSION 0.1.0)

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
include(GNUInstallDirs)

SET(COVERAGE OFF CACHE BOOL "Coverage")
# Check if var_futures is being used directly or via add_subdirectory, but allow overriding
if (NOT DEFINED VAR_FUTURES_MASTER_PROJECT)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(VAR_FUTURES_MASTER_PROJECT ON)
else()
set(VAR_FUTURES_MASTER_PROJECT OFF)
endif()
endif ()

option(VAR_FUTURES_BUILD_EXAMPLES "var_futures examples" OFF)
option(VAR_FUTURES_BUILD_TESTS "var_futures tests" OFF)
option(VAR_FUTURES_TEST_COVERAGE "var_futures Coverage" OFF)
option(VAR_FUTURES_INSTALL "Generate the install target" ${VAR_FUTURES_MASTER_PROJECT})

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
if(CMAKE_COMPILER_IS_GNUCXX)
include(CodeCoverage)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
set(COVERAGE_LCOV_EXCLUDES
'/usr/*'
)
APPEND_COVERAGE_COMPILER_FLAGS()
find_package(Threads REQUIRED)

if(VAR_FUTURES_TEST_COVERAGE)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
if(CMAKE_COMPILER_IS_GNUCXX)
include(CodeCoverage)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
set(COVERAGE_LCOV_EXCLUDES
'/usr/*'
)
APPEND_COVERAGE_COMPILER_FLAGS()
endif()
endif()

include(CTest)
Expand All @@ -27,34 +41,66 @@ include(GoogleTest)
find_package(GTest REQUIRED CONFIG)

add_library(var_futures INTERFACE)
target_include_directories(var_futures INTERFACE . include)
target_include_directories(var_futures INTERFACE
$<BUILD_INTERFACE:. include>
$<INSTALL_INTERFACE:include>
)
target_compile_features(var_futures INTERFACE cxx_std_17)

add_executable(futures_test
tests/async.cpp
tests/int.cpp
tests/misc.cpp
tests/void.cpp)
if(${VAR_FUTURES_INSTALL})
set(export_dest_dir "${CMAKE_INSTALL_LIBDIR}/spdlog/cmake")

install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(TARGETS var_futures
EXPORT var_futuresTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

#install cmake export
install(EXPORT var_futuresTargets DESTINATION ${export_dest_dir})

configure_file(cmake/var_futures-config.cmake.in
"${PROJECT_BINARY_DIR}/var_futures-config.cmake" @ONLY)

if(MSVC)
target_compile_options(futures_test PUBLIC /W4 /WX)
else()
target_compile_options(futures_test PUBLIC -Wall -Wextra -pedantic -Werror)
install(FILES "${PROJECT_BINARY_DIR}/var_futures-config.cmake" DESTINATION "${export_dest_dir}")
endif()

target_link_libraries(futures_test var_futures GTest::gtest_main GTest::gtest --coverage)

if(VAR_FUTURES_BUILD_TESTS)
add_executable(futures_test
tests/async.cpp
tests/int.cpp
tests/misc.cpp
tests/void.cpp)

include(ProcessorCount)
ProcessorCount(PROCESSOR_COUNT)
if(MSVC)
target_compile_options(futures_test PUBLIC /W4 /WX)
else()
target_compile_options(futures_test PUBLIC -Wall -Wextra -pedantic -Werror)
endif()

if(CMAKE_COMPILER_IS_GNUCXX)
setup_target_for_coverage_lcov(
NAME coverage
EXECUTABLE ctest -j ${PROCESSOR_COUNT}
DEPENDENCIES futures_test)
target_link_libraries(futures_test var_futures GTest::gtest_main GTest::gtest --coverage)


include(ProcessorCount)
ProcessorCount(PROCESSOR_COUNT)

if(VAR_FUTURES_TEST_COVERAGE)
if(CMAKE_COMPILER_IS_GNUCXX)
setup_target_for_coverage_lcov(
NAME coverage
EXECUTABLE ctest -j ${PROCESSOR_COUNT}
DEPENDENCIES futures_test)
endif()
endif()

gtest_discover_tests(futures_test)
endif()

gtest_discover_tests(futures_test)
if(VAR_FUTURES_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()



add_subdirectory(examples)
3 changes: 3 additions & 0 deletions cmake/var_futures-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
get_filename_component(VAR_FUTURES_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)

include("${VAR_FUTURES_CMAKE_DIR}/var_futuresTargets.cmake")
12 changes: 8 additions & 4 deletions include/var_future/impl/storage_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,17 @@ class Future_storage {

static bool is_ready_state(State v);

// Calculate how much memory we want to reserve for the eventual callback
static constexpr std::size_t soo_space =
std::min(std::size_t(var_fut_min_soo_size),
std::max({sizeof(fullfill_type), sizeof(finish_type),
sizeof(fail_type)}) -
sizeof(Future_handler_iface<Ts...>*));

// The SSO buffer is a parent class so that we can get zero-size base
// optimization.

struct Callback_data {
Future_handler_iface<Ts...>* callback_;
// This will either point to soo_buffer_, or heap-allocated data, depending on state_.
Future_handler_iface<Ts...>* callback_;
typename std::aligned_storage<soo_space>::type soo_buffer_;
};

Expand All @@ -144,7 +145,10 @@ class Future_storage {
template <typename T>
struct Storage_ptr {
Storage_ptr() = default;
Storage_ptr(T* val) : ptr_(val) { ++(ptr_->ref_count_); }
Storage_ptr(T* val) : ptr_(val) {
assert(val);
++(ptr_->ref_count_);
}

Storage_ptr(const Storage_ptr& rhs) : ptr_(rhs.ptr_) {
if (ptr_) {
Expand Down

0 comments on commit ad2e59b

Please sign in to comment.