Findre2.cmake 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #.rst:
  2. # FindRE2
  3. # --------------
  4. #
  5. # Find RE2 library and headers
  6. #
  7. # The module defines the following variables:
  8. #
  9. # ::
  10. #
  11. # RE2_FOUND - true if libre2 was found
  12. # RE2_INCLUDE_DIRS - include search path
  13. # RE2_LIBRARIES - libraries to link
  14. # The module checks also these variables:
  15. # WITH_RE2_ROOT - the full path to the libre2
  16. # if so, it will have the highest priority to find
  17. # WITH_RE2_INCLUDES - where to find the header files
  18. # WITH_RE2_LIBS - where to search for the lib
  19. #=============================================================================
  20. # Copyright 2017-2026, Manticore Software LTD (https://manticoresearch.com)
  21. # Copyright 2015-2016 Sphinx Technologies, Inc.
  22. #
  23. # Distributed under the OSI-approved BSD License (the "License");
  24. # see accompanying file Copyright.txt for details.
  25. #
  26. # This software is distributed WITHOUT ANY WARRANTY; without even the
  27. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  28. # See the License for more information.
  29. #=============================================================================
  30. # (To distribute this file outside of CMake, substitute the full
  31. # License text for the above reference.)
  32. # we may have following variables from the top dir
  33. # set (RE2_INCLUDES "/usr/include;/usr/include/re2" CACHE PATH "path to re2 header files")
  34. # set (RE2_LIBRARIES "/usr/lib/x86_64-linux-gnu;/usr/lib64;/usr/local/lib64;/usr/lib/i386-linux-gnu;/usr/lib;/usr/local/lib" CACHE PATH "path to re2 libraries")
  35. function ( check_re2 HINT )
  36. if (RE2_LIBRARY AND NOT EXISTS ${RE2_LIBRARY})
  37. unset ( RE2_LIBRARY CACHE )
  38. endif ()
  39. set ( CMAKE_FIND_LIBRARY_SUFFIXES .a .lib .so .dylib .dll )
  40. FIND_LIBRARY ( RE2_LIBRARY NAMES re2 RE2 HINTS ${HINT} NO_DEFAULT_PATH )
  41. endfunction ()
  42. # First check if include path was explicitly given.
  43. # If so, it has the maximum priority over any other possibilities
  44. if (EXISTS "${WITH_RE2_ROOT}/re2/re2.h")
  45. check_re2 ( "${WITH_RE2_ROOT}/obj/" )
  46. set ( RE2_INCLUDE_DIRS ${WITH_RE2_ROOT} )
  47. else ()
  48. # Check if there are any sources in ./libre2 path
  49. if (EXISTS ${CMAKE_SOURCE_DIR}/libre2/re2/re2.h)
  50. check_re2 ( "${CMAKE_SOURCE_DIR}/libre2/obj/" )
  51. set ( RE2_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/libre2" )
  52. else ()
  53. if (EXISTS ${WITH_RE2_INCLUDES})
  54. set ( RE2_INCLUDE_DIRS "${WITH_RE2_INCLUDES}" )
  55. else ()
  56. find_path ( RE2_INCLUDE_DIRS NAMES re2/re2.h PATHS /usr/include /usr/include/re2 )
  57. endif ()
  58. set ( CMAKE_FIND_LIBRARY_SUFFIXES .a .lib .so .dylib .dll )
  59. FIND_LIBRARY ( RE2_LIBRARY NAMES re2 RE2
  60. PATHS
  61. ${WITH_RE2_LIBS}
  62. /usr/lib/x86_64-linux-gnu
  63. /usr/lib64
  64. /usr/local/lib64
  65. /usr/lib/i386-linux-gnu
  66. /usr/lib
  67. /usr/local/lib )
  68. endif ()
  69. endif ()
  70. mark_as_advanced ( RE2_INCLUDE_DIRS RE2_LIBRARY )
  71. include ( FindPackageHandleStandardArgs )
  72. find_package_handle_standard_args ( re2 REQUIRED_VARS RE2_INCLUDE_DIRS RE2_LIBRARY )
  73. if (re2_FOUND AND NOT TARGET re2::re2)
  74. add_library ( re2::re2 UNKNOWN IMPORTED )
  75. set_target_properties ( re2::re2 PROPERTIES
  76. IMPORTED_LOCATION "${RE2_LIBRARY}"
  77. INTERFACE_INCLUDE_DIRECTORIES "${RE2_INCLUDE_DIRS}"
  78. )
  79. endif ()