From 5ee4ec40de4b121411cbe5b0cb0b69fdc40787f4 Mon Sep 17 00:00:00 2001 From: Tushar Maheshwari Date: Sat, 17 Jul 2021 12:46:02 +0530 Subject: [PATCH] Update CMake usage to enable C++17 (#156) The target_compile_features command allows setting PUBLIC compile features for the library, making it implicit for the applications linking it. This reduces the CMake boilerplate required to set up a dependent project (eg. ftxui-starter). --- cmake/ftxui_benchmark.cmake | 1 - cmake/ftxui_set_options.cmake | 4 ++-- cmake/ftxui_test.cmake | 1 - doc/mainpage.md | 3 --- examples/component/CMakeLists.txt | 1 - examples/dom/CMakeLists.txt | 1 - examples/util/CMakeLists.txt | 1 - 7 files changed, 2 insertions(+), 10 deletions(-) diff --git a/cmake/ftxui_benchmark.cmake b/cmake/ftxui_benchmark.cmake index 95ad0eb..df24458 100644 --- a/cmake/ftxui_benchmark.cmake +++ b/cmake/ftxui_benchmark.cmake @@ -16,5 +16,4 @@ if (NOT WIN32) target_include_directories(ftxui_benchmark PRIVATE src ) - set_property(TARGET ftxui_benchmark PROPERTY CXX_STANDARD 17) endif() diff --git a/cmake/ftxui_set_options.cmake b/cmake/ftxui_set_options.cmake index ecc42c9..f40ff1a 100644 --- a/cmake/ftxui_set_options.cmake +++ b/cmake/ftxui_set_options.cmake @@ -10,8 +10,8 @@ function(ftxui_set_options library) src ) - # C++17 is used. We requires fold expression at least. - set_property(TARGET ${library} PROPERTY CXX_STANDARD 17) + # C++17 is used. We require fold expression at least. + 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 cd985a8..8c73ff0 100644 --- a/cmake/ftxui_test.cmake +++ b/cmake/ftxui_test.cmake @@ -36,7 +36,6 @@ target_include_directories(tests ) 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) diff --git a/doc/mainpage.md b/doc/mainpage.md index 28efb32..efca7ea 100644 --- a/doc/mainpage.md +++ b/doc/mainpage.md @@ -83,9 +83,6 @@ target_link_libraries(ftxui-starter PRIVATE ftxui::component # Not needed for this example. ) -# C++17 is used. We requires fold expressions at least. -set_target_properties(ftxui-starter PROPERTIES CXX_STANDARD 17) - ~~~ Build diff --git a/examples/component/CMakeLists.txt b/examples/component/CMakeLists.txt index 2d66ddd..30702f5 100644 --- a/examples/component/CMakeLists.txt +++ b/examples/component/CMakeLists.txt @@ -1,7 +1,6 @@ function(example name) add_executable(${name} ${name}.cpp) target_link_libraries(${name} PUBLIC component) - set_property(TARGET ${name} PROPERTY CXX_STANDARD 17) endfunction(example) example(button) diff --git a/examples/dom/CMakeLists.txt b/examples/dom/CMakeLists.txt index 01d3c20..e750925 100644 --- a/examples/dom/CMakeLists.txt +++ b/examples/dom/CMakeLists.txt @@ -1,7 +1,6 @@ function(example name) add_executable(${name} ${name}.cpp) target_link_libraries(${name} PUBLIC dom) - set_property(TARGET ${name} PROPERTY CXX_STANDARD 17) endfunction(example) example(border) diff --git a/examples/util/CMakeLists.txt b/examples/util/CMakeLists.txt index ee10806..7b2db4f 100644 --- a/examples/util/CMakeLists.txt +++ b/examples/util/CMakeLists.txt @@ -1,7 +1,6 @@ function(example name) add_executable(${name} ${name}.cpp) target_link_libraries(${name} PUBLIC component) - set_property(TARGET ${name} PROPERTY CXX_STANDARD 17) endfunction(example) example(print_key_press)