From 3cc4705dd207255c05f5d02792d3865487203388 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Wed, 6 Mar 2024 22:21:24 +0100 Subject: [PATCH] cmake: build OBJC sources with warning & error flags, ignoring deprecated declarations --- CMakeLists.txt | 1 - cmake/sdlcompilers.cmake | 37 ++++++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1cce17fc0..282a2591a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -589,7 +589,6 @@ if(USE_GCC OR USE_CLANG OR USE_INTELCC OR USE_QCC) cmake_pop_check_state() if(APPLE) - # FIXME: don't use deprecated declarations check_c_compiler_flag(-Wno-error=deprecated-declarations COMPILER_SUPPORTS_WNO_ERROR_DEPRECATED_DECLARATIONS) if(COMPILER_SUPPORTS_WNO_ERROR_DEPRECATED_DECLARATIONS) sdl_compile_options(PRIVATE "-Wno-error=deprecated-declarations") diff --git a/cmake/sdlcompilers.cmake b/cmake/sdlcompilers.cmake index 5fd3081b4..81b5f8369 100644 --- a/cmake/sdlcompilers.cmake +++ b/cmake/sdlcompilers.cmake @@ -19,6 +19,13 @@ macro(SDL_DetectCompiler) endif() endmacro() +function(sdl_target_compile_option_all_languages TARGET OPTION) + target_compile_options(${TARGET} PRIVATE "$<$:${OPTION}>") + if(CMAKE_OBJC_COMPILER) + target_compile_options(${TARGET} PRIVATE "$<$:${OPTION}>") + endif() +endfunction() + function(SDL_AddCommonCompilerFlags TARGET) option(SDL_WERROR "Enable -Werror" OFF) @@ -41,20 +48,20 @@ function(SDL_AddCommonCompilerFlags TARGET) if(MSVC_CLANG) target_compile_options(${TARGET} PRIVATE "/W3") elseif(HAVE_GCC_WALL) - target_compile_options(${TARGET} PRIVATE "-Wall") + sdl_target_compile_option_all_languages(${TARGET} "-Wall") if(HAIKU) - target_compile_options(${TARGET} PRIVATE "-Wno-multichar") + sdl_target_compile_option_all_languages(${TARGET} "-Wno-multichar") endif() endif() check_c_compiler_flag(-Wundef HAVE_GCC_WUNDEF) if(HAVE_GCC_WUNDEF) - target_compile_options(${TARGET} PRIVATE "$<$:-Wundef>") + sdl_target_compile_option_all_languages(${TARGET} "-Wundef") endif() check_c_compiler_flag(-fno-strict-aliasing HAVE_GCC_NO_STRICT_ALIASING) if(HAVE_GCC_NO_STRICT_ALIASING) - target_compile_options(${TARGET} PRIVATE "$<$:-fno-strict-aliasing>") + sdl_target_compile_option_all_languages(${TARGET} "-fno-strict-aliasing") endif() check_c_compiler_flag(-Wdocumentation HAVE_GCC_WDOCUMENTATION) @@ -62,10 +69,10 @@ function(SDL_AddCommonCompilerFlags TARGET) if(SDL_WERROR) check_c_compiler_flag(-Werror=documentation HAVE_GCC_WERROR_DOCUMENTATION) if(HAVE_GCC_WERROR_DOCUMENTATION) - target_compile_options(${TARGET} PRIVATE "$<$:-Werror=documentation>") + sdl_target_compile_option_all_languages(${TARGET} "-Werror=documentation") endif() endif() - target_compile_options(${TARGET} PRIVATE "$<$:-Wdocumentation>") + sdl_target_compile_option_all_languages(${TARGET} "-Wdocumentation") endif() check_c_compiler_flag(-Wdocumentation-unknown-command HAVE_GCC_WDOCUMENTATION_UNKNOWN_COMMAND) @@ -73,30 +80,30 @@ function(SDL_AddCommonCompilerFlags TARGET) if(SDL_WERROR) check_c_compiler_flag(-Werror=documentation-unknown-command HAVE_GCC_WERROR_DOCUMENTATION_UNKNOWN_COMMAND) if(HAVE_GCC_WERROR_DOCUMENTATION_UNKNOWN_COMMAND) - target_compile_options(${TARGET} PRIVATE "$<$:-Werror=documentation-unknown-command>") + sdl_target_compile_option_all_languages(${TARGET} "-Werror=documentation-unknown-command") endif() endif() - target_compile_options(${TARGET} PRIVATE "$<$:-Wdocumentation-unknown-command>") + sdl_target_compile_option_all_languages(${TARGET} "-Wdocumentation-unknown-command") endif() check_c_compiler_flag(-fcomment-block-commands=threadsafety HAVE_GCC_COMMENT_BLOCK_COMMANDS) if(HAVE_GCC_COMMENT_BLOCK_COMMANDS) - target_compile_options(${TARGET} PRIVATE "$<$:-fcomment-block-commands=threadsafety>") + sdl_target_compile_option_all_languages(${TARGET} "-fcomment-block-commands=threadsafety") else() check_c_compiler_flag(/clang:-fcomment-block-commands=threadsafety HAVE_CLANG_COMMENT_BLOCK_COMMANDS) if(HAVE_CLANG_COMMENT_BLOCK_COMMANDS) - target_compile_options(${TARGET} PRIVATE "$<$:/clang:-fcomment-block-commands=threadsafety>") + sdl_target_compile_option_all_languages(${TARGET} "/clang:-fcomment-block-commands=threadsafety") endif() endif() check_c_compiler_flag(-Wshadow HAVE_GCC_WSHADOW) if(HAVE_GCC_WSHADOW) - target_compile_options(${TARGET} PRIVATE "$<$:-Wshadow>") + sdl_target_compile_option_all_languages(${TARGET} "-Wshadow") endif() check_c_compiler_flag(-Wunused-local-typedefs HAVE_GCC_WUNUSED_LOCAL_TYPEDEFS) if(HAVE_GCC_WUNUSED_LOCAL_TYPEDEFS) - target_compile_options(${TARGET} PRIVATE "$<$:-Wno-unused-local-typedefs>") + sdl_target_compile_option_all_languages(${TARGET} "-Wno-unused-local-typedefs") endif() endif() @@ -109,7 +116,7 @@ function(SDL_AddCommonCompilerFlags TARGET) elseif(USE_GCC OR USE_CLANG OR USE_INTELCC OR USE_QNX) check_c_compiler_flag(-Werror HAVE_WERROR) if(HAVE_WERROR) - target_compile_options(${TARGET} PRIVATE "$<$:-Werror>") + sdl_target_compile_option_all_languages(${TARGET} "-Werror") endif() endif() endif() @@ -117,12 +124,12 @@ function(SDL_AddCommonCompilerFlags TARGET) if(USE_CLANG) check_c_compiler_flag("-fcolor-diagnostics" COMPILER_SUPPORTS_FCOLOR_DIAGNOSTICS) if(COMPILER_SUPPORTS_FCOLOR_DIAGNOSTICS) - target_compile_options(${TARGET} PRIVATE "$<$:-fcolor-diagnostics>") + sdl_target_compile_option_all_languages(${TARGET} "-fcolor-diagnostics") endif() else() check_c_compiler_flag("-fdiagnostics-color=always" COMPILER_SUPPORTS_FDIAGNOSTICS_COLOR_ALWAYS) if(COMPILER_SUPPORTS_FDIAGNOSTICS_COLOR_ALWAYS) - target_compile_options(${TARGET} PRIVATE "$<$:-fdiagnostics-color=always>") + sdl_target_compile_option_all_languages(${TARGET} "-fdiagnostics-color=always") endif() endif() endfunction()