CMakeLists.txt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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,
  13. # software distributed under the License is distributed on an
  14. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. # KIND, either express or implied. See the License for the
  16. # specific language governing permissions and limitations
  17. # under the License.
  18. #
  19. cmake_minimum_required(VERSION 2.8.12)
  20. project("Apache Thrift")
  21. set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/build/cmake")
  22. # TODO: add `git rev-parse --short HEAD`
  23. # Read the version information from the Autoconf file
  24. file (STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/configure.ac" CONFIGURE_AC REGEX "AC_INIT\\(.*\\)" )
  25. # The following variable is used in the version.h.in file
  26. string(REGEX REPLACE "AC_INIT\\(\\[.*\\], \\[([0-9]+\\.[0-9]+\\.[0-9]+(-dev)?)\\]\\)" "\\1" PACKAGE_VERSION ${CONFIGURE_AC})
  27. message(STATUS "Parsed Thrift package version: ${PACKAGE_VERSION}")
  28. # These are internal to CMake
  29. string(REGEX REPLACE "([0-9]+\\.[0-9]+\\.[0-9]+)(-dev)?" "\\1" thrift_VERSION ${PACKAGE_VERSION})
  30. string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" thrift_VERSION_MAJOR ${thrift_VERSION})
  31. string(REGEX REPLACE "[0-9]+\\.([0-9])+\\.[0-9]+" "\\1" thrift_VERSION_MINOR ${thrift_VERSION})
  32. string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" thrift_VERSION_PATCH ${thrift_VERSION})
  33. message(STATUS "Parsed Thrift version: ${thrift_VERSION} (${thrift_VERSION_MAJOR}.${thrift_VERSION_MINOR}.${thrift_VERSION_PATCH})")
  34. # Some default settings
  35. include(DefineCMakeDefaults)
  36. # Build time options are defined here
  37. include(DefineOptions)
  38. include(DefineInstallationPaths)
  39. # Based on the options set some platform specifics
  40. include(DefinePlatformSpecifc)
  41. # Generate the config.h file
  42. include(ConfigureChecks)
  43. # Package it
  44. include(CPackConfig)
  45. find_package(Threads)
  46. include(CTest)
  47. if(BUILD_TESTING)
  48. message(STATUS "Building with unittests")
  49. enable_testing()
  50. # Define "make check" as alias for "make test"
  51. add_custom_target(check COMMAND ctest)
  52. else ()
  53. message(STATUS "Building without tests")
  54. endif ()
  55. if(BUILD_COMPILER)
  56. if(NOT EXISTS ${THRIFT_COMPILER})
  57. set(THRIFT_COMPILER $<TARGET_FILE:thrift-compiler>)
  58. endif()
  59. add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/compiler/cpp)
  60. elseif(EXISTS ${THRIFT_COMPILER})
  61. add_executable(thrift-compiler IMPORTED)
  62. set_property(TARGET thrift-compiler PROPERTY IMPORTED_LOCATION ${THRIFT_COMPILER})
  63. endif()
  64. if(BUILD_CPP)
  65. add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/cpp)
  66. if(BUILD_TUTORIALS)
  67. add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tutorial/cpp)
  68. endif()
  69. if(BUILD_TESTING)
  70. if(WITH_LIBEVENT AND WITH_ZLIB AND WITH_OPENSSL)
  71. add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/cpp)
  72. else()
  73. message(WARNING "libevent and/or ZLIB and/or OpenSSL not found or disabled; will not build some tests")
  74. endif()
  75. endif()
  76. endif()
  77. if(BUILD_C_GLIB)
  78. add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/c_glib)
  79. endif()
  80. if(BUILD_JAVA)
  81. add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/java)
  82. endif()
  83. if(BUILD_PYTHON)
  84. add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/py)
  85. if(BUILD_TESTING)
  86. add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/py)
  87. endif()
  88. endif()
  89. if(BUILD_HASKELL)
  90. add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/hs)
  91. if(BUILD_TESTING)
  92. add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/hs)
  93. endif()
  94. endif()
  95. PRINT_CONFIG_SUMMARY()