]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
ENH: Allow setting the C_STANDARD version from command line
authorHans Johnson <hans-johnson@uiowa.edu>
Wed, 16 Jan 2019 15:41:53 +0000 (09:41 -0600)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Thu, 31 Jan 2019 12:07:20 +0000 (13:07 +0100)
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.

CMakeLists.txt

index a946973399b15a4bb21312cbe2eb87edec4941d0..3fabc77d8e04be4c4fbd2aa95d8ee7b8887ba2df 100644 (file)
@@ -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)