From 8a4563361fcd84574b29702013200437a83c68b2 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Mon, 4 Apr 2022 12:07:55 -0600 Subject: [PATCH] Set compiler warnings on a per-target, not per-file basis No 1st party SFML targets contain 3rd party source code so it's safe and correct to apply warnings to the entire target. --- cmake/CompilerWarnings.cmake | 8 +++----- cmake/Macros.cmake | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/cmake/CompilerWarnings.cmake b/cmake/CompilerWarnings.cmake index 87903b4b..1954a063 100644 --- a/cmake/CompilerWarnings.cmake +++ b/cmake/CompilerWarnings.cmake @@ -2,8 +2,8 @@ # # https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md -# Helper function to enable compiler warnings for a specific set of files -function(set_file_warnings) +# Helper function to enable compiler warnings for a specific target +function(set_target_warnings target) option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" TRUE) set(MSVC_WARNINGS @@ -106,7 +106,5 @@ function(set_file_warnings) message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.") endif() - foreach(WARNING ${FILE_WARNINGS}) - set_property(SOURCE ${ARGV} APPEND_STRING PROPERTY COMPILE_FLAGS " ${WARNING}") - endforeach() + target_compile_options(${target} PRIVATE ${FILE_WARNINGS}) endfunction() diff --git a/cmake/Macros.cmake b/cmake/Macros.cmake index d6860d6f..038cb973 100644 --- a/cmake/Macros.cmake +++ b/cmake/Macros.cmake @@ -84,7 +84,7 @@ macro(sfml_add_library module) endif() endif() - set_file_warnings(${THIS_SOURCES}) + set_target_warnings(${target}) # define the export symbol of the module string(REPLACE "-" "_" NAME_UPPER "${target}") @@ -286,7 +286,7 @@ macro(sfml_add_example target) add_executable(${target} ${target_input}) endif() - set_file_warnings(${target_input}) + set_target_warnings(${target}) # set the debug suffix set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -d)