summaryrefslogtreecommitdiffstats
path: root/src/zstd/build/cmake/CMakeModules/AddZstdCompilationFlags.cmake
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/zstd/build/cmake/CMakeModules/AddZstdCompilationFlags.cmake
parentInitial commit. (diff)
downloadceph-upstream/16.2.11+ds.tar.xz
ceph-upstream/16.2.11+ds.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/zstd/build/cmake/CMakeModules/AddZstdCompilationFlags.cmake')
-rw-r--r--src/zstd/build/cmake/CMakeModules/AddZstdCompilationFlags.cmake79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/zstd/build/cmake/CMakeModules/AddZstdCompilationFlags.cmake b/src/zstd/build/cmake/CMakeModules/AddZstdCompilationFlags.cmake
new file mode 100644
index 000000000..186819885
--- /dev/null
+++ b/src/zstd/build/cmake/CMakeModules/AddZstdCompilationFlags.cmake
@@ -0,0 +1,79 @@
+include(CheckCXXCompilerFlag)
+include(CheckCCompilerFlag)
+
+function(EnableCompilerFlag _flag _C _CXX)
+ string(REGEX REPLACE "\\+" "PLUS" varname "${_flag}")
+ string(REGEX REPLACE "[^A-Za-z0-9]+" "_" varname "${varname}")
+ string(REGEX REPLACE "^_+" "" varname "${varname}")
+ string(TOUPPER "${varname}" varname)
+ if (_C)
+ CHECK_C_COMPILER_FLAG(${_flag} C_FLAG_${varname})
+ if (C_FLAG_${varname})
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_flag}" PARENT_SCOPE)
+ endif ()
+ endif ()
+ if (_CXX)
+ CHECK_CXX_COMPILER_FLAG(${_flag} CXX_FLAG_${varname})
+ if (CXX_FLAG_${varname})
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flag}" PARENT_SCOPE)
+ endif ()
+ endif ()
+endfunction()
+
+macro(ADD_ZSTD_COMPILATION_FLAGS)
+ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" OR MINGW) #Not only UNIX but also WIN32 for MinGW
+ #Set c++11 by default
+ EnableCompilerFlag("-std=c++11" false true)
+ #Set c99 by default
+ EnableCompilerFlag("-std=c99" true false)
+ EnableCompilerFlag("-Wall" true true)
+ EnableCompilerFlag("-Wextra" true true)
+ EnableCompilerFlag("-Wundef" true true)
+ EnableCompilerFlag("-Wshadow" true true)
+ EnableCompilerFlag("-Wcast-align" true true)
+ EnableCompilerFlag("-Wcast-qual" true true)
+ EnableCompilerFlag("-Wstrict-prototypes" true false)
+ # Enable asserts in Debug mode
+ if (CMAKE_BUILD_TYPE MATCHES "Debug")
+ EnableCompilerFlag("-DDEBUGLEVEL=1" true true)
+ endif ()
+ elseif (MSVC) # Add specific compilation flags for Windows Visual
+
+ set(ACTIVATE_MULTITHREADED_COMPILATION "ON" CACHE BOOL "activate multi-threaded compilation (/MP flag)")
+ if (CMAKE_GENERATOR MATCHES "Visual Studio" AND ACTIVATE_MULTITHREADED_COMPILATION)
+ EnableCompilerFlag("/MP" true true)
+ endif ()
+
+ # UNICODE SUPPORT
+ EnableCompilerFlag("/D_UNICODE" true true)
+ EnableCompilerFlag("/DUNICODE" true true)
+ # Enable asserts in Debug mode
+ if (CMAKE_BUILD_TYPE MATCHES "Debug")
+ EnableCompilerFlag("/DDEBUGLEVEL=1" true true)
+ endif ()
+ endif ()
+
+ # Remove duplicates compilation flags
+ foreach (flag_var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
+ CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
+ CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
+ CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
+ if( ${flag_var} )
+ separate_arguments(${flag_var})
+ list(REMOVE_DUPLICATES ${flag_var})
+ string(REPLACE ";" " " ${flag_var} "${${flag_var}}")
+ endif()
+ endforeach ()
+
+ if (MSVC AND ZSTD_USE_STATIC_RUNTIME)
+ foreach (flag_var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
+ CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
+ CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
+ CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
+ if ( ${flag_var} )
+ string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
+ endif()
+ endforeach ()
+ endif ()
+
+endmacro()