summaryrefslogtreecommitdiffstats
path: root/cmake/Modules/AddCCompilerFlag.cmake
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2018-09-02 11:18:09 +0200
committerAndreas Schneider <asn@samba.org>2018-10-23 15:38:36 +0200
commitaa9b0da96927e957f6ed0b1b9d51b16db90ea2af (patch)
treea2f00464b7b71e53c07279a1317404dc9e4d5849 /cmake/Modules/AddCCompilerFlag.cmake
parent567261810523f2ab3af10268fc4a64d863ce2c93 (diff)
downloadsocket_wrapper-aa9b0da96927e957f6ed0b1b9d51b16db90ea2af.tar.gz
socket_wrapper-aa9b0da96927e957f6ed0b1b9d51b16db90ea2af.tar.xz
socket_wrapper-aa9b0da96927e957f6ed0b1b9d51b16db90ea2af.zip
cmake: Improve checks for compiler flags
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
Diffstat (limited to 'cmake/Modules/AddCCompilerFlag.cmake')
-rw-r--r--cmake/Modules/AddCCompilerFlag.cmake21
1 files changed, 21 insertions, 0 deletions
diff --git a/cmake/Modules/AddCCompilerFlag.cmake b/cmake/Modules/AddCCompilerFlag.cmake
new file mode 100644
index 0000000..c24c215
--- /dev/null
+++ b/cmake/Modules/AddCCompilerFlag.cmake
@@ -0,0 +1,21 @@
+#
+# add_c_compiler_flag("-Werror" SUPPORTED_CFLAGS)
+#
+# Copyright (c) 2018 Andreas Schneider <asn@cryptomilk.org>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+include(CheckCCompilerFlag)
+
+macro(add_c_compiler_flag _COMPILER_FLAG _OUTPUT_VARIABLE)
+ string(TOUPPER ${_COMPILER_FLAG} _COMPILER_FLAG_NAME)
+ string(REGEX REPLACE "^-" "" _COMPILER_FLAG_NAME "${_COMPILER_FLAG_NAME}")
+ string(REGEX REPLACE "(-|=|\ )" "_" _COMPILER_FLAG_NAME "${_COMPILER_FLAG_NAME}")
+
+ check_c_compiler_flag("${_COMPILER_FLAG}" WITH_${_COMPILER_FLAG_NAME}_FLAG)
+ if (WITH_${_COMPILER_FLAG_NAME}_FLAG)
+ #string(APPEND ${_OUTPUT_VARIABLE} "${_COMPILER_FLAG} ")
+ list(APPEND ${_OUTPUT_VARIABLE} ${_COMPILER_FLAG})
+ endif()
+endmacro()