Skip to content

Commit d47bdc8

Browse files
Fix building of samples due to incosistent c++ standard
1 parent 914eff5 commit d47bdc8

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

samples/CXX11/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.3.0)
1+
if (NOT CMAKE_VERSION VERSION_LESS 3.3.0)
22
cmake_minimum_required(VERSION 3.3)
33

44
if(cxx_std_11 IN_LIST CMAKE_CXX_COMPILE_FEATURES)

samples/CXX11/Main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int main()
2020
std::unordered_set<std::string> unorderedSet = { "red", "green", "blue" };
2121
PLOG_INFO << unorderedSet;
2222

23-
std::array<int, 4> array = {1, 2, 3, 4};
23+
std::array<int, 4> array = {{1, 2, 3, 4}};
2424
PLOG_INFO << array;
2525

2626
return 0;

samples/CXX17/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.3.0)
1+
if (NOT CMAKE_VERSION VERSION_LESS 3.3.0)
22
cmake_minimum_required(VERSION 3.3)
33

4-
if(cxx_std_17 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
4+
# Unfortunately cxx_std_17 in CMAKE_CXX_COMPILE_FEATURES is not reliable, so check include files
5+
include(CheckIncludeFileCXX)
6+
CHECK_INCLUDE_FILE_CXX("string_view" HAS_STRING_VIEW)
7+
CHECK_INCLUDE_FILE_CXX("filesystem" HAS_FILESYSTEM)
8+
9+
if(HAS_STRING_VIEW AND HAS_FILESYSTEM)
510
add_executable(CXX17 Main.cpp)
611
target_link_libraries(CXX17 plog::plog)
712
set_target_properties(CXX17 PROPERTIES FOLDER Samples CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)

0 commit comments

Comments
 (0)