diff --git a/CMakeLists.txt b/CMakeLists.txt index 1794a7e..3034051 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.11) find_package(Git QUIET) if (Git_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") @@ -218,17 +218,7 @@ if (FTXUI_BUILD_TESTS AND ${CMAKE_VERSION} VERSION_GREATER "3.11.4") GIT_REPOSITORY "https://github.com/google/googletest" GIT_TAG 23ef29555ef4789f555f1ba8c51b4c52975f0907 ) - - FetchContent_GetProperties(googletest) - if(NOT googletest_POPULATED) - message(STATUS "Fetching googletest...") - FetchContent_Populate(googletest) - message(STATUS "... done") - add_subdirectory( - ${googletest_SOURCE_DIR} - ${googletest_BINARY_DIR} - EXCLUDE_FROM_ALL) - endif() + FetchContent_MakeAvailable(googletest) add_executable(tests src/ftxui/component/component_test.cpp @@ -255,9 +245,29 @@ if (FTXUI_BUILD_TESTS AND ${CMAKE_VERSION} VERSION_GREATER "3.11.4") ) target_compile_options(tests PRIVATE -fsanitize=address) target_link_libraries(tests PRIVATE -fsanitize=address) - set_property(TARGET tests PROPERTY CXX_STANDARD 17) + if (NOT MSVC) + FetchContent_Declare(googlebenchmark + GIT_REPOSITORY "https://github.com/google/benchmark" + GIT_TAG 62937f91b5c763a8e119d0c20c67b87bde8eff1c + ) + FetchContent_MakeAvailable(googlebenchmark) + + add_executable(ftxui_benchmark + src/ftxui/dom/benchmark_test.cpp + ) + target_link_libraries(ftxui_benchmark + PRIVATE dom + PRIVATE benchmark::benchmark + PRIVATE benchmark::benchmark_main + ) + target_include_directories(ftxui_benchmark + PRIVATE src + ) + set_property(TARGET ftxui_benchmark PROPERTY CXX_STANDARD 17) + endif() + if (FTXUI_BUILD_TESTS_FUZZER) set(CMAKE_C_COMPILER clang) set(CMAKE_CXX_COMPILER clang++) diff --git a/src/ftxui/component/component_test.cpp b/src/ftxui/component/component_test.cpp index cfa46d7..5e1813c 100644 --- a/src/ftxui/component/component_test.cpp +++ b/src/ftxui/component/component_test.cpp @@ -1,8 +1,8 @@ -#include // for Test, SuiteApiResolver, TestInfo (ptr only), TEST, TestFactoryImpl #include // for shared_ptr, allocator, make_shared, __shared_ptr_access #include "ftxui/component/captured_mouse.hpp" // for ftxui #include "ftxui/component/component_base.hpp" // for ComponentBase, Component +#include "gtest/gtest_pred_impl.h" // for Test, SuiteApiResolver, TEST, TestFactoryImpl using namespace ftxui; diff --git a/src/ftxui/component/screen_interactive.cpp b/src/ftxui/component/screen_interactive.cpp index 5843b09..67085ca 100644 --- a/src/ftxui/component/screen_interactive.cpp +++ b/src/ftxui/component/screen_interactive.cpp @@ -206,7 +206,7 @@ void OnExit(int signal) { on_exit_functions.pop(); } if (signal) - std::raise(signal); + std::raise(signal); } auto install_signal_handler = [](int sig, SignalHandler handler) { diff --git a/src/ftxui/dom/benchmark_test.cpp b/src/ftxui/dom/benchmark_test.cpp new file mode 100644 index 0000000..5808e66 --- /dev/null +++ b/src/ftxui/dom/benchmark_test.cpp @@ -0,0 +1,35 @@ +#include + +#include "ftxui/dom/elements.hpp" // for separator, gauge, operator|, text, Element, blink, inverted, hbox, vbox, border +#include "ftxui/dom/node.hpp" // for Render +#include "ftxui/screen/box.hpp" // for ftxui +#include "ftxui/screen/screen.hpp" // for Screen + +using namespace ftxui; + +static void BencharkBasic(benchmark::State& state) { + while (state.KeepRunning()) { + auto document = vbox({ + text(L"Test"), + separator(), + hbox({ + gauge(0.9), + separator() | blink, + gauge(0.5), + separator() | inverted, + gauge(0.1), + separator(), + }), + text(L"Test"), + }) | + border; + auto root = gauge(1.0); + Screen screen(80, state.range(0)); + Render(screen, root); + } +} +BENCHMARK(BencharkBasic)->DenseRange(0, 256, 16); + +// Copyright 2021 Arthur Sonzogni. All rights reserved. +// Use of this source code is governed by the MIT license that can be found in +// the LICENSE file.l