Options.cmake 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #
  2. # Licensed to the Apache Software Foundation (ASF) under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. #
  18. OPTION(ENABLE_COVERAGE "enable code coverage" OFF)
  19. OPTION(ENABLE_DEBUG "enable debug build" OFF)
  20. OPTION(ENABLE_SSE "enable SSE4.2 buildin function" ON)
  21. OPTION(ENABLE_FRAME_POINTER "enable frame pointer on 64bit system with flag -fno-omit-frame-pointer, on 32bit system, it is always enabled" ON)
  22. OPTION(ENABLE_LIBCPP "using libc++ instead of libstdc++, only valid for clang compiler" OFF)
  23. OPTION(ENABLE_BOOST "using boost instead of native compiler c++0x support" OFF)
  24. INCLUDE (CheckFunctionExists)
  25. CHECK_FUNCTION_EXISTS(dladdr HAVE_DLADDR)
  26. CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
  27. IF(ENABLE_DEBUG STREQUAL ON)
  28. SET(CMAKE_BUILD_TYPE Debug CACHE
  29. STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
  30. SET(CMAKE_CXX_FLAGS_DEBUG "-g -O0" CACHE STRING "compiler flags for debug" FORCE)
  31. SET(CMAKE_C_FLAGS_DEBUG "-g -O0" CACHE STRING "compiler flags for debug" FORCE)
  32. ELSE(ENABLE_DEBUG STREQUAL ON)
  33. SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE
  34. STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
  35. ENDIF(ENABLE_DEBUG STREQUAL ON)
  36. IF(ENABLE_COVERAGE STREQUAL ON)
  37. INCLUDE(CodeCoverage)
  38. ENDIF(ENABLE_COVERAGE STREQUAL ON)
  39. IF(ENABLE_FRAME_POINTER STREQUAL ON)
  40. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer")
  41. ENDIF(ENABLE_FRAME_POINTER STREQUAL ON)
  42. IF(ENABLE_SSE STREQUAL ON)
  43. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
  44. ENDIF(ENABLE_SSE STREQUAL ON)
  45. IF(NOT TEST_HDFS_PREFIX)
  46. SET(TEST_HDFS_PREFIX "./" CACHE STRING "default directory prefix used for test." FORCE)
  47. ENDIF(NOT TEST_HDFS_PREFIX)
  48. ADD_DEFINITIONS(-DTEST_HDFS_PREFIX="${TEST_HDFS_PREFIX}")
  49. ADD_DEFINITIONS(-D__STDC_FORMAT_MACROS)
  50. ADD_DEFINITIONS(-D_GNU_SOURCE)
  51. IF(OS_MACOSX AND CMAKE_COMPILER_IS_GNUCXX)
  52. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-bind_at_load")
  53. ENDIF(OS_MACOSX AND CMAKE_COMPILER_IS_GNUCXX)
  54. IF(OS_LINUX)
  55. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--export-dynamic")
  56. ENDIF(OS_LINUX)
  57. SET(BOOST_ROOT ${CMAKE_PREFIX_PATH})
  58. IF(ENABLE_BOOST STREQUAL ON)
  59. MESSAGE(STATUS "using boost instead of native compiler c++0x support.")
  60. FIND_PACKAGE(Boost 1.53 REQUIRED)
  61. SET(NEED_BOOST true CACHE INTERNAL "boost is required")
  62. ELSE(ENABLE_BOOST STREQUAL ON)
  63. SET(NEED_BOOST false CACHE INTERNAL "boost is required")
  64. ENDIF(ENABLE_BOOST STREQUAL ON)
  65. IF(CMAKE_COMPILER_IS_GNUCXX)
  66. IF(ENABLE_LIBCPP STREQUAL ON)
  67. MESSAGE(FATAL_ERROR "Unsupport using GCC compiler with libc++")
  68. ENDIF(ENABLE_LIBCPP STREQUAL ON)
  69. IF((GCC_COMPILER_VERSION_MAJOR EQUAL 4) AND (GCC_COMPILER_VERSION_MINOR EQUAL 4) AND OS_MACOSX)
  70. SET(NEED_GCCEH true CACHE INTERNAL "Explicitly link with gcc_eh")
  71. MESSAGE(STATUS "link with -lgcc_eh for TLS")
  72. ENDIF((GCC_COMPILER_VERSION_MAJOR EQUAL 4) AND (GCC_COMPILER_VERSION_MINOR EQUAL 4) AND OS_MACOSX)
  73. IF((GCC_COMPILER_VERSION_MAJOR LESS 4) OR ((GCC_COMPILER_VERSION_MAJOR EQUAL 4) AND (GCC_COMPILER_VERSION_MINOR LESS 4)))
  74. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
  75. IF(NOT ENABLE_BOOST STREQUAL ON)
  76. MESSAGE(STATUS "gcc version is older than 4.6.0, boost is required.")
  77. FIND_PACKAGE(Boost 1.53 REQUIRED)
  78. SET(NEED_BOOST true CACHE INTERNAL "boost is required")
  79. ENDIF(NOT ENABLE_BOOST STREQUAL ON)
  80. ELSEIF((GCC_COMPILER_VERSION_MAJOR EQUAL 4) AND (GCC_COMPILER_VERSION_MINOR LESS 6))
  81. IF(NOT ENABLE_BOOST STREQUAL ON)
  82. MESSAGE(STATUS "gcc version is older than 4.6.0, boost is required.")
  83. FIND_PACKAGE(Boost 1.53 REQUIRED)
  84. SET(NEED_BOOST true CACHE INTERNAL "boost is required")
  85. ENDIF(NOT ENABLE_BOOST STREQUAL ON)
  86. MESSAGE(STATUS "adding c++0x support for gcc compiler")
  87. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
  88. ELSE((GCC_COMPILER_VERSION_MAJOR LESS 4) OR ((GCC_COMPILER_VERSION_MAJOR EQUAL 4) AND (GCC_COMPILER_VERSION_MINOR LESS 4)))
  89. MESSAGE(STATUS "adding c++0x support for gcc compiler")
  90. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
  91. ENDIF((GCC_COMPILER_VERSION_MAJOR LESS 4) OR ((GCC_COMPILER_VERSION_MAJOR EQUAL 4) AND (GCC_COMPILER_VERSION_MINOR LESS 4)))
  92. IF(NEED_BOOST)
  93. IF((Boost_MAJOR_VERSION LESS 1) OR ((Boost_MAJOR_VERSION EQUAL 1) AND (Boost_MINOR_VERSION LESS 53)))
  94. MESSAGE(FATAL_ERROR "boost 1.53+ is required")
  95. ENDIF()
  96. ELSE(NEED_BOOST)
  97. IF(HAVE_NANOSLEEP)
  98. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_NANOSLEEP")
  99. ELSE(HAVE_NANOSLEEP)
  100. MESSAGE(FATAL_ERROR "nanosleep() is required")
  101. ENDIF(HAVE_NANOSLEEP)
  102. ENDIF(NEED_BOOST)
  103. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
  104. ELSEIF(CMAKE_COMPILER_IS_CLANG)
  105. MESSAGE(STATUS "adding c++0x support for clang compiler")
  106. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
  107. SET(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++0x")
  108. IF(ENABLE_LIBCPP STREQUAL ON)
  109. MESSAGE(STATUS "using libc++ instead of libstdc++")
  110. SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
  111. SET(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
  112. ENDIF(ENABLE_LIBCPP STREQUAL ON)
  113. ENDIF(CMAKE_COMPILER_IS_GNUCXX)
  114. TRY_COMPILE(STRERROR_R_RETURN_INT
  115. ${CMAKE_BINARY_DIR}
  116. ${CMAKE_SOURCE_DIR}/CMake/CMakeTestCompileStrerror.cpp
  117. OUTPUT_VARIABLE OUTPUT)
  118. MESSAGE(STATUS "Checking whether strerror_r returns an int")
  119. IF(STRERROR_R_RETURN_INT)
  120. MESSAGE(STATUS "Checking whether strerror_r returns an int -- yes")
  121. ELSE(STRERROR_R_RETURN_INT)
  122. MESSAGE(STATUS "Checking whether strerror_r returns an int -- no")
  123. ENDIF(STRERROR_R_RETURN_INT)