From 034b17bbad2812400cc60dbd2ab44f5a8ee408d1 Mon Sep 17 00:00:00 2001 From: Sam Yates <sam@quux.dropbear.id.au> Date: Sat, 11 Jun 2016 12:53:35 +0200 Subject: [PATCH] Infrastructure for compiler-specific options * Add file cmake/CompilerOptions.cmake for setting up compiler specific options * Disable 'missing-braces' warning on Clang * Avoid defect in g++ 4.9.2 standard library that omits move constructor for `stdd::ifstream` * Remove signed/unsigned warning in test_optional.cpp --- CMakeLists.txt | 5 ++++- cmake/CompilerOptions.cmake | 14 ++++++++++++++ tests/test_optional.cpp | 4 ++-- tests/util.hpp | 2 +- 4 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 cmake/CompilerOptions.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d8497cb..7be418be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,10 @@ enable_language(CXX) set(SAVED_CXX_FLAGS "${CMAKE_CXX_FLAGS}") # compilation flags -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++11 -pthread -Wall") +set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") +include("CompilerOptions") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXXOPT_DEBUG} ${CXXOPT_CXX11} ${CXXOPT_PTHREAD} ${CXXOPT_WALL}") +# -g -std=c++11 -pthread -Wall") # this generates a .json file with full compilation command for each file set(CMAKE_EXPORT_COMPILE_COMMANDS "YES") diff --git a/cmake/CompilerOptions.cmake b/cmake/CompilerOptions.cmake new file mode 100644 index 00000000..e5447d88 --- /dev/null +++ b/cmake/CompilerOptions.cmake @@ -0,0 +1,14 @@ +# Compiler-aware compiler options + +set(CXXOPT_DEBUG "-g") +set(CXXOPT_PTHREAD "-pthread") +set(CXXOPT_CXX11 "-std=c++11") +set(CXXOPT_WALL "-Wall") + +if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") + # Disable 'missing-braces' warning: this will inappropriately + # flag initializations such as + # std::array<int,3> a={1,2,3}; + + set(CXXOPT_WALL "${CXXOPT_WALL} -Wno-missing-braces") +endif() diff --git a/tests/test_optional.cpp b/tests/test_optional.cpp index 64df6cac..4fe63010 100644 --- a/tests/test_optional.cpp +++ b/tests/test_optional.cpp @@ -7,7 +7,7 @@ #if defined(__clang__) // refer: https://llvm.org/bugs/show_bug.cgi?id=21629 -#pragma clang diagnostic ignored "-Wmissing-braces" +//#pragma clang diagnostic ignored "-Wmissing-braces" #endif using namespace nest::mc::util; @@ -66,7 +66,7 @@ TEST(optionalm,deref) { TEST(optionalm,ctor_conv) { optional<std::array<int,3>> x{{1,2,3}}; - EXPECT_EQ(3,x->size()); + EXPECT_EQ(3u,x->size()); } TEST(optionalm,ctor_ref) { diff --git a/tests/util.hpp b/tests/util.hpp index 6252c7e4..cfa89896 100644 --- a/tests/util.hpp +++ b/tests/util.hpp @@ -60,7 +60,7 @@ nlohmann::json load_spike_data(const std::string& input_name) { nlohmann::json cell_data; - auto fid = std::ifstream(input_name); + std::ifstream fid(input_name); if(!fid.is_open()) { std::cerr << "error : unable to open file " << input_name << " : run the validation generation script first\n"; -- GitLab