build: add DISABLE_CXXFLAGS_OPTIMIZATIONS option

handy when packaging should control optimization without build system
masking. Especially handy when building to common architecture.

no change of behavior if DISABLE_CXXFLAGS_OPTIMIZATIONS is unset.

Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
pull/326/head
Alon Bar-Lev 2016-10-21 23:49:04 +03:00
parent b49343398b
commit db50b93766
2 changed files with 40 additions and 33 deletions

View File

@ -39,6 +39,7 @@ option(BUILD_DOCUMENTATION "Use Doxygen to create the HTML based API documentati
option(DISABLE_ASM "Disable ASM" OFF)
option(DISABLE_SSSE3 "Disable SSSE3" OFF)
option(DISABLE_AESNI "Disable AES-NI" OFF)
option(DISABLE_CXXFLAGS_OPTIMIZATIONS "Disable CXXFLAGS optimizations" OFF)
set(CRYPTOPP_DATA_DIR "" CACHE PATH "Crypto++ test data directory")
#============================================================================
@ -125,7 +126,7 @@ if ((NOT CRYPTOPP_CROSS_COMPILE) AND (NOT (WINDOWS OR WINDOWS_STORE OR WINDOWS_P
endif()
# -march=native for GCC, Clang and ICC in any version that does support it.
if ((NOT CRYPTOPP_CROSS_COMPILE) AND (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU|Intel"))
if ((NOT DISABLE_CXXFLAGS_OPTIMIZATIONS) AND (NOT CRYPTOPP_CROSS_COMPILE) AND (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU|Intel"))
CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_OPT_ARCH_NATIVE_SUPPORTED)
if (COMPILER_OPT_ARCH_NATIVE_SUPPORTED AND NOT CMAKE_CXX_FLAGS MATCHES "-march=")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
@ -134,6 +135,7 @@ endif()
# Solaris specific
if ((NOT CRYPTOPP_CROSS_COMPILE) AND "${UNAME_SYSTEM}" STREQUAL "SunOS")
if (NOT DISABLE_CXXFLAGS_OPTIMIZATIONS)
# SunCC needs -native
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "SunPro")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -native")
@ -154,6 +156,7 @@ if ((NOT CRYPTOPP_CROSS_COMPILE) AND "${UNAME_SYSTEM}" STREQUAL "SunOS")
else()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
endif()
endif()
# GCC needs to enable use of '/'
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")

View File

@ -49,6 +49,8 @@ IS_X86 := $(shell isainfo -k 2>/dev/null | grep -i -c "i386")
IS_X64 := $(shell isainfo -k 2>/dev/null | grep -i -c "amd64")
endif
DISABLE_CXXFLAGS_OPTIMIZATIONS := 0
###########################################################
##### General Variables #####
###########################################################
@ -125,6 +127,7 @@ ifeq ($(IS_X86)$(IS_X32)$(IS_CYGWIN)$(IS_MINGW)$(SUN_COMPILER),00000)
endif
endif
ifeq ($(DISABLE_CXXFLAGS_OPTIMIZATIONS),0)
# Guard use of -march=native
ifeq ($(GCC42_OR_LATER)$(IS_NETBSD),10)
CXXFLAGS += -march=native
@ -141,6 +144,7 @@ else
CXXFLAGS += -m32
endif # X86/X32/X64
endif
endif
# Aligned access required for -O3 and above due to vectorization
UNALIGNED_ACCESS := $(shell $(EGREP) -c "^[[:space:]]*//[[:space:]]*\#[[:space:]]*define[[:space:]]*CRYPTOPP_NO_UNALIGNED_DATA_ACCESS" config.h)