From 6ce88c25e5ba7dd27a3ce726949d74b114988fe4 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Thu, 25 May 2023 19:34:34 +0200 Subject: [PATCH] CMake: use compile_features to set min C++ standard (#647) --- cmake/ftxui_fuzzer.cmake | 17 +++++------------ cmake/ftxui_set_options.cmake | 14 +------------- cmake/ftxui_test.cmake | 8 ++++++-- examples/CMakeLists.txt | 4 +--- 4 files changed, 13 insertions(+), 30 deletions(-) diff --git a/cmake/ftxui_fuzzer.cmake b/cmake/ftxui_fuzzer.cmake index 8a2fb1d..edddb78 100644 --- a/cmake/ftxui_fuzzer.cmake +++ b/cmake/ftxui_fuzzer.cmake @@ -10,18 +10,11 @@ function(fuzz name) add_executable(${name} src/ftxui/component/${name}.cpp ) - target_include_directories(${name} - PRIVATE src - ) - target_link_libraries(${name} - PRIVATE component - ) - target_compile_options(${name} - PRIVATE -fsanitize=fuzzer,address - ) - target_link_libraries(${name} - PRIVATE -fsanitize=fuzzer,address - ) + target_include_directories(${name} PRIVATE src) + target_link_libraries(${name} PRIVATE component) + target_compile_options(${name} PRIVATE -fsanitize=fuzzer,address) + target_link_libraries(${name} PRIVATE -fsanitize=fuzzer,address) + target_compile_features(${name} PRIVATE cxx_std_17) endfunction(fuzz) fuzz(terminal_input_parser_test_fuzzer) diff --git a/cmake/ftxui_set_options.cmake b/cmake/ftxui_set_options.cmake index 6053910..1fb4490 100644 --- a/cmake/ftxui_set_options.cmake +++ b/cmake/ftxui_set_options.cmake @@ -43,19 +43,7 @@ function(ftxui_set_options library) $ ) - # Play nicely if we are being consumed by another project - # and use their CMAKE_CXX_STANDARD. Otherwise, fall back to 17 - # C++17 is used. We require fold expression at least. - if (DEFINED CMAKE_CXX_STANDARD) - set(CXX_STANDARD ${CMAKE_CXX_STANDARD}) - else() - set(CXX_STANDARD 17) - endif() - - set_target_properties(${library} PROPERTIES - CXX_STANDARD ${CXX_STANDARD} - CXX_EXTENSIONS OFF - ) + target_compile_features(${library} PUBLIC cxx_std_17) # Force Microsoft Visual Studio to decode sources files in UTF-8. This applies # to the library and the library users. diff --git a/cmake/ftxui_test.cmake b/cmake/ftxui_test.cmake index 456fcb8..3c9850d 100644 --- a/cmake/ftxui_test.cmake +++ b/cmake/ftxui_test.cmake @@ -57,8 +57,12 @@ target_link_libraries(ftxui-tests target_include_directories(ftxui-tests PRIVATE src ) -ftxui_set_options(ftxui-tests) -target_compile_features(ftxui-tests PUBLIC cxx_std_20) +target_compile_features(ftxui-tests PRIVATE cxx_std_20) + +if (FTXUI_MICROSOFT_TERMINAL_FALLBACK) + target_compile_definitions(ftxui-tests + PRIVATE "FTXUI_MICROSOFT_TERMINAL_FALLBACK") +endif() include(GoogleTest) gtest_discover_tests(ftxui-tests diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index ecfa932..af46c21 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -8,9 +8,7 @@ function(example name) target_link_libraries(ftxui_example_${name} PUBLIC ${DIRECTORY_LIB}) file(RELATIVE_PATH dir ${EXAMPLES_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) set_property(GLOBAL APPEND PROPERTY FTXUI::EXAMPLES ${dir}/${name}) - set_target_properties(ftxui_example_${name} PROPERTIES - CXX_STANDARD 20 - ) + target_compile_features(ftxui_example_${name} PRIVATE cxx_std_17) endfunction(example) add_subdirectory(component)