FTXUI/CMakeLists.txt

300 lines
8.8 KiB
CMake

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()
project(ftxui
LANGUAGES CXX
VERSION 0.6.${git_version}
)
option(FTXUI_BUILD_DOCS "Set to ON to build tests" ON)
option(FTXUI_BUILD_EXAMPLES "Set to ON to build examples" ON)
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
src/ftxui/screen/color_info.cpp
src/ftxui/screen/screen.cpp
src/ftxui/screen/string.cpp
src/ftxui/screen/terminal.cpp
src/ftxui/screen/wcwidth.cpp
include/ftxui/screen/box.hpp
include/ftxui/screen/color.hpp
include/ftxui/screen/color_info.hpp
include/ftxui/screen/screen.hpp
include/ftxui/screen/string.hpp
)
add_library(dom STATIC
include/ftxui/dom/elements.hpp
include/ftxui/dom/node.hpp
include/ftxui/dom/requirement.hpp
include/ftxui/dom/take_any_args.hpp
src/ftxui/dom/blink.cpp
src/ftxui/dom/bold.cpp
src/ftxui/dom/border.cpp
src/ftxui/dom/clear_under.cpp
src/ftxui/dom/color.cpp
src/ftxui/dom/composite_decorator.cpp
src/ftxui/dom/dbox.cpp
src/ftxui/dom/dim.cpp
src/ftxui/dom/flex.cpp
src/ftxui/dom/frame.cpp
src/ftxui/dom/gauge.cpp
src/ftxui/dom/graph.cpp
src/ftxui/dom/hbox.cpp
src/ftxui/dom/hflow.cpp
src/ftxui/dom/inverted.cpp
src/ftxui/dom/node.cpp
src/ftxui/dom/node_decorator.cpp
src/ftxui/dom/paragraph.cpp
src/ftxui/dom/reflect.cpp
src/ftxui/dom/separator.cpp
src/ftxui/dom/size.cpp
src/ftxui/dom/spinner.cpp
src/ftxui/dom/text.cpp
src/ftxui/dom/underlined.cpp
src/ftxui/dom/util.cpp
src/ftxui/dom/vbox.cpp
)
add_library(component STATIC
include/ftxui/component/button.hpp
include/ftxui/component/captured_mouse.hpp
include/ftxui/component/checkbox.hpp
include/ftxui/component/component.hpp
include/ftxui/component/component_base.hpp
include/ftxui/component/container.hpp
include/ftxui/component/event.hpp
include/ftxui/component/input.hpp
include/ftxui/component/menu.hpp
include/ftxui/component/mouse.hpp
include/ftxui/component/radiobox.hpp
include/ftxui/component/receiver.hpp
include/ftxui/component/screen_interactive.hpp
include/ftxui/component/toggle.hpp
src/ftxui/component/button.cpp
src/ftxui/component/catch_event.cpp
src/ftxui/component/checkbox.cpp
src/ftxui/component/component.cpp
src/ftxui/component/container.cpp
src/ftxui/component/event.cpp
src/ftxui/component/input.cpp
src/ftxui/component/menu.cpp
src/ftxui/component/radiobox.cpp
src/ftxui/component/radiobox.cpp
src/ftxui/component/renderer.cpp
src/ftxui/component/resizable_split.cpp
src/ftxui/component/screen_interactive.cpp
src/ftxui/component/slider.cpp
src/ftxui/component/terminal_input_parser.cpp
src/ftxui/component/terminal_input_parser.hpp
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(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()
foreach(lib screen dom component)
target_include_directories(${lib}
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
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")
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()
endif()
if(FTXUI_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if(FTXUI_BUILD_DOCS)
add_subdirectory(doc)
endif()