CMake: Add custom compiler flags for MSVC

This commit is contained in:
Max Bruckner 2017-06-17 14:42:52 +02:00
parent ac368e9dfb
commit e174831819
2 changed files with 39 additions and 30 deletions

View File

@ -16,37 +16,46 @@ set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT
set(custom_compiler_flags) set(custom_compiler_flags)
include(CheckCCompilerFlag) include(CheckCCompilerFlag)
option(ENABLE_CUSTOM_COMPILER_FLAGS "Enables custom compiler flags for Clang and GCC" ON) option(ENABLE_CUSTOM_COMPILER_FLAGS "Enables custom compiler flags" ON)
if (ENABLE_CUSTOM_COMPILER_FLAGS) if (ENABLE_CUSTOM_COMPILER_FLAGS)
list(APPEND custom_compiler_flags if (("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") OR ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU"))
-std=c89 list(APPEND custom_compiler_flags
-pedantic -std=c89
-Wall -pedantic
-Wextra -Wall
-Werror -Wextra
-Wstrict-prototypes -Werror
-Wwrite-strings -Wstrict-prototypes
-Wshadow -Wwrite-strings
-Winit-self -Wshadow
-Wcast-align -Winit-self
-Wformat=2 -Wcast-align
-Wmissing-prototypes -Wformat=2
-Wstrict-overflow=2 -Wmissing-prototypes
-Wcast-qual -Wstrict-overflow=2
-Wundef -Wcast-qual
-Wswitch-default -Wundef
-Wconversion -Wswitch-default
-Wc++-compat -Wconversion
-fstack-protector-strong -Wc++-compat
-Wcomma -fstack-protector-strong
-Wdouble-promotion -Wcomma
-Wparentheses -Wdouble-promotion
-Wformat-overflow -Wparentheses
-Wunused-macros -Wformat-overflow
-Wmissing-variable-declarations -Wunused-macros
-Wused-but-marked-unused -Wmissing-variable-declarations
-Wswitch-enum -Wused-but-marked-unused
-Wswitch-enum
) )
elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
list(APPEND custom_compiler_flags
/GS
/Za
/sdl
/W4
)
endif()
endif() endif()
option(ENABLE_SANITIZERS "Enables AddressSanitizer and UndefinedBehaviorSanitizer." OFF) option(ENABLE_SANITIZERS "Enables AddressSanitizer and UndefinedBehaviorSanitizer." OFF)

View File

@ -85,7 +85,7 @@ You can change the build process with a list of different options that you can p
* `-DENABLE_CJSON_TEST=On`: Enable building the tests. (on by default) * `-DENABLE_CJSON_TEST=On`: Enable building the tests. (on by default)
* `-DENABLE_CJSON_UTILS=On`: Enable building cJSON_Utils. (off by default) * `-DENABLE_CJSON_UTILS=On`: Enable building cJSON_Utils. (off by default)
* `-DENABLE_TARGET_EXPORT=On`: Enable the export of CMake targets. Turn off if it makes problems. (on by default) * `-DENABLE_TARGET_EXPORT=On`: Enable the export of CMake targets. Turn off if it makes problems. (on by default)
* `-DENABLE_CUSTOM_COMPILER_FLAGS=On`: Enable custom compiler flags (currently for Clang and GCC). Turn off if it makes problems. (on by default) * `-DENABLE_CUSTOM_COMPILER_FLAGS=On`: Enable custom compiler flags (currently for Clang, GCC and MSVC). Turn off if it makes problems. (on by default)
* `-DENABLE_VALGRIND=On`: Run tests with [valgrind](http://valgrind.org). (off by default) * `-DENABLE_VALGRIND=On`: Run tests with [valgrind](http://valgrind.org). (off by default)
* `-DENABLE_SANITIZERS=On`: Compile cJSON with [AddressSanitizer](https://github.com/google/sanitizers/wiki/AddressSanitizer) and [UndefinedBehaviorSanitizer](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html) enabled (if possible). (off by default) * `-DENABLE_SANITIZERS=On`: Compile cJSON with [AddressSanitizer](https://github.com/google/sanitizers/wiki/AddressSanitizer) and [UndefinedBehaviorSanitizer](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html) enabled (if possible). (off by default)
* `-DBUILD_SHARED_LIBS=On`: Build the shared libraries. (on by default) * `-DBUILD_SHARED_LIBS=On`: Build the shared libraries. (on by default)