CMakeLists.txt 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. cmake_minimum_required (VERSION 2.8)
  2. project (benchmark)
  3. option(BENCHMARK_ENABLE_SHARED "Enable building a shared library." OFF)
  4. option(BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." ON)
  5. # Make sure we can import out CMake functions
  6. list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
  7. # Read the git tags to determine the project version
  8. include(GetGitVersion)
  9. get_git_version(GIT_VERSION)
  10. # Tell the user what versions we are using
  11. string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" VERSION ${GIT_VERSION})
  12. message("-- Version: ${VERSION}")
  13. # The version of the libraries
  14. set(GENERIC_LIB_VERSION ${VERSION})
  15. string(SUBSTRING ${VERSION} 0 1 GENERIC_LIB_SOVERSION)
  16. # Try and enable C++11. Don't use C++14 because it doesn't work in some
  17. # configurations.
  18. include(CheckCXXCompilerFlag)
  19. include(AddCXXCompilerFlag)
  20. include(CXXFeatureCheck)
  21. check_cxx_compiler_flag(-std=c++11 HAVE_FLAG_CXX_11)
  22. check_cxx_compiler_flag(-std=c++0x HAVE_FLAG_CXX_0X)
  23. if (HAVE_FLAG_CXX_11)
  24. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  25. elseif (HAVE_FLAG_CXX_0X)
  26. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
  27. endif()
  28. # Turn compiler warnings up to 11
  29. add_cxx_compiler_flag(-Wall)
  30. add_cxx_compiler_flag(-Wextra)
  31. add_cxx_compiler_flag(-Wshadow)
  32. add_cxx_compiler_flag(-Werror)
  33. add_cxx_compiler_flag(-pedantic-errors)
  34. add_cxx_compiler_flag(-Wshorten-64-to-32)
  35. add_cxx_compiler_flag(-Wfloat-equal)
  36. add_cxx_compiler_flag(-Wzero-as-null-pointer-constant)
  37. # Release flags
  38. add_cxx_compiler_flag(-fno-strict-aliasing RELEASE)
  39. add_cxx_compiler_flag(-Wthread-safety)
  40. if (HAVE_WTHREAD_SAFETY)
  41. add_definitions(-DHAVE_WTHREAD_SAFETY)
  42. cxx_feature_check(THREAD_SAFETY_ATTRIBUTES)
  43. endif()
  44. # C++ feature checks
  45. cxx_feature_check(STD_REGEX)
  46. cxx_feature_check(GNU_POSIX_REGEX)
  47. cxx_feature_check(POSIX_REGEX)
  48. cxx_feature_check(STEADY_CLOCK)
  49. # Set up directories
  50. include_directories(${PROJECT_SOURCE_DIR}/include)
  51. # Build the targets
  52. add_subdirectory(src)
  53. if (BENCHMARK_ENABLE_TESTING)
  54. enable_testing()
  55. add_subdirectory(test)
  56. endif()