From: Hans Johnson Date: Wed, 16 Jan 2019 15:41:53 +0000 (-0600) Subject: ENH: Allow setting the C_STANDARD version from command line X-Git-Tag: 1.9.9-b1~533 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=90d75a18f2eaf217e68cc66c9176ab38bbce8e7a;p=thirdparty%2Fzlib-ng.git ENH: Allow setting the C_STANDARD version from command line Allow for both C99 and C11 standards to be used. By default, do not support compiler extensions, but allow this setting to be overridden by the developer. The setting of the language standard needs to be performed before the "project" directive. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index a9469733..3fabc77d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,23 @@ endif() set(CMAKE_MACOSX_RPATH 1) +# If not specified on the command line, enable C99 as the default +# Configuration items that affect the global compiler envirionment standards +# should be issued before the "project" command. +if(NOT CMAKE_C_STANDARD) + set (CMAKE_C_STANDARD 99) #The C standard whose features are requested to build this target +endif() +if(NOT CMAKE_C_STANDARD_REQUIRED) + set (CMAKE_C_STANDARD_REQUIRED ON) #Boolean describing whether the value of C_STANDARD is a requirement +endif() +if(NOT CMAKE_C_EXTENSIONS) + set (CMAKE_C_EXTENSIONS OFF) #Boolean specifying whether compiler specific extensions are requested +endif() +set(VALID_C_STANDARDS "99" "11") +if(NOT CMAKE_C_STANDARD IN_LIST VALID_C_STANDARDS ) + MESSAGE(FATAL_ERROR "CMAKE_C_STANDARD:STRING=${CMAKE_C_STANDARD} not in know standards list\n ${VALID_C_STANDARDS}") +endif() + project(zlib C) set(VERSION "1.2.11") @@ -25,9 +42,6 @@ include(CheckCSourceCompiles) include(CheckCSourceRuns) include(FeatureSummary) -# Enable C99 -set (CMAKE_C_STANDARD 99) - # make sure we use an appropriate BUILD_TYPE by default, "Release" to be exact # this should select the maximum generic optimisation on the current platform (i.e. -O3 for gcc/clang) if(NOT CMAKE_BUILD_TYPE)