summaryrefslogtreecommitdiffstats
path: root/cmake/GodotCompilerWarnings.cmake
diff options
context:
space:
mode:
authorSamuel Nicholas <nicholas.samuel@gmail.com>2024-09-19 08:11:03 +0930
committerSamuel Nicholas <nicholas.samuel@gmail.com>2024-09-24 16:27:28 +0930
commit2402a044ebc2189f6c725b9a64c66c9bc2e5c616 (patch)
tree62a9a2531e97373cb9509ccbdbbebf3460790d46 /cmake/GodotCompilerWarnings.cmake
parent64221facda062dfb09cb50bcccb9c1fcb3881088 (diff)
downloadredot-cpp-2402a044ebc2189f6c725b9a64c66c9bc2e5c616.tar.gz
Re-Structure cmake solution to be closer to the scons solution.
This is just a single step, re-arranging the code without actually changing its functionality. new docs/cmake.md moved the block of comments from the start of the CMakeLists.txt into the cmake.md file and converted content to markdown. new cmake/godotcpp.cmake Moved all exposed options into a new function godotcpp_options() Moved configuration and generation code into godotcpp_generate() To get all the options into the godotcpp_options() I changed the logic of GODOT_USE_HOT_RELOAD which I believe is a closer match to scons, that if the options is not set, and the build type is not release, then it defaults to ON. I msvc builds require the default flags to be modified or it will throw errors. I have added the links to articles in the commit, but its about removing the runtime error checks /RTC1 from the CMAKE_CXX_FLAGS_DEBUG variable. This needs to happen before the files are included. https://stackoverflow.com/questions/74426638/how-to-remove-rtc1-from-specific-target-or-file-in-cmake https://discourse.cmake.org/t/how-do-i-remove-compile-options-from-target/5965 Renamed GodotCompilerWarnings.cmake to common_compiler_flags.cmake to match scons Included files explicitly by path, as we dont need to append to the CMAKE_MODULES_PATH which effects the whole build tree. This prevents consumers of the library from clobbering the names of the cmake include files and breaking the build.
Diffstat (limited to 'cmake/GodotCompilerWarnings.cmake')
-rw-r--r--cmake/GodotCompilerWarnings.cmake94
1 files changed, 0 insertions, 94 deletions
diff --git a/cmake/GodotCompilerWarnings.cmake b/cmake/GodotCompilerWarnings.cmake
deleted file mode 100644
index 9455641..0000000
--- a/cmake/GodotCompilerWarnings.cmake
+++ /dev/null
@@ -1,94 +0,0 @@
-# Add warnings based on compiler & version
-# Set some helper variables for readability
-set( compiler_less_than_v8 "$<VERSION_LESS:$<CXX_COMPILER_VERSION>,8>" )
-set( compiler_greater_than_or_equal_v9 "$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,9>" )
-set( compiler_greater_than_or_equal_v11 "$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,11>" )
-set( compiler_less_than_v11 "$<VERSION_LESS:$<CXX_COMPILER_VERSION>,11>" )
-set( compiler_greater_than_or_equal_v12 "$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,12>" )
-
-# These compiler options reflect what is in godot/SConstruct.
-target_compile_options( ${PROJECT_NAME} PRIVATE
- # MSVC only
- $<${compiler_is_msvc}:
- /W4
-
- # Disable warnings which we don't plan to fix.
- /wd4100 # C4100 (unreferenced formal parameter): Doesn't play nice with polymorphism.
- /wd4127 # C4127 (conditional expression is constant)
- /wd4201 # C4201 (non-standard nameless struct/union): Only relevant for C89.
- /wd4244 # C4244 C4245 C4267 (narrowing conversions): Unavoidable at this scale.
- /wd4245
- /wd4267
- /wd4305 # C4305 (truncation): double to float or real_t, too hard to avoid.
- /wd4514 # C4514 (unreferenced inline function has been removed)
- /wd4714 # C4714 (function marked as __forceinline not inlined)
- /wd4820 # C4820 (padding added after construct)
- >
-
- # Clang and GNU common options
- $<$<OR:${compiler_is_clang},${compiler_is_gnu}>:
- -Wall
- -Wctor-dtor-privacy
- -Wextra
- -Wno-unused-parameter
- -Wnon-virtual-dtor
- -Wwrite-strings
- >
-
- # Clang only
- $<${compiler_is_clang}:
- -Wimplicit-fallthrough
- -Wno-ordered-compare-function-pointers
- >
-
- # GNU only
- $<${compiler_is_gnu}:
- -Walloc-zero
- -Wduplicated-branches
- -Wduplicated-cond
- -Wno-misleading-indentation
- -Wplacement-new=1
- -Wshadow-local
- -Wstringop-overflow=4
- >
- $<$<AND:${compiler_is_gnu},${compiler_less_than_v8}>:
- # Bogus warning fixed in 8+.
- -Wno-strict-overflow
- >
- $<$<AND:${compiler_is_gnu},${compiler_greater_than_or_equal_v9}>:
- -Wattribute-alias=2
- >
- $<$<AND:${compiler_is_gnu},${compiler_greater_than_or_equal_v11}>:
- # Broke on MethodBind templates before GCC 11.
- -Wlogical-op
- >
- $<$<AND:${compiler_is_gnu},${compiler_less_than_v11}>:
- # Regression in GCC 9/10, spams so much in our variadic templates that we need to outright disable it.
- -Wno-type-limits
- >
- $<$<AND:${compiler_is_gnu},${compiler_greater_than_or_equal_v12}>:
- # False positives in our error macros, see GH-58747.
- -Wno-return-type
- >
-)
-
-# Treat warnings as errors
-function( set_warning_as_error )
- message( STATUS "[${PROJECT_NAME}] Treating warnings as errors")
- if ( CMAKE_VERSION VERSION_GREATER_EQUAL "3.24" )
- set_target_properties( ${PROJECT_NAME}
- PROPERTIES
- COMPILE_WARNING_AS_ERROR ON
- )
- else()
- target_compile_options( ${PROJECT_NAME}
- PRIVATE
- $<${compiler_is_msvc}:/WX>
- $<$<OR:${compiler_is_clang},${compiler_is_gnu}>:-Werror>
- )
- endif()
-endfunction()
-
-if ( GODOT_WARNING_AS_ERROR )
- set_warning_as_error()
-endif()