3 #################################
4 ## Setup default CXXFLAGS
5 if(NOT PASSED_FIRST_CONFIGURE)
6 message(STATUS "Overriding CMake's default CFLAGS (this should appear only once)")
8 # default build type is Release when compiling make files
9 if(NOT CMAKE_BUILD_TYPE AND NOT HONOR_GENTOO_FLAGS)
10 if(${CMAKE_GENERATOR} STREQUAL "Xcode")
12 else(${CMAKE_GENERATOR} STREQUAL "Xcode")
13 set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type: options are None, Release, Debug, RelWithDebInfo" FORCE)
14 endif(${CMAKE_GENERATOR} STREQUAL "Xcode")
15 endif(NOT CMAKE_BUILD_TYPE AND NOT HONOR_GENTOO_FLAGS)
17 if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
18 # special handling to honor gentoo flags
19 if (HONOR_GENTOO_FLAGS)
20 set(CMAKE_CXX_FLAGS_DEBUG "-Wall" CACHE STRING "Flags used by the compiler during debug builds." FORCE)
21 set(CMAKE_CXX_FLAGS_MINSIZEREL "-Wall -DNDEBUG" CACHE STRING "Flags used by the compiler during minimum size release builds." FORCE)
22 set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -Wall" CACHE STRING "Flags used by the compiler during release builds." FORCE)
23 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-DNDEBUG -Wall" CACHE STRING "Flags used by the compiler during release builds with debug info." FORCE)
25 else (HONOR_GENTOO_FLAGS)
27 # default flags for g++
28 set(CMAKE_CXX_FLAGS_DEBUG "-march=native -g -Wall -Wno-unknown-pragmas" CACHE STRING "Flags used by the compiler during debug builds." FORCE)
29 set(CMAKE_CXX_FLAGS_MINSIZEREL "-march=native -Os -Wall -Wno-unknown-pragmas -DNDEBUG" CACHE STRING "Flags used by the compiler during minimum size release builds." FORCE)
30 set(CMAKE_CXX_FLAGS_RELEASE "-march=native -O3 -funroll-loops -DNDEBUG -Wall -Wno-unknown-pragmas" CACHE STRING "Flags used by the compiler during release builds." FORCE)
31 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-march=native -g -O3 -funroll-loops -DNDEBUG -Wall -Wno-unknown-pragmas" CACHE STRING "Flags used by the compiler during release builds with debug info." FORCE)
33 endif (HONOR_GENTOO_FLAGS)
35 # default flags for visual studio 2005
39 set(SSE_OPT "/arch:SSE2")
42 set(CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /W3 /Zm1000 /EHs /GR /MP" CACHE STRING "Flags used by all build types." FORCE)
43 set(CMAKE_CXX_FLAGS_RELEASE "${SSE_OPT} /Oi /Ot /Oy /fp:fast /MD /Ox /Ob2 /D NDEBUG" CACHE STRING "Flags used by the compiler during release builds." FORCE)
44 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${SSE_OPT} /Oi /Ot /Oy /fp:fast /MD /Zi /Ox /Ob1 /D NDEBUG" CACHE STRING "Flags used by the compiler during release builds with debug info." FORCE)
45 set(CMAKE_CXX_FLAGS_MINSIZEREL "${SSE_OPT} /Oi /Ot /Oy /fp:fast /MD /O1 /Ob1 /D NDEBUG" CACHE STRING "Flags used by the compiler during minimum size release builds." FORCE)
47 elseif(CMAKE_CXX_COMPILER MATCHES "icpc")
48 # default flags for intel
49 set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g" CACHE STRING "Flags used by the compiler during debug builds." FORCE)
50 set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG" CACHE STRING "Flags used by the compiler during minimum size release builds." FORCE)
51 set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "Flags used by the compiler during release builds." FORCE)
52 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O3 -DNDEBUG" CACHE STRING "Flags used by the compiler during release builds with debug info." FORCE)
54 else(CMAKE_COMPILER_IS_GNUCXX)
55 message(STATUS "No default CXXFLAGS for your compiler, set them manually")
56 endif(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
58 SET(PASSED_FIRST_CONFIGURE ON CACHE INTERNAL "First configure has run: CXX_FLAGS have had their defaults changed" FORCE)
59 endif(NOT PASSED_FIRST_CONFIGURE)
61 # disable crazy windows warnings
63 add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE)