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)