2017-03-16 15:24:33 +00:00
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
include(CheckCCompilerFlag)
|
|
|
|
|
|
|
|
function(EnableCompilerFlag _flag _C _CXX)
|
2017-04-20 22:54:17 +00:00
|
|
|
string(REGEX REPLACE "\\+" "PLUS" varname "${_flag}")
|
|
|
|
string(REGEX REPLACE "[^A-Za-z0-9]+" "_" varname "${varname}")
|
|
|
|
string(REGEX REPLACE "^_+" "" varname "${varname}")
|
|
|
|
string(TOUPPER "${varname}" varname)
|
2017-03-16 15:24:33 +00:00
|
|
|
if (_C)
|
2017-04-20 22:54:17 +00:00
|
|
|
CHECK_C_COMPILER_FLAG(${_flag} C_FLAG_${varname})
|
|
|
|
if (C_FLAG_${varname})
|
2017-04-20 22:55:48 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_flag}" PARENT_SCOPE)
|
2017-03-16 15:24:33 +00:00
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
if (_CXX)
|
2017-04-20 22:54:17 +00:00
|
|
|
CHECK_CXX_COMPILER_FLAG(${_flag} CXX_FLAG_${varname})
|
|
|
|
if (CXX_FLAG_${varname})
|
2017-04-20 22:55:48 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flag}" PARENT_SCOPE)
|
2017-03-16 15:24:33 +00:00
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
endfunction()
|
|
|
|
|
2017-04-20 22:46:44 +00:00
|
|
|
MACRO(ADD_ZSTD_COMPILATION_FLAGS)
|
2017-03-21 20:44:33 +00:00
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" OR MINGW) #Not only UNIX but also WIN32 for MinGW
|
2016-01-07 10:37:00 +00:00
|
|
|
#Set c++11 by default
|
2017-03-16 15:24:33 +00:00
|
|
|
EnableCompilerFlag("-std=c++11" false true)
|
2016-01-07 10:37:00 +00:00
|
|
|
#Set c99 by default
|
2017-03-16 15:24:33 +00:00
|
|
|
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)
|
|
|
|
elseif (MSVC) # Add specific compilation flags for Windows Visual
|
|
|
|
EnableCompilerFlag("/Wall" true true)
|
2016-01-07 10:37:00 +00:00
|
|
|
|
2016-01-10 11:20:52 +00:00
|
|
|
# Only for DEBUG version
|
2017-03-16 15:24:33 +00:00
|
|
|
EnableCompilerFlag("/RTC1" true true)
|
|
|
|
EnableCompilerFlag("/Zc:forScope" true true)
|
|
|
|
EnableCompilerFlag("/Gd" true true)
|
|
|
|
EnableCompilerFlag("/analyze:stacksize25000" true true)
|
|
|
|
|
2016-01-07 10:37:00 +00:00
|
|
|
if (MSVC80 OR MSVC90 OR MSVC10 OR MSVC11)
|
|
|
|
# To avoid compiler warning (level 4) C4571, compile with /EHa if you still want
|
|
|
|
# your catch(...) blocks to catch structured exceptions.
|
2017-03-16 15:24:33 +00:00
|
|
|
EnableCompilerFlag("/EHa" false true)
|
2016-01-07 10:37:00 +00:00
|
|
|
endif (MSVC80 OR MSVC90 OR MSVC10 OR MSVC11)
|
|
|
|
|
2017-03-16 15:24:33 +00:00
|
|
|
set(ACTIVATE_MULTITHREADED_COMPILATION "ON" CACHE BOOL "activate multi-threaded compilation (/MP flag)")
|
2016-01-07 10:37:00 +00:00
|
|
|
if (ACTIVATE_MULTITHREADED_COMPILATION)
|
2017-03-16 15:24:33 +00:00
|
|
|
EnableCompilerFlag("/MP" true true)
|
|
|
|
endif ()
|
2016-01-07 10:37:00 +00:00
|
|
|
|
|
|
|
#For exceptions
|
2017-03-16 15:24:33 +00:00
|
|
|
EnableCompilerFlag("/EHsc" true true)
|
2016-01-10 11:20:52 +00:00
|
|
|
|
|
|
|
# UNICODE SUPPORT
|
2017-03-16 15:24:33 +00:00
|
|
|
EnableCompilerFlag("/D_UNICODE" true true)
|
|
|
|
EnableCompilerFlag("/DUNICODE" true true)
|
2016-01-07 10:37:00 +00:00
|
|
|
endif ()
|
|
|
|
|
|
|
|
# Remove duplicates compilation flags
|
2017-03-16 15:24:33 +00:00
|
|
|
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)
|
|
|
|
separate_arguments(${flag_var})
|
|
|
|
list(REMOVE_DUPLICATES ${flag_var})
|
|
|
|
string(REPLACE ";" " " ${flag_var} "${${flag_var}}")
|
2017-04-20 22:55:48 +00:00
|
|
|
ENDFOREACH (flag_var)
|
2016-01-07 10:37:00 +00:00
|
|
|
|
|
|
|
if (MSVC)
|
|
|
|
# Replace /MT to /MD flag
|
2017-03-16 15:24:33 +00:00
|
|
|
# Replace /O2 to /O3 flag
|
2016-01-07 10:37:00 +00:00
|
|
|
FOREACH (flag_var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
|
2017-03-16 15:24:33 +00:00
|
|
|
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)
|
2016-01-07 10:37:00 +00:00
|
|
|
STRING(REGEX REPLACE "/MT" "/MD" ${flag_var} "${${flag_var}}")
|
2017-03-16 15:24:33 +00:00
|
|
|
STRING(REGEX REPLACE "/O2" "/Ox" ${flag_var} "${${flag_var}}")
|
2017-04-20 22:55:48 +00:00
|
|
|
ENDFOREACH (flag_var)
|
2016-01-07 10:37:00 +00:00
|
|
|
endif ()
|
|
|
|
|
2017-04-20 22:46:44 +00:00
|
|
|
ENDMACRO(ADD_ZSTD_COMPILATION_FLAGS)
|