add build options for more stuff

This commit is contained in:
Menche 2016-01-16 00:00:47 -08:00
parent 473b8dde96
commit c19ec67cdd
2 changed files with 35 additions and 12 deletions

View File

@ -34,6 +34,9 @@ endif()
set(REBUILD_ICNS 0 CACHE BOOL "Rebuild icns from voxelands.svg .")
set(CPU_OPTS 0 CACHE BOOL "Enable CPU optimizations")
set(ENABLE_SSP 1 CACHE BOOL "Enable stack smashing protection")
set(ENABLE_SAFESTACK 1 CACHE BOOL "Enable SafeStack if supported (LLVM only)")
set(ENABLE_PIE 0 CACHE BOOL "Produce a Position Independent Executable")
if(NOT CMAKE_BUILD_TYPE)
# Default to release

View File

@ -373,27 +373,47 @@ else()
set(ARCH x86_64)
endif()
set(SAFETY_FLAGS "-fno-strict-aliasing -fwrapv -fvisibility=hidden")
set(SAFETY_LDFLAGS "")
set(OPT_FLAGS "-O2 -fomit-frame-pointer")
set(OPT_LDFLAGS "-Wl,-O1,--as-needed,--discard-all,--no-undefined,-s,--sort-common,-z,relro,-z,now")
if(ENABLE_SSP)
CHECK_CXX_COMPILER_FLAG("-fstack-protector-strong" HAS_FSTACK_STRONG)
if(HAS_FSTACK_STRONG)
set(SAFETY_FLAGS "-fno-strict-aliasing -fwrapv -fvisibility=hidden -fstack-protector-strong --param=ssp-buffer-size=4")
set(SAFETY_FLAGS "${SAFETY_FLAGS} -fstack-protector-strong")
else()
set(SAFETY_FLAGS "-fno-strict-aliasing -fwrapv -fvisibility=hidden -fstack-protector --param=ssp-buffer-size=4")
set(SAFETY_FLAGS "${SAFETY_FLAGS} -fstack-protector")
endif()
endif()
if(ENABLE_SAFESTACK)
CHECK_CXX_COMPILER_FLAG("-fsanitize=safe-stack" HAS_SAFESTACK)
if(HAS_SAFESTACK)
set(SAFETY_FLAGS "${SAFETY_FLAGS} -fsanitize=safe-stack")
set(SAFETY_LDFLAGS "-fsanitize=safe-stack -lrt")
endif()
endif()
if(ENABLE_PIE)
set(SAFETY_FLAGS "${SAFETY_FLAGS} -fPIC -fPIE")
set(SAFETY_LDFLAGS "${LINKER_FLAGS} -Wl,-pie")
endif()
if(CPU_OPTS)
set(OPT_FLAGS "${OPT_FLAGS} -march=native -mtune=native")
endif()
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 "${OPT_FLAGS} ${SAFETY_FLAGS} -Wall -DNDEBUG -pipe")
set(CMAKE_CXX_FLAGS_DEBUG "${SAFETY_FLAGS} -Wall -O0 -g2 -ggdb")
set(CMAKE_C_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
set(CMAKE_CXX_FLAGS_DEBUG "${SAFETY_FLAGS} -Wall -O0 -g2 -ggdb")
set(CMAKE_C_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-Wl,-O1,--as-needed,--discard-all,--no-undefined,-s,--sort-common,-z,relro,-z,now")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${OPT_LDFLAGS} ${SAFETY_LDFLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS_RELEASE ${CMAKE_EXE_LINKER_FLAGS_RELEASE})
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE ${CMAKE_EXE_LINKER_FLAGS_RELEASE})
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${SAFETY_LDFLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS_DEBUG ${CMAKE_EXE_LINKER_FLAGS_DEBUG})
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG ${CMAKE_EXE_LINKER_FLAGS_DEBUG})
if(USE_GPROF)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg")