From 2a654cfe3dd84b2bbddc9985b96aa91cf009f85d Mon Sep 17 00:00:00 2001 From: Menche Date: Sat, 21 Mar 2015 17:14:59 -0700 Subject: [PATCH] more flag-related tweaks --- CMakeLists.txt | 2 ++ src/CMakeLists.txt | 23 +++++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 765d1a7..1fd6e30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,8 @@ else() set(BUILD_SERVER 1 CACHE BOOL "Build server") endif() +set(CPU_OPTS 0 CACHE BOOL "Enable CPU optimizations") + set(WARN_ALL 1 CACHE BOOL "Enable -Wall for Release build") if(NOT CMAKE_BUILD_TYPE) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7d4e771..95a79d1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -372,10 +372,20 @@ else() set(SAFETY_FLAGS "-fno-strict-aliasing -fwrapv -fvisibility=hidden -fstack-protector --param=ssp-buffer-size=4 -D_FORTIFY_SOURCE=2") endif() - set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG ${SAFETY_FLAGS} -O2 -Wall -fomit-frame-pointer -pipe") - set(CMAKE_CXX_FLAGS_DEBUG "${SAFETY_FLAGS} -O0 -g2 -ggdb") - set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG ${SAFETY_FLAGS} -O2 -Wall -fomit-frame-pointer -pipe") - set(CMAKE_C_FLAGS_DEBUG "${SAFETY_FLAGS} -O0 -g2 -ggdb") + if(CPU_OPTS) + set(OPT_FLAGS "-march=native -mtune=native -O2 -fomit-frame-pointer") + else() + set(OPT_FLAGS "-O2 -fomit-frame-pointer") + endif() + + set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG ${SAFETY_FLAGS} ${OPT_FLAGS} -pipe") + set(CMAKE_CXX_FLAGS_DEBUG "${SAFETY_FLAGS} -Wall -O0 -g2 -ggdb") + set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG ${SAFETY_FLAGS} ${OPT_FLAGS} -pipe") + set(CMAKE_C_FLAGS_DEBUG "${SAFETY_FLAGS} -Wall -O0 -g2 -ggdb") + + set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-Wl,-O1,--as-needed,--discard-all,--no-undefined,--sort-common,-z,relro,-z,now") + set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "-Wl,-O1,--as-needed,--discard-all,--no-undefined,--sort-common,-z,relro,-z,now") + set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "-Wl,-O1,--as-needed,--discard-all,--no-undefined,--sort-common,-z,relro,-z,now") if(USE_GPROF) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg") @@ -388,8 +398,9 @@ else() endif() -MESSAGE(STATUS "CMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}") -MESSAGE(STATUS "CMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}") +MESSAGE(STATUS "Release Flags: ${CMAKE_CXX_FLAGS_RELEASE}") +MESSAGE(STATUS "Debug Flags: ${CMAKE_CXX_FLAGS_DEBUG}") +MESSAGE(STATUS "Linker Flags: ${CMAKE_EXE_LINKER_FLAGS_RELEASE}") # # Installation