mirror of
				https://github.com/ArthurSonzogni/FTXUI.git
				synced 2025-10-31 18:48:11 +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:
		| @@ -1,31 +1,21 @@ | ||||
| if (NOT WIN32) | ||||
|   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(NOT googlebenchmark_POPULATED) | ||||
|     FetchContent_Populate(googlebenchmark) | ||||
|     add_subdirectory( | ||||
|       ${googlebenchmark_SOURCE_DIR} | ||||
|       ${googlebenchmark_BINARY_DIR} | ||||
|       EXCLUDE_FROM_ALL | ||||
| if (NOT FTXUI_BUILD_TESTS OR | ||||
|     NOT ${CMAKE_VERSION} VERSION_GREATER "3.11.4" OR | ||||
|     WIN32 | ||||
|     ) | ||||
|   endif() | ||||
|  | ||||
|   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 | ||||
|   ) | ||||
|   return() | ||||
| 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_CXX_COMPILER clang++) | ||||
|  | ||||
|   | ||||
| @@ -1,3 +1,7 @@ | ||||
| if(NOT FTXUI_ENABLE_INSTALL) | ||||
|   return() | ||||
| endif() | ||||
|  | ||||
| include(GNUInstallDirs) | ||||
| install(TARGETS screen dom component | ||||
|     EXPORT ftxui-export | ||||
|   | ||||
| @@ -1,3 +1,7 @@ | ||||
| if(NOT FTXUI_ENABLE_INSTALL) | ||||
|   return() | ||||
| endif() | ||||
|  | ||||
| if (UNIX AND NOT APPLE) | ||||
|   set(CPACK_GENERATOR "DEB;External;RPM;STGZ;TBZ2;TGZ;TXZ;TZ;TZST;ZIP") | ||||
| 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) | ||||
|   message(STATUS "clang-tidy not found.") | ||||
| else() | ||||
|   message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}") | ||||
| endif() | ||||
|  | ||||
|  | ||||
| function(ftxui_set_options library) | ||||
|   set_target_properties(${library} PROPERTIES | ||||
|     VERSION ${PROJECT_VERSION} | ||||
|     OUTPUT_NAME "ftxui-${library}" | ||||
|   ) | ||||
|   message(STATUS "ftxui_set_options " ${library}) | ||||
|   set_target_properties(${library} PROPERTIES VERSION ${PROJECT_VERSION}) | ||||
|   if (NOT ${library} MATCHES "ftxui-*") | ||||
|     set_target_properties(${library} PROPERTIES OUTPUT_NAME "ftxui-${library}") | ||||
|   endif() | ||||
|  | ||||
|   if(CLANG_TIDY_EXE AND FTXUI_CLANG_TIDY) | ||||
|     set_target_properties(${library} | ||||
| @@ -44,7 +44,11 @@ function(ftxui_set_options library) | ||||
|   ) | ||||
|  | ||||
|   # 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 | ||||
|   # to the library and the library users. | ||||
| @@ -80,9 +84,7 @@ function(ftxui_set_options library) | ||||
| endfunction() | ||||
|  | ||||
| if (EMSCRIPTEN) | ||||
|   #string(APPEND CMAKE_CXX_FLAGS " -s ASSERTIONS=1") | ||||
|   string(APPEND CMAKE_CXX_FLAGS " -s USE_PTHREADS") | ||||
|   string(APPEND CMAKE_EXE_LINKER_FLAGS " -s ASYNCIFY") | ||||
|   string(APPEND CMAKE_EXE_LINKER_FLAGS " -s PROXY_TO_PTHREAD") | ||||
| endif() | ||||
|  | ||||
|   | ||||
| @@ -1,28 +1,13 @@ | ||||
| enable_testing() | ||||
|  | ||||
| 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(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 | ||||
|   ) | ||||
| if (NOT FTXUI_BUILD_TESTS OR | ||||
|     NOT ${CMAKE_VERSION} VERSION_GREATER "3.11.4") | ||||
|   return() | ||||
| 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/button_test.cpp | ||||
|   src/ftxui/component/collapsible_test.cpp | ||||
| @@ -63,25 +48,18 @@ add_executable(tests | ||||
|   src/ftxui/screen/string_test.cpp | ||||
| ) | ||||
|  | ||||
| target_link_libraries(tests | ||||
| target_link_libraries(ftxui-tests | ||||
|   PRIVATE component | ||||
|   PRIVATE gtest | ||||
|   PRIVATE gtest_main | ||||
|   PRIVATE GTest::gtest | ||||
|   PRIVATE GTest::gtest_main | ||||
| ) | ||||
| target_include_directories(tests | ||||
| target_include_directories(ftxui-tests | ||||
|   PRIVATE src | ||||
| ) | ||||
| ftxui_set_options(tests) | ||||
| target_compile_features(tests PUBLIC cxx_std_20) | ||||
| ftxui_set_options(ftxui-tests) | ||||
| target_compile_features(ftxui-tests PUBLIC cxx_std_20) | ||||
|  | ||||
| include(GoogleTest) | ||||
| gtest_discover_tests(tests | ||||
| gtest_discover_tests(ftxui-tests | ||||
|   DISCOVERY_TIMEOUT 600 | ||||
| ) | ||||
|  | ||||
|  | ||||
| include(cmake/ftxui_benchmark.cmake) | ||||
|  | ||||
| if (FTXUI_BUILD_TESTS_FUZZER) | ||||
|   include(cmake/ftxui_fuzzer.cmake) | ||||
| endif() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Arthur Sonzogni
					Arthur Sonzogni