FindEXAMPLE_PLUGIN_DEP.cmake 5.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ################################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2016 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 any DEPendencies required for the exampleplugin
  17. # Once done this will define
  18. #
  19. # EXAMPLE_PLUGIN_DEP_FOUND - system has the dependencies
  20. # EXAMPLE_PLUGIN_DEP_INCLUDE_DIR - the dependency include directory
  21. # EXAMPLE_PLUGIN_DEP_LIBRARIES - The dependency libraries needed.
  22. IF (NOT EXAMPLE_PLUGIN_DEP_FOUND)
  23. #The following two libraries are required dependencies for this plugin: libhpcc-example-plugin-deps_1 and libhpcc-example-plugin-deps_2.
  24. IF (WIN32)
  25. SET (libdep_1 "libhpcc-example-plugin-deps_1")
  26. SET (libdep_1 "libhpcc-example-plugin-deps_2")
  27. ELSE()
  28. SET (libdep_1 "hpcc-example-plugin-deps_1")
  29. SET (libdep_2 "hpcc-example-plugin-deps_2")
  30. ENDIF()
  31. #Find the path to any required include file
  32. FIND_PATH (EXAMPLE_PLUGIN_DEP_INCLUDE_DIR hpcc-example-plugin-deps PATHS /usr/include /usr/share/include /usr/local/include PATH_SUFFIXES dep)
  33. #Find the path to any required libraries, in this example there are two.
  34. FIND_LIBRARY (EXAMPLE_PLUGIN_DEP_LIBRARY_1 NAMES ${libdep_1} PATHS /usr/lib /usr/share /usr/lib64 /usr/local/lib /usr/local/lib64)
  35. FIND_LIBRARY (EXAMPLE_PLUGIN_DEP_LIBRARY_2 NAMES ${libdep_2} PATHS /usr/lib /usr/share /usr/lib64 /usr/local/lib /usr/local/lib64)
  36. SET (EXAMPLE_PLUGIN_DEP_LIBRARIES ${EXAMPLE_PLUGIN_DEP_LIBRARY_1} ${EXAMPLE_PLUGIN_DEP_LIBRARY_2})
  37. #The required include file may contain certain definitions for the major, minor, and patch versions,
  38. #in which case this can be extracted such that a minimum version check can be conducted at cmake
  39. #configuration time. In this example the following is being extracted from a C header file:
  40. #"#define EXAMPLE_PLUGIN_DEP_MAJOR 5"
  41. #"#define EXAMPLE_PLUGIN_DEP_MINOR 4"
  42. #"#define EXAMPLE_PLUGIN_DEP_PATCH 2"
  43. #The minimum version to requirement is made visible to this cmake file from
  44. #HPCC/plugins/exampleplugin/CMakeLists.txt:ADD_PLUGIN(EXAMPLEPLUGIN PACKAGES EXAMPLE_PLUGIN_DEP MINVERSION 4.6.2)
  45. IF (EXISTS "${EXAMPLE_PLUGIN_DEP_INCLUDE_DIR}/hpcc-example-plugin-deps.h")
  46. #MAJOR
  47. FILE (STRINGS "${EXAMPLE_PLUGIN_DEP_INCLUDE_DIR}/hpcc-example-plugin-deps.h" major REGEX "#define EXAMPLE_PLUGIN_DEP_MAJOR")
  48. STRING (REGEX REPLACE "#define EXAMPLE_PLUGIN_DEP_MAJOR " "" major "${major}")
  49. STRING (REGEX REPLACE "\"" "" major "${major}")
  50. #MINOR
  51. FILE (STRINGS "${EXAMPLE_PLUGIN_DEP_INCLUDE_DIR}/deps.h" minor REGEX "#define EXAMPLE_PLUGIN_DEP_MINOR")
  52. STRING (REGEX REPLACE "#define EXAMPLE_PLUGIN_DEP_MINOR " "" minor "${minor}")
  53. STRING (REGEX REPLACE "\"" "" minor "${minor}")
  54. #PATCH
  55. FILE (STRINGS "${EXAMPLE_PLUGIN_DEP_INCLUDE_DIR}/deps.h" patch REGEX "#define EXAMPLE_PLUGIN_DEP_PATCH")
  56. STRING (REGEX REPLACE "#define EXAMPLE_PLUGIN_DEP_PATCH " "" patch "${patch}")
  57. STRING (REGEX REPLACE "\"" "" patch "${patch}")
  58. SET (EXAMPLE_PLUGIN_DEP_VERSION_STRING "${major}.${minor}.${patch}")
  59. IF ("${EXAMPLE_PLUGIN_DEP_VERSION_STRING}" VERSION_LESS "${EXAMPLE_PLUGIN_DEP_FIND_VERSION}")
  60. SET(MSG "libhpcc-example-plugin-deps version '${EXAMPLE_PLUGIN_DEP_VERSION_STRING}' incompatible with min version>=${EXAMPLE_PLUGIN_DEP_FIND_VERSION}")
  61. ELSE()
  62. SET (EXAMPLE_PLUGIN_DEP_VERSION_OK 1)
  63. SET (MSG "${DEFAULT_MSG}")
  64. ENDIF()
  65. ENDIF()
  66. #The following three lines are used for building this example as part of the HPCC regression suite.
  67. #They are not intended to be present as part of this example itself and should be removed.
  68. SET (EXAMPLE_PLUGIN_DEP_LIBRARIES "jlib")
  69. SET (EXAMPLE_PLUGIN_DEP_INCLUDE_DIR "./")
  70. SET (EXAMPLE_PLUGIN_DEP_VERSION_OK 1)
  71. #If the following three variables (EXAMPLE_PLUGIN_DEP_LIBRARIES, EXAMPLE_PLUGIN_DEP_INCLUDE_DIR, &
  72. #EXAMPLE_PLUGIN_DEP_VERSION_OK) have not been set, MAKE_EXAMPLEPLUGIN will be set false when
  73. #returning to HPCC/plugins/exampleplugin/CMakeLists.txt and thus this plugin will not be built
  74. #and a message will be given explaining which of three where missing or give the above version
  75. #incompatible message.
  76. include(FindPackageHandleStandardArgs)
  77. find_package_handle_standard_args(example_plugin_dep ${MSG}
  78. EXAMPLE_PLUGIN_DEP_LIBRARIES
  79. EXAMPLE_PLUGIN_DEP_INCLUDE_DIR
  80. EXAMPLE_PLUGIN_DEP_VERSION_OK
  81. )
  82. MARK_AS_ADVANCED(EXAMPLE_PLUGIN_DEP_INCLUDE_DIR EXAMPLE_PLUGIN_DEP_LIBRARIES)
  83. ENDIF()