@@ -5,7 +5,7 @@ cmake_policy(SET CMP0091 NEW)
55endif ()
66
77set (SOFTWARE_NAME "awslc" )
8- set (SOFTWARE_VERSION "1.60 .0" )
8+ set (SOFTWARE_VERSION "1.61 .0" )
99set (ABI_VERSION 0)
1010set (CRYPTO_LIB_NAME "crypto" )
1111set (SSL_LIB_NAME "ssl" )
@@ -31,6 +31,26 @@ endif()
3131
3232include (sources .cmake)
3333include (TestBigEndian)
34+ include (CheckCCompilerFlag)
35+
36+ macro (add_flag_if_supported VARIABLE FLAG)
37+ # Create a safe, unique variable name to cache the result of the check
38+ string (MAKE_C_IDENTIFIER "HAVE_C_FLAG_${FLAG} " _CHECK_VAR_NAME)
39+
40+ # Keep configure output tidy
41+ set (CMAKE_REQUIRED_QUIET ${CMAKE_NOT_VERBOSE} )
42+
43+ # Run the check only once to speed up re-configuration
44+ if (NOT DEFINED ${_CHECK_VAR_NAME} )
45+ check_c_compiler_flag("${FLAG} " ${_CHECK_VAR_NAME} )
46+ endif ()
47+
48+ # If the check passed, append the flag to the specified variable
49+ if (${_CHECK_VAR_NAME} )
50+ set (${VARIABLE} "${${VARIABLE} } ${FLAG} " )
51+ message (STATUS "Compiler supports '${FLAG} ', adding to ${VARIABLE} " )
52+ endif ()
53+ endmacro ()
3454
3555if (POLICY CMP0077)
3656 cmake_policy (SET CMP0077 NEW) #option does nothing when a normal variable of the same name exists.
@@ -474,12 +494,9 @@ if(GCC OR CLANG)
474494 endif ()
475495 set (C_CXX_FLAGS "${C_CXX_FLAGS} -Werror -Wformat=2 -Wsign-compare -Wmissing-field-initializers -Wwrite-strings" )
476496
477- if ((GCC AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "8" ) OR
478- (CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS "13" ))
479- # GCC 8.x added a warning called -Wcast-function-type to the -Wextra umbrella.
480- # Also suppress for all clang versions supporting this warning.
481- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-cast-function-type" )
482- endif ()
497+ # GCC 8.x added a warning called -Wcast-function-type to the -Wextra umbrella.
498+ # Also suppress for all clang versions supporting this warning.
499+ add_flag_if_supported(CMAKE_C_FLAGS "-Wno-cast-function-type" )
483500
484501 if (CMAKE_BUILD_TYPE_LOWER STREQUAL "debug" OR CMAKE_BUILD_TYPE_LOWER STREQUAL "relwithdebinfo" )
485502 if (MSVC )
@@ -503,31 +520,24 @@ if(GCC OR CLANG)
503520
504521 if (CLANG)
505522 set (C_CXX_FLAGS "${C_CXX_FLAGS} -Wnewline-eof -fcolor-diagnostics" )
506- elseif (CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.1.3" )
523+ else ( )
507524 # GCC (at least 4.8.4) has a bug where it'll find unreachable free() calls
508525 # and declare that the code is trying to free a stack pointer. GCC 4.1.3 and lower
509526 # doesn't support this flag and can't use it.
510- set (C_CXX_FLAGS "${C_CXX_FLAGS} -Wno-free-nonheap-object" )
527+ add_flag_if_supported (C_CXX_FLAGS "-Wno-free-nonheap-object" )
511528 # GCC (from at least 4.8) does not include -Wmissing-braces in -Wall due to Bug 25137.
512529 # This warning is turned on everywhere internally however, so we have to define it here
513530 # to check that our changes don't break the build.
514531 # See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25137
515- set (C_CXX_FLAGS "${C_CXX_FLAGS} -Wmissing-braces" )
532+ add_flag_if_supported (C_CXX_FLAGS "-Wmissing-braces" )
516533 endif ()
517534
518535 # -Wstring-concatenation was added in Clang 12.0.0, which corresponds to
519536 # AppleClang 13.0.0 per the table in
520537 # https://en.wikipedia.org/wiki/Xcode#Toolchain_versions
521- if ((CMAKE_C_COMPILER_ID STREQUAL "Clang" AND
522- NOT (CMAKE_C_COMPILER_VERSION VERSION_LESS "12.0.0" )) OR
523- (CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND
524- NOT (CMAKE_C_COMPILER_VERSION VERSION_LESS "13.0.0" )))
525- set (C_CXX_FLAGS "${C_CXX_FLAGS} -Wstring-concatenation" )
526- endif ()
538+ add_flag_if_supported(C_CXX_FLAGS "-Wstring-concatenation" )
527539
528- if (CLANG OR NOT "7.0.0" VERSION_GREATER CMAKE_C_COMPILER_VERSION)
529- set (C_CXX_FLAGS "${C_CXX_FLAGS} -Wimplicit-fallthrough" )
530- endif ()
540+ add_flag_if_supported(C_CXX_FLAGS "-Wimplicit-fallthrough" )
531541
532542 if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "5" )
533543 set (C_CXX_FLAGS "${C_CXX_FLAGS} -Wformat-signedness" )
@@ -674,11 +684,7 @@ if(WIN32)
674684 add_definitions ("-D_STL_EXTRA_DISABLED_WARNINGS=4774 4987" )
675685endif ()
676686
677- if ((GCC AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.9.99" ) OR
678- CLANG)
679- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow" )
680- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshadow" )
681- endif ()
687+ add_flag_if_supported(C_CXX_FLAGS "-Wshadow" )
682688
683689# pthread_rwlock_t on Linux requires a feature flag. We limit this to Linux
684690# because, on Apple platforms, it instead disables APIs we use. See compat(5)
0 commit comments