Skip to content

Commit 3306953

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

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
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: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@ int main()
1414
{
1515
plog::init<plog::TxtFormatter>(plog::debug, plog::streamStdOut); // Initialize logging
1616

17-
std::unordered_map<std::string, int> unorderedMap = { {"red", 1}, {"green", 2}, {"blue", 4} };
17+
std::unordered_map<std::string, int> unorderedMap;
18+
unorderedMap["red"] = 1;
19+
unorderedMap["green"] = 2;
20+
unorderedMap["blue"] = 4;
1821
PLOG_INFO << unorderedMap;
1922

20-
std::unordered_set<std::string> unorderedSet = { "red", "green", "blue" };
23+
std::unordered_set<std::string> unorderedSet;
24+
unorderedSet.insert("red");
25+
unorderedSet.insert("green");
26+
unorderedSet.insert("blue");
2127
PLOG_INFO << unorderedSet;
2228

23-
std::array<int, 4> array = {1, 2, 3, 4};
29+
std::array<int, 4> array = {{1, 2, 3, 4}};
2430
PLOG_INFO << array;
2531

2632
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)