cJSON

mirror of Dave's cJSON
git clone git://git.thc420.xyz/cJSON
Log | Files | Refs | README | LICENSE

commit d00ca18ac2ac4fe20c9abdba8333fe2fd5e4b553
parent 6cdb6894d42446dd679d61dc9be011078015b7e8
Author: Max Bruckner <max@maxbruckner.de>
Date:   Tue,  7 Feb 2017 14:51:29 +0100

CMake: automatic detection of compiler flag compatibility

Diffstat:
MCMakeLists.txt | 36+++++++++++++++++++++++++++++++++---
1 file changed, 33 insertions(+), 3 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -12,13 +12,43 @@ set(CJSON_VERSION_SO 1) set(CJSON_UTILS_VERSION_SO 1) set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") + +set(custom_compiler_flags) + +include(CheckCCompilerFlag) option(ENABLE_CUSTOM_COMPILER_FLAGS "Enables custom compiler flags for Clang and GCC" ON) if (ENABLE_CUSTOM_COMPILER_FLAGS) - if(("${CMAKE_C_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c89 -pedantic -Wall -Wextra -Werror -Wstrict-prototypes -Wwrite-strings -Wshadow -Winit-self -Wcast-align -Wformat=2 -Wmissing-prototypes -Wstrict-overflow=2 -Wcast-qual -Wc++-compat -Wundef -Wswitch-default -Wconversion -fstack-protector-strong") - endif() + list(APPEND custom_compiler_flags + -std=c89 + -pedantic + -Wall + -Wextra + -Werror + -Wstrict-prototypes + -Wwrite-strings + -Wshadow + -Winit-self + -Wcast-align + -Wformat=2 + -Wmissing-prototypes + -Wstrict-overflow=2 + -Wcast-qual + -Wc++-compat + -Wundef + -Wswitch-default + -Wconversion + -fstack-protector-strong + ) endif() +# apply custom compiler flags +foreach(compiler_flag ${custom_compiler_flags}) + CHECK_C_COMPILER_FLAG(${compiler_flag} "FLAG_SUPPORTED-${compiler_flag}") + if (FLAG_SUPPORTED${compiler_flag}) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${compiler_flag}") + endif() +endforeach() + #variables for pkg-config set(prefix "${CMAKE_INSTALL_PREFIX}") set(libdir "${CMAKE_INSTALL_LIBDIR}")