mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-22 10:40:00 +08:00
cmake: support gtest from the package manager (#552)
Some developers would be happier with the gtest version provided from their package manager. Use it if it is installed the package provide cmake support. Fixed: https://github.com/ArthurSonzogni/FTXUI/issues/551
This commit is contained in:
parent
1561293140
commit
65848d1e5f
@ -46,6 +46,9 @@ current (development)
|
|||||||
- Bugfix: Add unicode 13 support for full width characters.
|
- Bugfix: Add unicode 13 support for full width characters.
|
||||||
- Bugfix: Fix MSVC treating codecvt C++17 deprecated function as an error.
|
- Bugfix: Fix MSVC treating codecvt C++17 deprecated function as an error.
|
||||||
|
|
||||||
|
### Build
|
||||||
|
- Support using the google test version provided by the package manager.
|
||||||
|
|
||||||
3.0.0
|
3.0.0
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
@ -145,22 +145,13 @@ ftxui_check_coverage(screen)
|
|||||||
ftxui_check_coverage(dom)
|
ftxui_check_coverage(dom)
|
||||||
ftxui_check_coverage(component)
|
ftxui_check_coverage(component)
|
||||||
|
|
||||||
if (FTXUI_BUILD_TESTS AND ${CMAKE_VERSION} VERSION_GREATER "3.11.4")
|
include(cmake/ftxui_test.cmake)
|
||||||
include(cmake/ftxui_test.cmake)
|
include(cmake/ftxui_benchmark.cmake)
|
||||||
endif()
|
include(cmake/ftxui_fuzzer.cmake)
|
||||||
|
|
||||||
if(FTXUI_BUILD_EXAMPLES)
|
|
||||||
add_subdirectory(examples)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(FTXUI_BUILD_DOCS)
|
|
||||||
add_subdirectory(doc)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
include(cmake/iwyu.cmake)
|
include(cmake/iwyu.cmake)
|
||||||
include(cmake/ftxui_export.cmake)
|
include(cmake/ftxui_export.cmake)
|
||||||
|
include(cmake/ftxui_install.cmake)
|
||||||
|
include(cmake/ftxui_package.cmake)
|
||||||
|
|
||||||
if(FTXUI_ENABLE_INSTALL)
|
add_subdirectory(examples)
|
||||||
include(cmake/ftxui_install.cmake)
|
add_subdirectory(doc)
|
||||||
include(cmake/ftxui_package.cmake)
|
|
||||||
endif()
|
|
||||||
|
@ -1,31 +1,21 @@
|
|||||||
if (NOT WIN32)
|
if (NOT FTXUI_BUILD_TESTS OR
|
||||||
FetchContent_Declare(googlebenchmark
|
NOT ${CMAKE_VERSION} VERSION_GREATER "3.11.4" OR
|
||||||
GIT_REPOSITORY "https://github.com/google/benchmark"
|
WIN32
|
||||||
GIT_TAG 62937f91b5c763a8e119d0c20c67b87bde8eff1c
|
|
||||||
GIT_PROGRESS TRUE
|
|
||||||
)
|
|
||||||
|
|
||||||
FetchContent_GetProperties(googlebenchmark)
|
|
||||||
set (BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE INTERNAL "")
|
|
||||||
set (BENCHMARK_ENABLE_TESTING OFF CACHE INTERNAL "")
|
|
||||||
if(NOT googlebenchmark_POPULATED)
|
|
||||||
FetchContent_Populate(googlebenchmark)
|
|
||||||
add_subdirectory(
|
|
||||||
${googlebenchmark_SOURCE_DIR}
|
|
||||||
${googlebenchmark_BINARY_DIR}
|
|
||||||
EXCLUDE_FROM_ALL
|
|
||||||
)
|
)
|
||||||
endif()
|
return()
|
||||||
|
|
||||||
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
|
|
||||||
)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
include(cmake/ftxui_find_google_benchmark.cmake)
|
||||||
|
|
||||||
|
add_executable(ftxui-benchmark
|
||||||
|
src/ftxui/dom/benchmark_test.cpp
|
||||||
|
)
|
||||||
|
ftxui_set_options(ftxui-benchmark)
|
||||||
|
target_link_libraries(ftxui-benchmark
|
||||||
|
PRIVATE dom
|
||||||
|
PRIVATE benchmark::benchmark
|
||||||
|
PRIVATE benchmark::benchmark_main
|
||||||
|
)
|
||||||
|
target_include_directories(ftxui-benchmark
|
||||||
|
PRIVATE src
|
||||||
|
)
|
||||||
|
32
cmake/ftxui_find_google_benchmark.cmake
Normal file
32
cmake/ftxui_find_google_benchmark.cmake
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# Some developers would be happier with the google benchmark version provided
|
||||||
|
# from their package manager. Use it if it is installed the package provide
|
||||||
|
# cmake support.
|
||||||
|
# https://github.com/ArthurSonzogni/FTXUI/issues/551
|
||||||
|
find_package(benchmark QUIET)
|
||||||
|
if (benchmark_FOUND)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
option(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)
|
||||||
|
option(FETCHCONTENT_QUIET FALSE)
|
||||||
|
include(FetchContent)
|
||||||
|
|
||||||
|
FetchContent_Declare(googlebenchmark
|
||||||
|
GIT_REPOSITORY "https://github.com/google/benchmark"
|
||||||
|
GIT_TAG 62937f91b5c763a8e119d0c20c67b87bde8eff1c
|
||||||
|
GIT_PROGRESS TRUE
|
||||||
|
)
|
||||||
|
|
||||||
|
FetchContent_GetProperties(googlebenchmark)
|
||||||
|
set (BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE INTERNAL "")
|
||||||
|
set (BENCHMARK_ENABLE_TESTING OFF CACHE INTERNAL "")
|
||||||
|
if(googlebenchmark_POPULATED)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
FetchContent_Populate(googlebenchmark)
|
||||||
|
add_subdirectory(
|
||||||
|
${googlebenchmark_SOURCE_DIR}
|
||||||
|
${googlebenchmark_BINARY_DIR}
|
||||||
|
EXCLUDE_FROM_ALL
|
||||||
|
)
|
33
cmake/ftxui_find_google_test.cmake
Normal file
33
cmake/ftxui_find_google_test.cmake
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
# Some developers would be happier with the gtest version provided from their
|
||||||
|
# package manager. Use it if it is installed the package provide cmake support.
|
||||||
|
# https://github.com/ArthurSonzogni/FTXUI/issues/551
|
||||||
|
find_package(GTest QUIET)
|
||||||
|
|
||||||
|
if (GTest_FOUND)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
option(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)
|
||||||
|
option(FETCHCONTENT_QUIET FALSE)
|
||||||
|
include(FetchContent)
|
||||||
|
|
||||||
|
FetchContent_Declare(googletest
|
||||||
|
GIT_REPOSITORY "https://github.com/google/googletest"
|
||||||
|
GIT_TAG 23ef29555ef4789f555f1ba8c51b4c52975f0907
|
||||||
|
GIT_PROGRESS TRUE
|
||||||
|
)
|
||||||
|
|
||||||
|
FetchContent_GetProperties(googletest)
|
||||||
|
if(googletest_POPULATED)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
FetchContent_Populate(googletest)
|
||||||
|
set(BUILD_GMOCK OFF CACHE INTERNAL "")
|
||||||
|
set(INSTALL_GTEST OFF CACHE INTERNAL "")
|
||||||
|
set(gtest_force_shared_crt ON CACHE INTERNAL "")
|
||||||
|
add_subdirectory(
|
||||||
|
${googletest_SOURCE_DIR}
|
||||||
|
${googletest_BINARY_DIR}
|
||||||
|
EXCLUDE_FROM_ALL
|
||||||
|
)
|
@ -1,3 +1,7 @@
|
|||||||
|
if (FTXUI_BUILD_TESTS_FUZZER)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
set(CMAKE_C_COMPILER clang)
|
set(CMAKE_C_COMPILER clang)
|
||||||
set(CMAKE_CXX_COMPILER clang++)
|
set(CMAKE_CXX_COMPILER clang++)
|
||||||
|
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
if(NOT FTXUI_ENABLE_INSTALL)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
install(TARGETS screen dom component
|
install(TARGETS screen dom component
|
||||||
EXPORT ftxui-export
|
EXPORT ftxui-export
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
if(NOT FTXUI_ENABLE_INSTALL)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
if (UNIX AND NOT APPLE)
|
if (UNIX AND NOT APPLE)
|
||||||
set(CPACK_GENERATOR "DEB;External;RPM;STGZ;TBZ2;TGZ;TXZ;TZ;TZST;ZIP")
|
set(CPACK_GENERATOR "DEB;External;RPM;STGZ;TBZ2;TGZ;TXZ;TZ;TZST;ZIP")
|
||||||
elseif (UNIX AND APPLE)
|
elseif (UNIX AND APPLE)
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
find_program( CLANG_TIDY_EXE NAMES "clang-tidy" DOC "Path to clang-tidy executable" )
|
find_program(CLANG_TIDY_EXE NAMES "clang-tidy" DOC "Path to clang-tidy executable" )
|
||||||
if(NOT CLANG_TIDY_EXE)
|
if(NOT CLANG_TIDY_EXE)
|
||||||
message(STATUS "clang-tidy not found.")
|
message(STATUS "clang-tidy not found.")
|
||||||
else()
|
else()
|
||||||
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
|
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
function(ftxui_set_options library)
|
function(ftxui_set_options library)
|
||||||
set_target_properties(${library} PROPERTIES
|
message(STATUS "ftxui_set_options " ${library})
|
||||||
VERSION ${PROJECT_VERSION}
|
set_target_properties(${library} PROPERTIES VERSION ${PROJECT_VERSION})
|
||||||
OUTPUT_NAME "ftxui-${library}"
|
if (NOT ${library} MATCHES "ftxui-*")
|
||||||
)
|
set_target_properties(${library} PROPERTIES OUTPUT_NAME "ftxui-${library}")
|
||||||
|
endif()
|
||||||
|
|
||||||
if(CLANG_TIDY_EXE AND FTXUI_CLANG_TIDY)
|
if(CLANG_TIDY_EXE AND FTXUI_CLANG_TIDY)
|
||||||
set_target_properties(${library}
|
set_target_properties(${library}
|
||||||
@ -44,7 +44,11 @@ function(ftxui_set_options library)
|
|||||||
)
|
)
|
||||||
|
|
||||||
# C++17 is used. We require fold expression at least.
|
# C++17 is used. We require fold expression at least.
|
||||||
target_compile_features(${library} PUBLIC cxx_std_17)
|
target_compile_features(${library} PUBLIC cxx_std_20)
|
||||||
|
set_target_properties(${library} PROPERTIES
|
||||||
|
CXX_STANDARD 17
|
||||||
|
CXX_EXTENSIONS OFF
|
||||||
|
)
|
||||||
|
|
||||||
# Force Microsoft Visual Studio to decode sources files in UTF-8. This applies
|
# Force Microsoft Visual Studio to decode sources files in UTF-8. This applies
|
||||||
# to the library and the library users.
|
# to the library and the library users.
|
||||||
@ -80,9 +84,7 @@ function(ftxui_set_options library)
|
|||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
if (EMSCRIPTEN)
|
if (EMSCRIPTEN)
|
||||||
#string(APPEND CMAKE_CXX_FLAGS " -s ASSERTIONS=1")
|
|
||||||
string(APPEND CMAKE_CXX_FLAGS " -s USE_PTHREADS")
|
string(APPEND CMAKE_CXX_FLAGS " -s USE_PTHREADS")
|
||||||
string(APPEND CMAKE_EXE_LINKER_FLAGS " -s ASYNCIFY")
|
string(APPEND CMAKE_EXE_LINKER_FLAGS " -s ASYNCIFY")
|
||||||
string(APPEND CMAKE_EXE_LINKER_FLAGS " -s PROXY_TO_PTHREAD")
|
string(APPEND CMAKE_EXE_LINKER_FLAGS " -s PROXY_TO_PTHREAD")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -1,28 +1,13 @@
|
|||||||
enable_testing()
|
if (NOT FTXUI_BUILD_TESTS OR
|
||||||
|
NOT ${CMAKE_VERSION} VERSION_GREATER "3.11.4")
|
||||||
option(FETCHCONTENT_UPDATES_DISCONNECTED TRUE)
|
return()
|
||||||
option(FETCHCONTENT_QUIET FALSE)
|
|
||||||
include(FetchContent)
|
|
||||||
|
|
||||||
FetchContent_Declare(googletest
|
|
||||||
GIT_REPOSITORY "https://github.com/google/googletest"
|
|
||||||
GIT_TAG 23ef29555ef4789f555f1ba8c51b4c52975f0907
|
|
||||||
GIT_PROGRESS TRUE
|
|
||||||
)
|
|
||||||
FetchContent_GetProperties(googletest)
|
|
||||||
if(NOT googletest_POPULATED)
|
|
||||||
FetchContent_Populate(googletest)
|
|
||||||
set(BUILD_GMOCK OFF CACHE INTERNAL "")
|
|
||||||
set(INSTALL_GTEST OFF CACHE INTERNAL "")
|
|
||||||
set(gtest_force_shared_crt ON CACHE INTERNAL "")
|
|
||||||
add_subdirectory(
|
|
||||||
${googletest_SOURCE_DIR}
|
|
||||||
${googletest_BINARY_DIR}
|
|
||||||
EXCLUDE_FROM_ALL
|
|
||||||
)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_executable(tests
|
enable_testing()
|
||||||
|
|
||||||
|
include(cmake/ftxui_find_google_test.cmake)
|
||||||
|
|
||||||
|
add_executable(ftxui-tests
|
||||||
src/ftxui/component/animation_test.cpp
|
src/ftxui/component/animation_test.cpp
|
||||||
src/ftxui/component/button_test.cpp
|
src/ftxui/component/button_test.cpp
|
||||||
src/ftxui/component/collapsible_test.cpp
|
src/ftxui/component/collapsible_test.cpp
|
||||||
@ -63,25 +48,18 @@ add_executable(tests
|
|||||||
src/ftxui/screen/string_test.cpp
|
src/ftxui/screen/string_test.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(tests
|
target_link_libraries(ftxui-tests
|
||||||
PRIVATE component
|
PRIVATE component
|
||||||
PRIVATE gtest
|
PRIVATE GTest::gtest
|
||||||
PRIVATE gtest_main
|
PRIVATE GTest::gtest_main
|
||||||
)
|
)
|
||||||
target_include_directories(tests
|
target_include_directories(ftxui-tests
|
||||||
PRIVATE src
|
PRIVATE src
|
||||||
)
|
)
|
||||||
ftxui_set_options(tests)
|
ftxui_set_options(ftxui-tests)
|
||||||
target_compile_features(tests PUBLIC cxx_std_20)
|
target_compile_features(ftxui-tests PUBLIC cxx_std_20)
|
||||||
|
|
||||||
include(GoogleTest)
|
include(GoogleTest)
|
||||||
gtest_discover_tests(tests
|
gtest_discover_tests(ftxui-tests
|
||||||
DISCOVERY_TIMEOUT 600
|
DISCOVERY_TIMEOUT 600
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
include(cmake/ftxui_benchmark.cmake)
|
|
||||||
|
|
||||||
if (FTXUI_BUILD_TESTS_FUZZER)
|
|
||||||
include(cmake/ftxui_fuzzer.cmake)
|
|
||||||
endif()
|
|
||||||
|
@ -1,22 +1,27 @@
|
|||||||
|
if(NOT FTXUI_BUILD_DOCS)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
find_package(Doxygen)
|
find_package(Doxygen)
|
||||||
if (DOXYGEN_FOUND)
|
if (NOT DOXYGEN_FOUND)
|
||||||
# Generate example list for documentation
|
|
||||||
set(EXAMPLE_LIST "${CMAKE_CURRENT_BINARY_DIR}/example_list.md")
|
|
||||||
file(WRITE ${EXAMPLE_LIST} "# Examples")
|
|
||||||
get_property(EXAMPLES GLOBAL PROPERTY FTXUI::EXAMPLES)
|
|
||||||
foreach(EXAMPLE IN LISTS EXAMPLES)
|
|
||||||
file(APPEND ${EXAMPLE_LIST} "\n@example examples/${EXAMPLE}.cpp")
|
|
||||||
endforeach(EXAMPLE IN LISTS EXAMPLES)
|
|
||||||
|
|
||||||
configure_file(Doxyfile.in Doxyfile @ONLY)
|
|
||||||
|
|
||||||
# note the option ALL which allows to build the docs together with the application
|
|
||||||
add_custom_target(doc
|
|
||||||
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
|
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
|
||||||
COMMENT "Generating API documentation with Doxygen"
|
|
||||||
VERBATIM
|
|
||||||
)
|
|
||||||
else (DOXYGEN_FOUND)
|
|
||||||
message("Doxygen need to be installed to generate the doxygen documentation")
|
message("Doxygen need to be installed to generate the doxygen documentation")
|
||||||
endif (DOXYGEN_FOUND)
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Generate example list for documentation
|
||||||
|
set(EXAMPLE_LIST "${CMAKE_CURRENT_BINARY_DIR}/example_list.md")
|
||||||
|
file(WRITE ${EXAMPLE_LIST} "# Examples")
|
||||||
|
get_property(EXAMPLES GLOBAL PROPERTY FTXUI::EXAMPLES)
|
||||||
|
foreach(EXAMPLE IN LISTS EXAMPLES)
|
||||||
|
file(APPEND ${EXAMPLE_LIST} "\n@example examples/${EXAMPLE}.cpp")
|
||||||
|
endforeach(EXAMPLE IN LISTS EXAMPLES)
|
||||||
|
|
||||||
|
configure_file(Doxyfile.in Doxyfile @ONLY)
|
||||||
|
|
||||||
|
# note the option ALL which allows to build the docs together with the application
|
||||||
|
add_custom_target(doc
|
||||||
|
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
COMMENT "Generating API documentation with Doxygen"
|
||||||
|
VERBATIM
|
||||||
|
)
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
if(NOT FTXUI_BUILD_EXAMPLES)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
set(EXAMPLES_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
set(EXAMPLES_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
function(example name)
|
function(example name)
|
||||||
add_executable(ftxui_example_${name} ${name}.cpp)
|
add_executable(ftxui_example_${name} ${name}.cpp)
|
||||||
|
Loading…
Reference in New Issue
Block a user