Finished cmake optimization options as well as cpu specific building.

This commit is contained in:
FernandoS27 2016-12-11 03:53:10 -05:00
parent 47f3711dbf
commit d3f8878cec

View File

@ -40,9 +40,46 @@ option(CITRA_USE_BUNDLED_SDL2 "Download bundled SDL2 binaries" OFF)
option(ENABLE_QT "Enable the Qt frontend" ON) option(ENABLE_QT "Enable the Qt frontend" ON)
option(CITRA_USE_BUNDLED_QT "Download bundled Qt binaries" OFF) option(CITRA_USE_BUNDLED_QT "Download bundled Qt binaries" OFF)
# uses O3 instead of O2 # uses full optimization on compilers
option(ENABLE_HIGH_OP "Enable highest optimizations possible" OFF) option(ENABLE_HIGH_OP "Enable highest optimizations possible" OFF)
set(CPU_TARGET "base" CACHE STRING "CPU minimum for this build, use base as default")
set(CPU_TYPES "base;pentium4;haswell;skylake;modern")
set_property(CACHE CPU_TARGET PROPERTY STRINGS ${CPU_TYPES})
set(CC_OP_LEVEL "")
set(CC_EXTRA "")
set(CC_CPU_FLAGS "")
if (MSVC)
set(CC_OP_LEVEL "/O2")
if (ENABLE_HIGH_OP)
# /GL - produces global unified optimizations instead of module-based
set(CC_OP_LEVEL "/Ox /GL /Gw")
endif()
if (CPU_TARGET MATCHES "base")
set(CC_CPU_FLAGS "/arch:SSE2")
else()
set(CC_CPU_FLAGS "/arch:SSE2 /arch:AVX2")
endif()
elseif (MINGW)
set(CC_EXTRA "${CC_EXTRA} -pthread")
set(CC_OP_LEVEL "-O2")
if (ENABLE_HIGH_OP)
set(CC_OP_LEVEL "-O3")
endif()
if (CPU_TARGET MATCHES "skylake")
set(CC_CPU_FLAGS "-march=skylake -maccumulate-outgoing-args")
elseif (CPU_TARGET MATCHES "modern")
set(CC_CPU_FLAGS "-mmmx -mmovbe -msse3 -msse4 -mavx -mavx2 -mbmi -mbmi2 -mf16c -maccumulate-outgoing-args")
elseif (CPU_TARGET MATCHES "pentium4")
set(CC_CPU_FLAGS "-march=pentium4")
elseif (CPU_TARGET MATCHES "haswell")
set(CC_CPU_FLAGS "-march=haswell -maccumulate-outgoing-args")
else ()
set(CC_CPU_FLAGS "-mmmx -msse -msse2")
endif()
endif()
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks/pre-commit) if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/hooks/pre-commit)
message(STATUS "Copying pre-commit hook") message(STATUS "Copying pre-commit hook")
file(COPY hooks/pre-commit file(COPY hooks/pre-commit
@ -68,9 +105,11 @@ message(STATUS "Target architecture: ${ARCHITECTURE}")
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(COMP_FLAGS "${CC_OP_LEVEL} ${CC_CPU_FLAGS} ${CC_EXTRA}")
if (NOT MSVC) if (NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-attributes") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMP_FLAGS} -Wno-attributes")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMP_FLAGS}")
if (MINGW) if (MINGW)
add_definitions(-DMINGW_HAS_SECURE_API) add_definitions(-DMINGW_HAS_SECURE_API)
@ -110,14 +149,9 @@ else()
set(CMAKE_C_FLAGS_DEBUG "/Od /MDd" CACHE STRING "" FORCE) set(CMAKE_C_FLAGS_DEBUG "/Od /MDd" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" CACHE STRING "" FORCE) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" CACHE STRING "" FORCE)
set(OP_LEVEL "/O2")
if (ENABLE_HIGH_OP)
set(OP_LEVEL "/O3")
# /O2 - Optimization level 2
# /GS- - No stack buffer overflow checks # /GS- - No stack buffer overflow checks
# /MD - Multi-threaded runtime DLL # /MD - Multi-threaded runtime DLL
set(CMAKE_C_FLAGS_RELEASE "${OP_LEVEL} /GS- /MD" CACHE STRING "" FORCE) set(CMAKE_C_FLAGS_RELEASE "${COMP_FLAGS} /GS- /MD" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}" CACHE STRING "" FORCE) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}" CACHE STRING "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG" CACHE STRING "" FORCE) set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG" CACHE STRING "" FORCE)
@ -157,7 +191,6 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/externals/cmake-modules")
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR}) include_directories(${OPENGL_INCLUDE_DIR})
# Prefer the -pthread flag on Linux. # Prefer the -pthread flag on Linux.
set (THREADS_PREFER_PTHREAD_FLAG ON) set (THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
@ -212,6 +245,8 @@ if (UNIX OR MINGW)
endif() endif()
endif() endif()
message(STATUS "Compiler Flags: ${CMAKE_CXX_FLAGS}")
if (ENABLE_QT) if (ENABLE_QT)
if (CITRA_USE_BUNDLED_QT) if (CITRA_USE_BUNDLED_QT)
if (MSVC14 AND ARCHITECTURE_x86_64) if (MSVC14 AND ARCHITECTURE_x86_64)