CMakeLists.txt 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. ################################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2015 HPCC Systems®.
  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. # Component: kafka
  17. #####################################################
  18. # Description:
  19. # ------------
  20. # Cmake Input File for kafka
  21. #####################################################
  22. project(kafka)
  23. if(KAFKA)
  24. ADD_PLUGIN(kafka)
  25. if(MAKE_KAFKA)
  26. # librdkafka packages do not include everything we need to properly
  27. # build against it; until/if they are ever fixed we will need to build
  28. # our own version of librdkafka from source and include it ourselves
  29. if(NOT EXISTS "${PROJECT_SOURCE_DIR}/librdkafka/configure")
  30. message(FATAL_ERROR
  31. " The librdkafka submodule is not available.
  32. This normally indicates that the git submodule has not been fetched.
  33. Please run git submodule update --init --recursive")
  34. endif()
  35. if(APPLE)
  36. set(LIBRDKAFKA_LIB ${PROJECT_BINARY_DIR}/lib/librdkafka.dylib)
  37. set(LIBRDKAFKA_LIB_REAL ${PROJECT_BINARY_DIR}/lib/librdkafka.1.dylib)
  38. set(LIBRDKAFKACPP_LIB ${PROJECT_BINARY_DIR}/lib/librdkafka++.dylib)
  39. set(LIBRDKAFKACPP_LIB_REAL ${PROJECT_BINARY_DIR}/lib/librdkafka++.1.dylib)
  40. else()
  41. set(LIBRDKAFKA_LIB ${PROJECT_BINARY_DIR}/lib/librdkafka.so)
  42. set(LIBRDKAFKA_LIB_REAL ${PROJECT_BINARY_DIR}/lib/librdkafka.so.1)
  43. set(LIBRDKAFKACPP_LIB ${PROJECT_BINARY_DIR}/lib/librdkafka++.so)
  44. set(LIBRDKAFKACPP_LIB_REAL ${PROJECT_BINARY_DIR}/lib/librdkafka++.so.1)
  45. endif()
  46. # librdkafka does not support out-of-source builds, so let's copy all
  47. # of its source code to our binary directory and build there; further,
  48. # we need to pull some working directory shenanigans for each command
  49. # in order to make the built scripts function correctly
  50. add_custom_command(
  51. OUTPUT ${LIBRDKAFKA_LIB}
  52. COMMAND cp -r ${PROJECT_SOURCE_DIR}/librdkafka ${PROJECT_BINARY_DIR}/src
  53. COMMAND cd ${PROJECT_BINARY_DIR}/src && ./configure --prefix=${PROJECT_BINARY_DIR}
  54. COMMAND cd ${PROJECT_BINARY_DIR}/src && make && make install
  55. COMMENT Copying and building librdkafka)
  56. add_custom_target(librdkafka-build ALL DEPENDS ${LIBRDKAFKA_LIB})
  57. install(CODE "set(ENV{LD_LIBRARY_PATH} \"\$ENV{LD_LIBRARY_PATH}:${PROJECT_BINARY_DIR}/lib\")")
  58. add_library(librdkafka SHARED IMPORTED)
  59. set_property(TARGET librdkafka PROPERTY IMPORTED_LOCATION ${LIBRDKAFKA_LIB})
  60. add_dependencies(librdkafka librdkafka-build)
  61. add_library(librdkafkacpp SHARED IMPORTED)
  62. set_property(TARGET librdkafkacpp PROPERTY IMPORTED_LOCATION ${LIBRDKAFKACPP_LIB})
  63. add_dependencies(librdkafkacpp librdkafka-build)
  64. set(
  65. SRCS
  66. kafka.hpp
  67. kafka.cpp)
  68. include_directories(
  69. ./../../system/include
  70. ./../../rtl/eclrtl
  71. ./../../rtl/include
  72. ./../../common/deftype
  73. ./../../system/jlib
  74. ${PROJECT_BINARY_DIR}/include
  75. ${CMAKE_BINARY_DIR}
  76. ${CMAKE_BINARY_DIR}/oss)
  77. add_definitions(-D_USRDLL -DECL_KAFKA_EXPORTS)
  78. HPCC_ADD_LIBRARY(kafka SHARED ${SRCS})
  79. if(${CMAKE_VERSION} VERSION_LESS "2.8.9")
  80. message(WARNING "Cannot set NO_SONAME. shlibdeps will give warnings when package is installed")
  81. elseif(NOT APPLE)
  82. set_target_properties(kafka PROPERTIES NO_SONAME 1)
  83. endif()
  84. install(
  85. TARGETS kafka
  86. DESTINATION plugins)
  87. install(
  88. FILES ${LIBRDKAFKA_LIB_REAL} ${LIBRDKAFKACPP_LIB_REAL}
  89. DESTINATION ${LIB_DIR}
  90. PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
  91. COMPONENT Runtime)
  92. install(
  93. FILES ${LIBRDKAFKA_LIB} ${LIBRDKAFKACPP_LIB}
  94. DESTINATION ${LIB_DIR}
  95. COMPONENT Runtime)
  96. target_link_libraries(
  97. kafka
  98. librdkafka
  99. librdkafkacpp
  100. eclrtl
  101. jlib
  102. ${ZLIB_LIBRARIES})
  103. endif()
  104. endif()
  105. if(PLATFORM OR CLIENTTOOLS_ONLY)
  106. install(
  107. FILES ${CMAKE_CURRENT_SOURCE_DIR}/kafka.ecllib
  108. DESTINATION plugins
  109. COMPONENT Runtime)
  110. endif()