From: Ivan Maidanski Date: Sat, 6 Jul 2019 05:57:41 +0000 (+0300) Subject: Support enable_werror option in CMake script X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=288c4eac78121b8d45a0891459f43ef6100d784c;p=gc Support enable_werror option in CMake script Issue #281 (bdwgc). * CMakeLists.txt (enable_werror): New option (OFF by default). * CMakeLists.txt: Specify add_compile_options to report all warnings; add TODO about pedantic. * CMakeLists.txt [enable_werror]: Specify add_compile_options to treat all warnings as errors. * CMakeLists.txt [enable_werror && APPLE]: Specify add_compile_options to ignore deprecated declarations, e.g. _dyld_bind_fully_image_containing_address. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 56a91e29..4fef247f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,19 +54,29 @@ option(enable_munmap "Return page to the OS if empty for N collections" ON) option(enable_dynamic_loading "Enable tracing of dynamic library data roots" ON) option(enable_register_main_static_data "Perform the initial guess of data root sets" ON) option(enable_checksums "Report erroneously cleared dirty bits" OFF) +option(enable_werror "Pass -Werror to the C compiler (treat warnings as errors)" OFF) option(enable_single_obj_compilation "Compile all libgc source files into single .o" OFF) option(enable_handle_fork "Attempt to ensure a usable collector after fork()" ON) option(install_headers "Install header files" ON) add_definitions("-DALL_INTERIOR_POINTERS -DNO_EXECUTE_PERMISSION") -if (APPLE) - if ("${CMAKE_OSX_ARCHITECTURES}" STREQUAL "") +if (APPLE AND ("${CMAKE_OSX_ARCHITECTURES}" STREQUAL "")) set(CMAKE_OSX_ARCHITECTURES "x86_64;i386" CACHE STRING "Build architectures for Mac OS X" FORCE) - endif() -elseif (MSVC) +endif() + +# Output all warnings. +if (MSVC) + # All warnings but ignoring "unreferenced formal parameter" and + # "conditional expression is constant" ones. + add_compile_options(/W4 /wd4100 /wd4127) + # Disable crt security warnings, since unfortunately they warn about all + # sorts of safe uses of strncpy. add_definitions("-D_CRT_SECURE_NO_DEPRECATE") +else() + # TODO add -[W]pedantic -Wno-long-long + add_compile_options(-Wall -Wextra) endif() include_directories(include) @@ -241,6 +251,18 @@ if (enable_checksums) set(SRC ${SRC} checksums.c) endif(enable_checksums) +if (enable_werror) + if (MSVC) + add_compile_options(/WX) + else() + add_compile_options(-Werror) + if (APPLE) + # _dyld_bind_fully_image_containing_address is deprecated in OS X 10.5+ + add_compile_options(-Wno-deprecated-declarations) + endif() + endif() +endif(enable_werror) + if (enable_single_obj_compilation OR BUILD_SHARED_LIBS) set(SRC extra/gc.c) # override SRC if (CMAKE_USE_PTHREADS_INIT)