diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 1e114c1..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,11 +0,0 @@ -image: registry.gitlab.com/nxxm/nxxm/ci/ubuntu-cpp:latest - -stages: - - build - -build-wasm: - stage: build - image: registry.gitlab.com/nxxm/nxxm/ci/ubuntu-cpp:latest - script: - - nxxm . --verbose - diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 636f867..0000000 --- a/.travis.yml +++ /dev/null @@ -1,40 +0,0 @@ -sudo: false - -language: - - cpp - -script: - - mkdir build - - cd build - - cmake .. -DFTXUI_BUILD_TESTS=ON - - cmake --build . - - "${FTXUI_TEST_EXE}" - -notifications: - email: false - -jobs: - include: - # Ubuntu - - os: linux - dist: bionic - compiler: gcc - env: - - FTXUI_TEST_EXE="./tests --gtest_color=yes" - - # Ubuntu - - os: linux - dist: bionic - compiler: clang - env: - - FTXUI_TEST_EXE="./tests --gtest_color=yes" - - # OS X - - os: osx - env: - - FTXUI_TEST_EXE="./tests --gtest_color=yes" - - # Windows - - os: windows - env: - - FTXUI_TEST_EXE="./Debug/tests.exe --gtest_color=yes" diff --git a/CMakeLists.txt b/CMakeLists.txt index b923284..1e24ea9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,17 +1,6 @@ cmake_minimum_required(VERSION 3.11) -find_package(Git QUIET) -if (Git_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") - message("git found") - execute_process( - COMMAND ${GIT_EXECUTABLE} rev-list --count HEAD - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - OUTPUT_VARIABLE git_version - OUTPUT_STRIP_TRAILING_WHITESPACE - ) -else() - set(git_version 0) -endif() +include(cmake/ftxui_git_version.cmake) project(ftxui LANGUAGES CXX @@ -24,8 +13,6 @@ option(FTXUI_BUILD_TESTS "Set to ON to build tests" OFF) option(FTXUI_BUILD_TESTS_FUZZER "Set to ON to enable fuzzing" OFF) option(FTXUI_ENABLE_INSTALL "Generate the install target" ON) -find_package(Threads) - add_library(screen STATIC src/ftxui/screen/box.cpp src/ftxui/screen/color.cpp @@ -108,186 +95,27 @@ add_library(component STATIC src/ftxui/component/toggle.cpp ) -add_library(ftxui::screen ALIAS screen) -add_library(ftxui::dom ALIAS dom) -add_library(ftxui::component ALIAS component) +target_link_libraries(dom + PUBLIC screen +) -target_link_libraries(dom PUBLIC screen) -target_link_libraries(component PUBLIC dom Threads::Threads) - find_program(iwyu_path NAMES include-what-you-use iwyu) - if(iwyu_path) - set_property(TARGET ${lib} - PROPERTY ${iwyu_path} -Xiwyu - --mapping_file ${CMAKE_CURRENT_SOURCE_DIR}/iwyu.impl - ) - endif() +find_package(Threads) +target_link_libraries(component + PUBLIC dom + PRIVATE Threads::Threads +) +include(cmake/ftxui_set_options.cmake) +ftxui_set_options(screen) +ftxui_set_options(dom) +ftxui_set_options(component) -foreach(lib screen dom component) - target_include_directories(${lib} - PUBLIC - $ - $ - PRIVATE - src - ) - - # C++17 is used. We requires fold expression at least. - set_property(TARGET ${lib} PROPERTY CXX_STANDARD 17) - - # Force Microsoft Visual Studio to decode sources files in UTF-8. This applies - # to the library and the library users. - if (MSVC) - target_compile_options(${lib} PUBLIC "/utf-8") - endif() - - # Add as many warning as possible: - if (WIN32) - if (MSVC) - target_compile_options(${lib} PRIVATE "/W3") - target_compile_options(${lib} PRIVATE "/WX") - target_compile_options(${lib} PRIVATE "/wd4244") - target_compile_options(${lib} PRIVATE "/wd4267") - target_compile_options(${lib} PRIVATE "/D_CRT_SECURE_NO_WARNINGS") - endif() - # Force Win32 to UNICODE - target_compile_definitions(${lib} PRIVATE UNICODE _UNICODE) - else() - target_compile_options(${lib} PRIVATE "-Wall") - target_compile_options(${lib} PRIVATE "-Wextra") - target_compile_options(${lib} PRIVATE "-pedantic") - target_compile_options(${lib} PRIVATE "-Werror") - target_compile_options(${lib} PRIVATE "-Wmissing-declarations") - target_compile_options(${lib} PRIVATE "-Wdeprecated") - target_compile_options(${lib} PRIVATE "-Wshadow") - endif() - -endforeach() - -if (EMSCRIPTEN) - #string(APPEND CMAKE_CXX_FLAGS " -s ASSERTIONS=1") - string(APPEND CMAKE_CXX_FLAGS " -s ASYNCIFY") - string(APPEND CMAKE_CXX_FLAGS " -s USE_PTHREADS") - string(APPEND CMAKE_CXX_FLAGS " -s PROXY_TO_PTHREAD") +if (FTXUI_BUILD_TESTS AND ${CMAKE_VERSION} VERSION_GREATER "3.11.4") + include(cmake/ftxui_test.cmake) endif() if(FTXUI_ENABLE_INSTALL) - include(GNUInstallDirs) - install(TARGETS screen dom component - EXPORT ftxui-export - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/ftxui/ - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/ftxui/ - ) - - install(DIRECTORY include/ftxui DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) - - include(CMakePackageConfigHelpers) - configure_package_config_file(ftxui-config.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/ftxui-config.cmake - INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/ftxui/cmake - PATH_VARS CMAKE_INSTALL_INCLUDEDIR - ) - write_basic_package_version_file( - ftxui-config-version.cmake - VERSION ${PACKAGE_VERSION} - COMPATIBILITY AnyNewerVersion - ) - - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ftxui-config.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ftxui - ) - install(EXPORT ftxui-export - FILE ftxui-config-version.cmake - NAMESPACE ftxui:: - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ftxui - ) -endif() - -export(TARGETS screen dom component NAMESPACE ftxui:: - FILE ${PROJECT_BINARY_DIR}/ftxui-targets.cmake) - - -if (FTXUI_BUILD_TESTS AND ${CMAKE_VERSION} VERSION_GREATER "3.11.4") - enable_testing() - set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - - set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE) - include(FetchContent) - - FetchContent_Declare( googletest - GIT_REPOSITORY "https://github.com/google/googletest" - GIT_TAG 23ef29555ef4789f555f1ba8c51b4c52975f0907 - ) - FetchContent_MakeAvailable(googletest) - - add_executable(tests - src/ftxui/component/component_test.cpp - src/ftxui/component/container_test.cpp - src/ftxui/component/input_test.cpp - src/ftxui/component/radiobox_test.cpp - src/ftxui/component/receiver_test.cpp - src/ftxui/component/screen_interactive_test.cpp - src/ftxui/component/terminal_input_parser_test.cpp - src/ftxui/component/toggle_test.cpp - src/ftxui/dom/gauge_test.cpp - src/ftxui/dom/hbox_test.cpp - src/ftxui/dom/text_test.cpp - src/ftxui/dom/vbox_test.cpp - ) - - target_link_libraries(tests - PRIVATE component - PRIVATE gtest - PRIVATE gmock - PRIVATE gtest_main - ) - target_include_directories(tests - PRIVATE src - ) - 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++) - add_executable(terminal_input_parser_test_fuzz - src/ftxui/component/terminal_input_parser_test_fuzz.cpp - ) - target_include_directories(terminal_input_parser_test_fuzz - PRIVATE src - ) - target_link_libraries(terminal_input_parser_test_fuzz - PRIVATE component - ) - target_compile_options(terminal_input_parser_test_fuzz - PRIVATE -fsanitize=fuzzer,address - ) - target_link_libraries(terminal_input_parser_test_fuzz - PRIVATE -fsanitize=fuzzer,address - ) - endif() + include(cmake/ftxui_install.cmake) endif() if(FTXUI_BUILD_EXAMPLES) @@ -297,3 +125,6 @@ endif() if(FTXUI_BUILD_DOCS) add_subdirectory(doc) endif() + +include(cmake/iwyu.cmake) +include(cmake/ftxui_export.cmake) diff --git a/cmake/ftxui_benchmark.cmake b/cmake/ftxui_benchmark.cmake new file mode 100644 index 0000000..95ad0eb --- /dev/null +++ b/cmake/ftxui_benchmark.cmake @@ -0,0 +1,20 @@ +if (NOT WIN32) + 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() diff --git a/cmake/ftxui_export.cmake b/cmake/ftxui_export.cmake new file mode 100644 index 0000000..9df4e7d --- /dev/null +++ b/cmake/ftxui_export.cmake @@ -0,0 +1,8 @@ +add_library(ftxui::screen ALIAS screen) +add_library(ftxui::dom ALIAS dom) +add_library(ftxui::component ALIAS component) +export( + TARGETS screen dom component + NAMESPACE ftxui:: + FILE ${PROJECT_BINARY_DIR}/ftxui-targets.cmake +) diff --git a/cmake/ftxui_fuzzer.cmake b/cmake/ftxui_fuzzer.cmake new file mode 100644 index 0000000..40693b8 --- /dev/null +++ b/cmake/ftxui_fuzzer.cmake @@ -0,0 +1,17 @@ +set(CMAKE_C_COMPILER clang) +set(CMAKE_CXX_COMPILER clang++) +add_executable(terminal_input_parser_test_fuzz + src/ftxui/component/terminal_input_parser_test_fuzz.cpp +) +target_include_directories(terminal_input_parser_test_fuzz + PRIVATE src +) +target_link_libraries(terminal_input_parser_test_fuzz + PRIVATE component +) +target_compile_options(terminal_input_parser_test_fuzz + PRIVATE -fsanitize=fuzzer,address +) +target_link_libraries(terminal_input_parser_test_fuzz + PRIVATE -fsanitize=fuzzer,address +) diff --git a/cmake/ftxui_git_version.cmake b/cmake/ftxui_git_version.cmake new file mode 100644 index 0000000..579832e --- /dev/null +++ b/cmake/ftxui_git_version.cmake @@ -0,0 +1,13 @@ +find_package(Git QUIET) +if (Git_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") + message("git found") + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-list --count HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE git_version + OUTPUT_STRIP_TRAILING_WHITESPACE + ) +else() + set(git_version 0) +endif() + diff --git a/cmake/ftxui_install.cmake b/cmake/ftxui_install.cmake new file mode 100644 index 0000000..8977814 --- /dev/null +++ b/cmake/ftxui_install.cmake @@ -0,0 +1,29 @@ +include(GNUInstallDirs) +install(TARGETS screen dom component + EXPORT ftxui-export + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/ftxui/ + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/ftxui/ +) + +install(DIRECTORY include/ftxui DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + +include(CMakePackageConfigHelpers) +configure_package_config_file(ftxui-config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/ftxui-config.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/ftxui/cmake + PATH_VARS CMAKE_INSTALL_INCLUDEDIR +) +write_basic_package_version_file( + ftxui-config-version.cmake + VERSION ${PACKAGE_VERSION} + COMPATIBILITY AnyNewerVersion +) + +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ftxui-config.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ftxui +) +install(EXPORT ftxui-export + FILE ftxui-config-version.cmake + NAMESPACE ftxui:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ftxui +) diff --git a/cmake/ftxui_set_options.cmake b/cmake/ftxui_set_options.cmake new file mode 100644 index 0000000..a25197f --- /dev/null +++ b/cmake/ftxui_set_options.cmake @@ -0,0 +1,46 @@ +function(ftxui_set_options library) + target_include_directories(${library} + PUBLIC + $ + $ + PRIVATE + src + ) + + # C++17 is used. We requires fold expression at least. + set_property(TARGET ${library} PROPERTY CXX_STANDARD 17) + + # Force Microsoft Visual Studio to decode sources files in UTF-8. This applies + # to the library and the library users. + if (MSVC) + target_compile_options(${library} PUBLIC "/utf-8") + endif() + + # Add as many warning as possible: + if (WIN32) + if (MSVC) + target_compile_options(${library} PRIVATE "/W3") + target_compile_options(${library} PRIVATE "/WX") + target_compile_options(${library} PRIVATE "/wd4244") + target_compile_options(${library} PRIVATE "/wd4267") + target_compile_options(${library} PRIVATE "/D_CRT_SECURE_NO_WARNINGS") + endif() + # Force Win32 to UNICODE + target_compile_definitions(${library} PRIVATE UNICODE _UNICODE) + else() + target_compile_options(${library} PRIVATE "-Wall") + target_compile_options(${library} PRIVATE "-Wextra") + target_compile_options(${library} PRIVATE "-pedantic") + target_compile_options(${library} PRIVATE "-Werror") + target_compile_options(${library} PRIVATE "-Wmissing-declarations") + target_compile_options(${library} PRIVATE "-Wdeprecated") + target_compile_options(${library} PRIVATE "-Wshadow") + endif() +endfunction() + +if (EMSCRIPTEN) + #string(APPEND CMAKE_CXX_FLAGS " -s ASSERTIONS=1") + string(APPEND CMAKE_CXX_FLAGS " -s ASYNCIFY") + string(APPEND CMAKE_CXX_FLAGS " -s USE_PTHREADS") + string(APPEND CMAKE_CXX_FLAGS " -s PROXY_TO_PTHREAD") +endif() diff --git a/cmake/ftxui_test.cmake b/cmake/ftxui_test.cmake new file mode 100644 index 0000000..cd985a8 --- /dev/null +++ b/cmake/ftxui_test.cmake @@ -0,0 +1,47 @@ +enable_testing() +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + +set(FETCHCONTENT_UPDATES_DISCONNECTED TRUE) +include(FetchContent) + +FetchContent_Declare( googletest + GIT_REPOSITORY "https://github.com/google/googletest" + GIT_TAG 23ef29555ef4789f555f1ba8c51b4c52975f0907 +) +FetchContent_MakeAvailable(googletest) + +add_executable(tests + src/ftxui/component/component_test.cpp + src/ftxui/component/container_test.cpp + src/ftxui/component/input_test.cpp + src/ftxui/component/radiobox_test.cpp + src/ftxui/component/receiver_test.cpp + src/ftxui/component/screen_interactive_test.cpp + src/ftxui/component/terminal_input_parser_test.cpp + src/ftxui/component/toggle_test.cpp + src/ftxui/dom/gauge_test.cpp + src/ftxui/dom/hbox_test.cpp + src/ftxui/dom/text_test.cpp + src/ftxui/dom/vbox_test.cpp +) + +target_link_libraries(tests + PRIVATE component + PRIVATE gtest + PRIVATE gmock + PRIVATE gtest_main +) +target_include_directories(tests + PRIVATE src +) +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) + include(cmake/ftxui_benchmark.cmake) +endif() + +if (FTXUI_BUILD_TESTS_FUZZER) + include(cmake/ftxui_fuzzer.cmake) +endif() diff --git a/cmake/iwyu.cmake b/cmake/iwyu.cmake new file mode 100644 index 0000000..868cdc4 --- /dev/null +++ b/cmake/iwyu.cmake @@ -0,0 +1,7 @@ +find_program(iwyu_path NAMES include-what-you-use iwyu) +if(iwyu_path) + set_property(TARGET ${lib} + PROPERTY ${iwyu_path} -Xiwyu + --mapping_file ${CMAKE_CURRENT_SOURCE_DIR}/iwyu.impl + ) +endif()