FindLIBMEMCACHED.cmake 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. ################################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2014 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. # - Try to find the libmemcached library # Once done this will define #
  17. # LIBMEMCACHED_FOUND - system has the libmemcached library
  18. # LIBMEMCACHED_INCLUDE_DIR - the libmemcached include directory(s)
  19. # LIBMEMCACHED_LIBRARIES - The libraries needed to use libmemcached
  20. # If the memcached libraries are found on the system, we assume they exist natively and dependencies
  21. # can be handled through package management. If the libraries are not found, and if
  22. # MEMCACHED_USE_EXTERNAL_LIBRARY is ON, we will fetch, build, and include a copy of the neccessary
  23. # Libraries.
  24. option(MEMCACHED_USE_EXTERNAL_LIBRARY "Pull and build source from external location if local is not found" ON)
  25. # Search for native library to build against
  26. if(WIN32)
  27. set(libmemcached_lib "libmemcached")
  28. set(libmemcachedUtil_lib "libmemcachedutil")
  29. else()
  30. set(libmemcached_lib "memcached")
  31. set(libmemcachedUtil_lib "memcachedutil")
  32. endif()
  33. find_path(LIBMEMCACHED_INCLUDE_DIR libmemcached/memcached.hpp PATHS /usr/include /usr/share/include /usr/local/include PATH_SUFFIXES libmemcached)
  34. find_library(LIBMEMCACHEDCORE_LIBRARY NAMES ${libmemcached_lib} PATHS /usr/lib usr/lib/libmemcached /usr/share /usr/lib64 /usr/local/lib /usr/local/lib64)
  35. find_library(LIBMEMCACHEDUTIL_LIBRARY NAMES ${libmemcachedUtil_lib} PATHS /usr/lib /usr/share /usr/lib64 /usr/local/lib /usr/local/lib64)
  36. set(LIBMEMCACHED_LIBRARIES ${LIBMEMCACHEDCORE_LIBRARY} ${LIBMEMCACHEDUTIL_LIBRARY})
  37. if(LIBMEMCACHED_INCLUDE_DIR)
  38. if(EXISTS "${LIBMEMCACHED_INCLUDE_DIR}/libmemcached-1.0/configure.h")
  39. file(STRINGS "${LIBMEMCACHED_INCLUDE_DIR}/libmemcached-1.0/configure.h" version REGEX "#define LIBMEMCACHED_VERSION_STRING")
  40. string(REGEX REPLACE "#define LIBMEMCACHED_VERSION_STRING " "" version "${version}")
  41. string(REGEX REPLACE "\"" "" version "${version}")
  42. set(LIBMEMCACHED_VERSION_STRING ${version})
  43. if("${LIBMEMCACHED_VERSION_STRING}" VERSION_EQUAL "${LIBMEMCACHED_FIND_VERSION}" OR "${LIBMEMCACHED_VERSION_STRING}" VERSION_GREATER "${LIBMEMCACHED_FIND_VERSION}")
  44. set(LIBMEMCACHED_VERSION_OK 1)
  45. set(MSG "${DEFAULT_MSG}")
  46. else()
  47. set(LIBMEMCACHED_VERSION_OK 0)
  48. set(MSG "libmemcached version '${LIBMEMCACHED_VERSION_STRING}' incompatible with min version>=${LIBMEMCACHED_FIND_VERSION}")
  49. endif()
  50. endif()
  51. endif()
  52. if((LIBMEMCACHEDCORE_LIBRARY STREQUAL "LIBMEMCACHEDCORE_LIBRARY-NOTFOUND"
  53. OR LIBMEMCACHEDUTIL_LIBRARY STREQUAL "LIBMEMCACHEDUTIL_LIBRARY-NOTFOUND"
  54. OR LIBMEMCACHED_INCLUDE_DIR STREQUAL "LIBMEMCACHED_INCLUDE_DIR-NOTFOUND"
  55. OR NOT LIBMEMCACHED_VERSION_OK)
  56. AND MEMCACHED_USE_EXTERNAL_LIBRARY)
  57. # Currently libmemcached versions are not sufficient on ubuntu 12.04 and 14.04 LTS
  58. # until then, we build the required libraries from source
  59. if(NOT TARGET generate-libmemcached)
  60. set(LIBMEMCACHED_URL https://launchpad.net/libmemcached/1.0/${LIBMEMCACHED_FIND_VERSION}/+download/libmemcached-${LIBMEMCACHED_FIND_VERSION}.tar.gz)
  61. include(ExternalProject)
  62. ExternalProject_Add(
  63. generate-libmemcached
  64. URL ${LIBMEMCACHED_URL}
  65. DOWNLOAD_NO_PROGRESS 1
  66. TIMEOUT 15
  67. DOWNLOAD_DIR ${CMAKE_BINARY_DIR}/downloads
  68. SOURCE_DIR ${CMAKE_BINARY_DIR}/downloads/libmemcached
  69. CONFIGURE_COMMAND "${CMAKE_BINARY_DIR}/downloads/libmemcached/configure" --prefix=${INSTALL_DIR} LDFLAGS=-L${LIB_PATH}
  70. BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} LDFLAGS=-Wl,-rpath-link,${LIB_PATH}
  71. BINARY_DIR ${CMAKE_BINARY_DIR}/build-libmemcached
  72. INSTALL_COMMAND "")
  73. add_library(libmemcached SHARED IMPORTED GLOBAL)
  74. add_library(libmemcachedutil SHARED IMPORTED GLOBAL)
  75. set_property(TARGET libmemcached
  76. PROPERTY IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/build-libmemcached/libmemcached/.libs/libmemcached.so.11.0.0)
  77. set_property(TARGET libmemcachedutil
  78. PROPERTY IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/build-libmemcached/libmemcached/.libs/libmemcachedutil.so.2.0.0)
  79. set_property(TARGET libmemcached
  80. PROPERTY IMPORTED_LINK_DEPENDENT_LIBRARIES libmemcachedutil)
  81. add_dependencies(libmemcached generate-libmemcached)
  82. add_dependencies(libmemcachedutil generate-libmemcached)
  83. if(PLATFORM)
  84. install(CODE "set(ENV{LD_LIBRARY_PATH} \"\$ENV{LD_LIBRARY_PATH}:${CMAKE_BINARY_DIR}:${CMAKE_BINARY_DIR}/build-libmemcached/libmemcached/.libs\")")
  85. install(PROGRAMS
  86. ${CMAKE_BINARY_DIR}/build-libmemcached/libmemcached/.libs/libmemcached.so
  87. ${CMAKE_BINARY_DIR}/build-libmemcached/libmemcached/.libs/libmemcached.so.11
  88. ${CMAKE_BINARY_DIR}/build-libmemcached/libmemcached/.libs/libmemcached.so.11.0.0
  89. ${CMAKE_BINARY_DIR}/build-libmemcached/libmemcached/.libs/libmemcachedutil.so
  90. ${CMAKE_BINARY_DIR}/build-libmemcached/libmemcached/.libs/libmemcachedutil.so.2
  91. ${CMAKE_BINARY_DIR}/build-libmemcached/libmemcached/.libs/libmemcachedutil.so.2.0.0
  92. DESTINATION lib)
  93. endif()
  94. endif()
  95. set(LIBMEMCACHEDCORE_LIBRARY $<TARGET_FILE:libmemcached>)
  96. set(LIBMEMCACHEDUTIL_LIBRARY $<TARGET_FILE:libmemcachedutil>)
  97. set(LIBMEMCACHED_LIBRARIES $<TARGET_FILE:libmemcached> $<TARGET_FILE:libmemcachedutil>)
  98. set(LIBMEMCACHED_INCLUDE_DIR ${CMAKE_BINARY_DIR}/downloads/libmemcached)
  99. # always assumed to be ok
  100. set(LIBMEMCACHED_VERSION_OK 1)
  101. else()
  102. set(MEMCACHED_USE_EXTERNAL_LIBRARY OFF)
  103. endif()
  104. include(FindPackageHandleStandardArgs)
  105. find_package_handle_standard_args(
  106. LIBMEMCACHED DEFAULT_MSG
  107. LIBMEMCACHEDCORE_LIBRARY
  108. LIBMEMCACHEDUTIL_LIBRARY
  109. LIBMEMCACHED_INCLUDE_DIR
  110. LIBMEMCACHED_VERSION_OK)
  111. mark_as_advanced(LIBMEMCACHED_INCLUDE_DIR LIBMEMCACHED_LIBRARIES LIBMEMCACHEDCORE_LIBRARY LIBMEMCACHEDUTIL_LIBRARY)