2017-03-16 08:24:33 -07:00
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
include(CheckCCompilerFlag)
|
|
|
|
|
|
|
|
function(EnableCompilerFlag _flag _C _CXX)
|
2017-04-20 15:54:17 -07: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 08:24:33 -07:00
|
|
|
if (_C)
|
2017-04-20 15:54:17 -07:00
|
|
|
CHECK_C_COMPILER_FLAG(${_flag} C_FLAG_${varname})
|
|
|
|
if (C_FLAG_${varname})
|
2017-04-20 15:55:48 -07:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_flag}" PARENT_SCOPE)
|
2017-03-16 08:24:33 -07:00
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
if (_CXX)
|
2017-04-20 15:54:17 -07:00
|
|
|
CHECK_CXX_COMPILER_FLAG(${_flag} CXX_FLAG_${varname})
|
|
|
|
if (CXX_FLAG_${varname})
|
2017-04-20 15:55:48 -07:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flag}" PARENT_SCOPE)
|
2017-03-16 08:24:33 -07:00
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
endfunction()
|
|
|
|
|
2018-12-22 17:31:59 -08:00
|
|
|
macro(ADD_ZSTD_COMPILATION_FLAGS)
|
2017-03-21 13:44:33 -07:00
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" OR MINGW) #Not only UNIX but also WIN32 for MinGW
|
2016-01-07 02:37:00 -08:00
|
|
|
#Set c++11 by default
|
2017-03-16 08:24:33 -07:00
|
|
|
EnableCompilerFlag("-std=c++11" false true)
|
2016-01-07 02:37:00 -08:00
|
|
|
#Set c99 by default
|
2017-03-16 08:24:33 -07: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
|
2016-01-07 02:37:00 -08:00
|
|
|
|
2017-03-16 08:24:33 -07:00
|
|
|
set(ACTIVATE_MULTITHREADED_COMPILATION "ON" CACHE BOOL "activate multi-threaded compilation (/MP flag)")
|
2017-05-24 01:48:10 -07:00
|
|
|
if (CMAKE_GENERATOR MATCHES "Visual Studio" AND ACTIVATE_MULTITHREADED_COMPILATION)
|
2017-03-16 08:24:33 -07:00
|
|
|
EnableCompilerFlag("/MP" true true)
|
|
|
|
endif ()
|
2016-01-10 03:20:52 -08:00
|
|
|
|
|
|
|
# UNICODE SUPPORT
|
2017-03-16 08:24:33 -07:00
|
|
|
EnableCompilerFlag("/D_UNICODE" true true)
|
|
|
|
EnableCompilerFlag("/DUNICODE" true true)
|
2016-01-07 02:37:00 -08:00
|
|
|
endif ()
|
|
|
|
|
|
|
|
# Remove duplicates compilation flags
|
2018-12-22 17:31:59 -08:00
|
|
|
foreach (flag_var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
|
2017-03-16 08:24:33 -07: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)
|
|
|
|
separate_arguments(${flag_var})
|
|
|
|
list(REMOVE_DUPLICATES ${flag_var})
|
|
|
|
string(REPLACE ";" " " ${flag_var} "${${flag_var}}")
|
2018-12-22 17:31:50 -08:00
|
|
|
endforeach ()
|
2016-01-07 02:37:00 -08:00
|
|
|
|
2017-05-24 01:48:10 -07:00
|
|
|
if (MSVC AND ZSTD_USE_STATIC_RUNTIME)
|
2018-12-22 17:31:59 -08:00
|
|
|
foreach (flag_var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
|
2017-03-16 08:24:33 -07: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)
|
2018-12-22 17:31:59 -08:00
|
|
|
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
|
2018-12-22 17:31:50 -08:00
|
|
|
endforeach ()
|
2016-01-07 02:37:00 -08:00
|
|
|
endif ()
|
|
|
|
|
2018-12-22 17:31:50 -08:00
|
|
|
endmacro()
|