From 24f49da39c771aaceeecb33b7d714948f379f50f Mon Sep 17 00:00:00 2001 From: Nils Wentzell Date: Wed, 26 Jun 2019 11:06:04 -0400 Subject: [PATCH] [cmake] Do not enable compiler warnings globally but instead through an interface target --- CMakeLists.txt | 22 ++++++++++++++++------ c++/app4triqs/CMakeLists.txt | 2 +- test/c++/CMakeLists.txt | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 736b0311..7cb817a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,13 +17,23 @@ set(BUILD_SHARED_LIBS OFF) # Export the list of compile-commands into compile_commands.json set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -# Enable compiler warnings for the whole project +# Global compiler options add_compile_options( - -Wall - -Wextra - $<$:-Og> - $<$:-ggdb3> - ) + $<$:-Og> + $<$:-ggdb3> +) + +# Create an Interface target for compiler warnings +add_library(project_warnings INTERFACE) +install(TARGETS project_warnings EXPORT app4triqs-targets) +target_compile_options(project_warnings + INTERFACE + -Wall + -Wextra + -Wshadow + -Wpedantic + -Wno-sign-compare +) # Load Dependencies find_package(TRIQS 2.2 REQUIRED) diff --git a/c++/app4triqs/CMakeLists.txt b/c++/app4triqs/CMakeLists.txt index 53e038b5..7bf1b64c 100644 --- a/c++/app4triqs/CMakeLists.txt +++ b/c++/app4triqs/CMakeLists.txt @@ -2,7 +2,7 @@ file(GLOB_RECURSE sources *.cpp) add_library(app4triqs_c ${sources}) # Link against dependencies -target_link_libraries(app4triqs_c PUBLIC triqs) +target_link_libraries(app4triqs_c PUBLIC triqs PRIVATE project_warnings) # Configure compilation target_compile_options(app4triqs_c PUBLIC -fPIC) diff --git a/test/c++/CMakeLists.txt b/test/c++/CMakeLists.txt index b2961064..72d47886 100644 --- a/test/c++/CMakeLists.txt +++ b/test/c++/CMakeLists.txt @@ -10,7 +10,7 @@ set(all_tests toto) foreach(test ${all_tests}) get_filename_component(test_name ${test} NAME_WE) add_executable(${test_name} ${test}) - target_link_libraries(${test_name} app4triqs_c triqs::gtest) + target_link_libraries(${test_name} app4triqs_c triqs::gtest project_warnings) add_test(${test_name} ${test_name}) # Run clang-tidy if found if(CLANG_TIDY_EXECUTABLE)