Add processor detection and automated optimal compiler option selection.
This commit is contained in:
parent
d6541bbbfa
commit
5f327cebd2
@ -11,17 +11,6 @@ IF(WIN32)
|
||||
SET(CMAKE_LIBRARY_PATH "${GNUWIN32}/lib")
|
||||
ENDIF(WIN32)
|
||||
|
||||
# In single config builds:
|
||||
#IF(NOT CMAKE_CONFIGURATION_TYPES)
|
||||
# IF (CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
# ADD_DEFINITIONS(-D_DEBUG)
|
||||
# # ADD_DEFINITIONS(-DDEBUG)
|
||||
# ENDIF (CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
#ELSE(NOT CMAKE_CONFIGURATION_TYPES)
|
||||
# SET(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} "-D_DEBUG")
|
||||
# SET(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} "-DNDEBUG")
|
||||
#ENDIF(NOT CMAKE_CONFIGURATION_TYPES)
|
||||
|
||||
IF(MSVC)
|
||||
# @@ Some of these might only be available in VC8.
|
||||
# Code generation flags.
|
||||
@ -39,18 +28,10 @@ IF(MSVC)
|
||||
ADD_DEFINITIONS(-D__SSE2__ -D__SSE__ -D__MMX__)
|
||||
ENDIF(MSVC)
|
||||
|
||||
# Set custom gcc options for your system:
|
||||
IF(CMAKE_COMPILER_IS_GNUCXX)
|
||||
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpmath=sse -mtune=i686 -msse3")
|
||||
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=pentium4")
|
||||
|
||||
# ibook G4:
|
||||
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=7450 -mtune=7450 -maltivec -mabi=altivec")
|
||||
|
||||
# powerpc:
|
||||
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=powerpc")
|
||||
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
|
||||
|
||||
INCLUDE(${NV_CMAKE_DIR}/OptimalOptions.cmake)
|
||||
MESSAGE(STATUS "Setting optimal options")
|
||||
MESSAGE(STATUS " Processor: ${NV_SYSTEM_PROCESSOR}")
|
||||
MESSAGE(STATUS " Compiler Flags: ${CMAKE_CXX_FLAGS}")
|
||||
|
||||
ADD_SUBDIRECTORY(src)
|
||||
|
||||
|
28
cmake/DetermineProcessor.cmake
Normal file
28
cmake/DetermineProcessor.cmake
Normal file
@ -0,0 +1,28 @@
|
||||
|
||||
# Assume i586 by default.
|
||||
SET(NV_SYSTEM_PROCESSOR "i586")
|
||||
|
||||
IF(UNIX)
|
||||
FIND_PROGRAM(CMAKE_UNAME uname /bin /usr/bin /usr/local/bin )
|
||||
IF(CMAKE_UNAME)
|
||||
EXEC_PROGRAM(uname ARGS -p OUTPUT_VARIABLE NV_SYSTEM_PROCESSOR RETURN_VALUE val)
|
||||
|
||||
IF("${val}" GREATER 0 OR NV_SYSTEM_PROCESSOR STREQUAL "unknown")
|
||||
EXEC_PROGRAM(uname ARGS -m OUTPUT_VARIABLE NV_SYSTEM_PROCESSOR RETURN_VALUE val)
|
||||
ENDIF("${val}" GREATER 0 OR NV_SYSTEM_PROCESSOR STREQUAL "unknown")
|
||||
|
||||
# processor may have double quote in the name, and that needs to be removed
|
||||
STRING(REGEX REPLACE "\"" "" NV_SYSTEM_PROCESSOR "${NV_SYSTEM_PROCESSOR}")
|
||||
STRING(REGEX REPLACE "/" "_" NV_SYSTEM_PROCESSOR "${NV_SYSTEM_PROCESSOR}")
|
||||
ENDIF(CMAKE_UNAME)
|
||||
|
||||
# Get extended processor information with:
|
||||
# `cat /proc/cpuinfo`
|
||||
|
||||
ELSE(UNIX)
|
||||
IF(WIN32)
|
||||
SET (NV_SYSTEM_PROCESSOR "$ENV{PROCESSOR_ARCHITECTURE}")
|
||||
ENDIF(WIN32)
|
||||
ENDIF(UNIX)
|
||||
|
||||
|
26
cmake/OptimalOptions.cmake
Normal file
26
cmake/OptimalOptions.cmake
Normal file
@ -0,0 +1,26 @@
|
||||
|
||||
INCLUDE(${NV_CMAKE_DIR}/DetermineProcessor.cmake)
|
||||
|
||||
# Set optimal options for gcc:
|
||||
IF(CMAKE_COMPILER_IS_GNUCXX)
|
||||
|
||||
IF(NV_SYSTEM_PROCESSOR STREQUAL "i586")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=i586")
|
||||
ENDIF(NV_SYSTEM_PROCESSOR STREQUAL "i586")
|
||||
|
||||
IF(NV_SYSTEM_PROCESSOR STREQUAL "i686")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=i686")
|
||||
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpmath=sse -mtune=i686 -msse3")
|
||||
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=pentium4")
|
||||
ENDIF(NV_SYSTEM_PROCESSOR STREQUAL "i686")
|
||||
|
||||
IF(NV_SYSTEM_PROCESSOR STREQUAL "powerpc")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=powerpc -maltivec -mabi=altivec -mpowerpc-gfxopt")
|
||||
|
||||
# ibook G4:
|
||||
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=7450 -mtune=7450 -maltivec -mabi=altivec -mpowerpc-gfxopt")
|
||||
ENDIF(NV_SYSTEM_PROCESSOR STREQUAL "powerpc")
|
||||
|
||||
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user