From 85c3dc45cad167aa028d4a1491fa36a03f02ce1b Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Wed, 9 Apr 2025 12:35:46 +0200 Subject: [PATCH] Add Changelog and remove flag. --- CHANGELOG.md | 16 ++++++ CMakeLists.txt | 14 +----- examples/component/button.cpp | 35 ++++++++++--- modules/ftxui/CMakeLists.txt | 95 +++++++++++++++++++++++++---------- 4 files changed, 114 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c8f7af0..80be8a12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,22 @@ Changelog Development ----------- + +### Build +- Feature: Support C++20 modules. + This requires: + - Using the Ninja or MSVC generator + - A recent Clang/GCC/MSVC compiler. + - Cmake 3.28 or higher. + Usage: + ```cpp + import ftxui; + import ftxui.component; + import ftxui.dom; + import ftxui.screen; + ``` + Thanks @mikomikotaishi for PR #1015. + ### Component - Bugfix: Fix a crash with ResizeableSplit. See #1023. - Clamp screen size to terminal size. diff --git a/CMakeLists.txt b/CMakeLists.txt index c08b9608..a30de597 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -179,16 +179,4 @@ include(cmake/ftxui_package.cmake) add_subdirectory(examples) add_subdirectory(doc) - -option(FTXUI_BUILD_MODULES "Build C++ modules support" OFF) - -if(FTXUI_BUILD_MODULES) - if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.28) - message(STATUS "Building C++ modules (CMake ${CMAKE_VERSION} supports modules)") - add_subdirectory(modules/ftxui) - else() - message(STATUS "Skipping C++ modules (requires CMake 3.28+, found ${CMAKE_VERSION})") - endif() -else() - message(STATUS "C++ modules support is disabled. Enable with -DFTXUI_BUILD_MODULES=ON") -endif() +add_subdirectory(modules/ftxui) diff --git a/examples/component/button.cpp b/examples/component/button.cpp index 63032f42..25813849 100644 --- a/examples/component/button.cpp +++ b/examples/component/button.cpp @@ -1,9 +1,30 @@ -#include "ftxui/component/component.hpp" -#include "ftxui/component/screen_interactive.hpp" +#include // for shared_ptr, allocator, __shared_ptr_access + +#include "ftxui/component/component.hpp" // for Renderer, ResizableSplitBottom, ResizableSplitLeft, ResizableSplitRight, ResizableSplitTop +#include "ftxui/component/component_base.hpp" // for ComponentBase +#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive +#include "ftxui/dom/elements.hpp" // for Element, operator|, text, center, border + +using namespace ftxui; + +int main() { + auto screen = ScreenInteractive::Fullscreen(); -int main(){ - auto screen = ftxui::ScreenInteractive::Fullscreen(); - auto testComponent = ftxui::Renderer([](){return ftxui::text("test Component");}); - screen.Loop(testComponent); - return 0; + std::string a = "aa"; + + auto component = Renderer([a] { + + std::vector elements; + + for (auto i = 0; i < 10; ++i) { + elements.push_back(window(text(a), paragraph(a))); + } + + return vbox(elements); + }); + + auto renderer = + Renderer(component, [&] { return component->Render() | border; }); + + screen.Loop(renderer); } diff --git a/modules/ftxui/CMakeLists.txt b/modules/ftxui/CMakeLists.txt index 7ac492c4..28c4f1b5 100644 --- a/modules/ftxui/CMakeLists.txt +++ b/modules/ftxui/CMakeLists.txt @@ -1,21 +1,67 @@ -file(GLOB_RECURSE FTXUI_MODULES *.cppm) - -add_library(ftxui_modules) - -cmake_minimum_required(VERSION 3.28) - -if(NOT COMMAND configure_cpp_module_target) - function(configure_cpp_module_target target) - if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.28) - target_sources(${target} PUBLIC FILE_SET CXX_MODULES FILES ${FTXUI_MODULES}) - else() - message(WARNING "C++ modules require CMake 3.28+. Using standard compilation.") - target_sources(${target} PRIVATE ${FTXUI_MODULES}) - endif() - endfunction() +# CMake 3.28+ supports the new CMake C++ module system. +if(CMAKE_VERSION VERSION_LESS 3.28) + return() endif() -configure_cpp_module_target(ftxui_modules) +# Not all compilers support the C++ module system yet. +if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU|MSVC") + return() +endif() + +# The list of generators which support scanning sources for C++ modules include: +# - Ninja +# - Ninja Multi-Config +# - Visual Studio 17 2022 +if (NOT (CMAKE_GENERATOR MATCHES "Ninja") AND + NOT (CMAKE_GENERATOR MATCHES "Visual Studio" AND + CMAKE_GENERATOR_VERSION VERSION_GREATER_EQUAL 17)) + return() +endif() + +cmake_minimum_required(VERSION 3.28) +add_library(ftxui_modules) + +target_sources(ftxui_modules + PUBLIC + FILE_SET CXX_MODULES + FILES + component.cppm + component/Animation.cppm + component/CapturedMouse.cppm + component/Component.cppm + component/ComponentBase.cppm + component/ComponentOptions.cppm + component/Event.cppm + component/Loop.cppm + component/Mouse.cppm + component/Receiver.cppm + component/ScreenInteractive.cppm + component/Task.cppm + dom.cppm + dom/Canvas.cppm + dom/Deprecated.cppm + dom/Direction.cppm + dom/Elements.cppm + dom/FlexboxConfig.cppm + dom/LinearGradient.cppm + dom/Node.cppm + dom/Requirement.cppm + dom/Selection.cppm + dom/Table.cppm + screen.cppm + screen/Box.cppm + screen/Color.cppm + screen/ColorInfo.cppm + screen/Deprecated.cppm + screen/Image.cppm + screen/Pixel.cppm + screen/Screen.cppm + screen/String.cppm + screen/Terminal.cppm + util.cppm + util/AutoReset.cppm + util/Ref.cppm + ) target_link_libraries(ftxui_modules PUBLIC @@ -24,17 +70,14 @@ target_link_libraries(ftxui_modules ftxui::component ) -target_include_directories(ftxui_modules - PRIVATE - ${ftxui_SOURCE_DIR}/include -) +target_compile_features(ftxui_modules PUBLIC cxx_std_20) -set_target_properties(ftxui_modules PROPERTIES - CXX_STANDARD 23 - CXX_STANDARD_REQUIRED ON - CXX_EXTENSIONS OFF - CXX_MODULE_DYNDEP OFF -) +#set_target_properties(ftxui_modules PROPERTIES + #CXX_STANDARD 23 + #CXX_STANDARD_REQUIRED ON + #CXX_EXTENSIONS OFF + #CXX_MODULE_DYNDEP OFF +#) add_library(ftxui::modules ALIAS ftxui_modules)