CMakeLists.txt 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #
  2. # Copyright 2017 The Abseil Authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. cmake_minimum_required(VERSION 2.8.12)
  17. project(absl)
  18. list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake)
  19. include(GNUInstallDirs)
  20. include(AbseilHelpers)
  21. # config options
  22. if (MSVC)
  23. # /wd4005 macro-redefinition
  24. # /wd4068 unknown pragma
  25. # /wd4244 conversion from 'type1' to 'type2'
  26. # /wd4267 conversion from 'size_t' to 'type2'
  27. # /wd4800 force value to bool 'true' or 'false' (performance warning)
  28. add_compile_options(/W3 /WX /wd4005 /wd4068 /wd4244 /wd4267 /wd4800)
  29. add_definitions(/DNOMINMAX /DWIN32_LEAN_AND_MEAN=1 /D_CRT_SECURE_NO_WARNINGS /D_SCL_SECURE_NO_WARNINGS)
  30. else()
  31. set(ABSL_STD_CXX_FLAG "-std=c++11" CACHE STRING "c++ std flag (default: c++11)")
  32. endif()
  33. ##
  34. ## Using absl targets
  35. ##
  36. ## all public absl targets are
  37. ## exported with the absl:: prefix
  38. ##
  39. ## e.g absl::base absl::synchronization absl::strings ....
  40. ##
  41. ## DO NOT rely on the internal targets outside of the prefix
  42. # include current path
  43. list(APPEND ABSL_COMMON_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR})
  44. # -std=X
  45. set(CMAKE_CXX_FLAGS "${ABSL_STD_CXX_FLAG} ${CMAKE_CXX_FLAGS}")
  46. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_WARNING_VLA} ${CMAKE_CXX_FLAGS} ")
  47. # -fexceptions
  48. set(ABSL_EXCEPTIONS_FLAG "${CMAKE_CXX_EXCEPTIONS}")
  49. # find dependencies
  50. ## pthread
  51. find_package(Threads REQUIRED)
  52. option(ABSL_USE_GOOGLETEST_HEAD
  53. "If ON, abseil will download HEAD from googletest at config time." OFF)
  54. option(ABSL_RUN_TESTS "If ON, Abseil tests will be run." OFF)
  55. if(${ABSL_RUN_TESTS})
  56. # enable CTest. This will set BUILD_TESTING to ON unless otherwise specified
  57. # on the command line
  58. include(CTest)
  59. enable_testing()
  60. endif()
  61. ## check targets
  62. if(BUILD_TESTING)
  63. if(${ABSL_USE_GOOGLETEST_HEAD})
  64. include(CMake/DownloadGTest.cmake)
  65. endif()
  66. check_target(gtest)
  67. check_target(gtest_main)
  68. check_target(gmock)
  69. list(APPEND ABSL_TEST_COMMON_LIBRARIES
  70. gtest_main
  71. gtest
  72. gmock
  73. ${CMAKE_THREAD_LIBS_INIT}
  74. )
  75. endif()
  76. add_subdirectory(absl)