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".
This commit is contained in:
Alastair Robertson 2023-05-19 07:47:37 -07:00 committed by Alastair Robertson
parent d71a497df5
commit 24e108a81b
2 changed files with 4 additions and 8 deletions

View File

@ -27,6 +27,8 @@ option(WITH_FLAKY_TESTS "Build with flaky tests" On)
option(FORCE_BOOST_STATIC "Build with static boost" On) option(FORCE_BOOST_STATIC "Build with static boost" On)
option(FORCE_LLVM_STATIC "Build with static llvm and clang" On) option(FORCE_LLVM_STATIC "Build with static llvm and clang" On)
set_project_warnings()
if (ASAN) if (ASAN)
add_compile_options(-fsanitize=address -fno-omit-frame-pointer) add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
add_link_options(-fsanitize=address) add_link_options(-fsanitize=address)
@ -38,7 +40,6 @@ if (CODE_COVERAGE)
endif() endif()
## System checks ## System checks
## These checks are potentially fatal so perform them first. ## These checks are potentially fatal so perform them first.
@ -251,7 +252,6 @@ add_library(oicore
oi/Serialize.cpp oi/Serialize.cpp
) )
add_dependencies(oicore libdrgn) add_dependencies(oicore libdrgn)
set_project_warnings(oicore)
target_include_directories(oicore SYSTEM PRIVATE ${LLVM_INCLUDE_DIRS} ${CLANG_INCLUDE_DIRS}) target_include_directories(oicore SYSTEM PRIVATE ${LLVM_INCLUDE_DIRS} ${CLANG_INCLUDE_DIRS})
target_compile_definitions(oicore PRIVATE ${LLVM_DEFINITIONS}) target_compile_definitions(oicore PRIVATE ${LLVM_DEFINITIONS})
@ -311,7 +311,6 @@ add_executable(oilgen
tools/OILGen.cpp tools/OILGen.cpp
oi/OIGenerator.cpp oi/OIGenerator.cpp
) )
target_link_libraries(oilgen target_link_libraries(oilgen
drgn_utils drgn_utils
oicore oicore
@ -319,17 +318,14 @@ target_link_libraries(oilgen
### Object Introspection cache Printer (OIP) ### Object Introspection cache Printer (OIP)
add_executable(oip tools/OIP.cpp) add_executable(oip tools/OIP.cpp)
set_project_warnings(oip)
target_link_libraries(oip oicore) target_link_libraries(oip oicore)
### Object Introspection Tree Builder (OITB) ### Object Introspection Tree Builder (OITB)
add_executable(oitb tools/OITB.cpp) add_executable(oitb tools/OITB.cpp)
set_project_warnings(oitb)
target_link_libraries(oitb oicore treebuilder) target_link_libraries(oitb oicore treebuilder)
### Object Introspection Debugger (OID) ### Object Introspection Debugger (OID)
add_executable(oid oi/OID.cpp oi/OIDebugger.cpp) add_executable(oid oi/OID.cpp oi/OIDebugger.cpp)
set_project_warnings(oid)
target_link_libraries(oid oicore oid_parser treebuilder) target_link_libraries(oid oicore oid_parser treebuilder)
if (STATIC_LINK) if (STATIC_LINK)

View File

@ -1,6 +1,6 @@
# https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md # 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) option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" OFF)
set(MSVC_WARNINGS 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.") message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.")
endif() endif()
target_compile_options(${project_name} PUBLIC ${PROJECT_WARNINGS}) add_compile_options(${PROJECT_WARNINGS})
endfunction() endfunction()