From 24e108a81b7e51f016c1a6bb620a3a5ee4d19ced Mon Sep 17 00:00:00 2001 From: Alastair Robertson Date: Fri, 19 May 2023 07:47:37 -0700 Subject: [PATCH] Enable compiler warnings globally With the previous method of enabling them on a target-by-target basis, it was very easy to accidentally miss a target. This had happened in a number of instances, e.g. "codegen" and "symbol_service". --- CMakeLists.txt | 8 ++------ cmake/CompilerWarnings.cmake | 4 ++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a406a4..7c53400 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,8 @@ option(WITH_FLAKY_TESTS "Build with flaky tests" On) option(FORCE_BOOST_STATIC "Build with static boost" On) option(FORCE_LLVM_STATIC "Build with static llvm and clang" On) +set_project_warnings() + if (ASAN) add_compile_options(-fsanitize=address -fno-omit-frame-pointer) add_link_options(-fsanitize=address) @@ -38,7 +40,6 @@ if (CODE_COVERAGE) endif() - ## System checks ## These checks are potentially fatal so perform them first. @@ -251,7 +252,6 @@ add_library(oicore oi/Serialize.cpp ) add_dependencies(oicore libdrgn) -set_project_warnings(oicore) target_include_directories(oicore SYSTEM PRIVATE ${LLVM_INCLUDE_DIRS} ${CLANG_INCLUDE_DIRS}) target_compile_definitions(oicore PRIVATE ${LLVM_DEFINITIONS}) @@ -311,7 +311,6 @@ add_executable(oilgen tools/OILGen.cpp oi/OIGenerator.cpp ) - target_link_libraries(oilgen drgn_utils oicore @@ -319,17 +318,14 @@ target_link_libraries(oilgen ### Object Introspection cache Printer (OIP) add_executable(oip tools/OIP.cpp) -set_project_warnings(oip) target_link_libraries(oip oicore) ### Object Introspection Tree Builder (OITB) add_executable(oitb tools/OITB.cpp) -set_project_warnings(oitb) target_link_libraries(oitb oicore treebuilder) ### Object Introspection Debugger (OID) add_executable(oid oi/OID.cpp oi/OIDebugger.cpp) -set_project_warnings(oid) target_link_libraries(oid oicore oid_parser treebuilder) if (STATIC_LINK) diff --git a/cmake/CompilerWarnings.cmake b/cmake/CompilerWarnings.cmake index c968140..e875078 100644 --- a/cmake/CompilerWarnings.cmake +++ b/cmake/CompilerWarnings.cmake @@ -1,6 +1,6 @@ # https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md -function(set_project_warnings project_name) +function(set_project_warnings) option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" OFF) set(MSVC_WARNINGS @@ -79,6 +79,6 @@ function(set_project_warnings project_name) message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.") endif() - target_compile_options(${project_name} PUBLIC ${PROJECT_WARNINGS}) + add_compile_options(${PROJECT_WARNINGS}) endfunction()