CMakeCompilers.txt 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. include(CheckCXXCompilerFlag)
  2. # C++11 support
  3. CHECK_CXX_COMPILER_FLAG(-std=c++11 COMPILER_SUPPORTS_CXX11)
  4. if(COMPILER_SUPPORTS_CXX11)
  5. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  6. else()
  7. CHECK_CXX_COMPILER_FLAG(-std=c++0x COMPILER_SUPPORTS_CXX0X)
  8. if(COMPILER_SUPPORTS_CXX0X)
  9. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
  10. else()
  11. message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
  12. endif()
  13. endif()
  14. # Use openmp
  15. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
  16. set(CMAKE_EXE_LINKER_FLAGS "-fopenmp")
  17. # optimization flags support
  18. if(CMAKE_BUILD_TYPE MATCHES Debug)
  19. add_definitions(-DCHECK_STRICTMOD)
  20. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb")
  21. message(STATUS "Building DEBUG version")
  22. else()
  23. set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -O3")
  24. message(STATUS "Building RELEASE version")
  25. foreach(FLAG -march=native -mtune=native -funroll-loops)
  26. string(REGEX REPLACE -= _ FLAG_ID ${FLAG})
  27. string(TOUPPER ${FLAG_ID} FLAG_ID)
  28. CHECK_CXX_COMPILER_FLAG(${FLAG} COMPILER_SUPPORTS${FLAG_ID})
  29. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${FLAG}")
  30. endforeach()
  31. # For OSX use clang
  32. if(APPLE)
  33. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mfpmath=sse -Wa,-q")
  34. endif()
  35. endif()