EFLHelpers.cmake 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # - Set of macros and functions that are useful for building the EFL port.
  2. #
  3. # The following functions are currently defined:
  4. # FIND_EFL_LIBRARY(<name> HEADERS <header1> ... HEADER_PREFIXES <prefix1> ... LIBRARY <libname>)
  5. # Looks for the header files inside the given prefix directories, and for the library
  6. # passed to the LIBRARY parameter.
  7. # Two #defines in the form <UPPERCASED_NAME>_VERSION_MAJOR and <UPPERCASED_NAME>_VERSION_MINOR
  8. # are looked for in all the given headers, and the first occurrence is used to build the library's
  9. # version number.
  10. # This function defines the following variables:
  11. # - <UPPERCASED_NAME>_INCLUDE_DIRS: All the directories required by this library's headers.
  12. # - <UPPERCASED_NAME>_LIBRARIES: All the libraries required to link against this library.
  13. # - <UPPERCASED_NAME>_VERSION: The library's version in the format "major.minor".
  14. #
  15. # Copyright (C) 2012 Intel Corporation. All rights reserved.
  16. #
  17. # Redistribution and use in source and binary forms, with or without
  18. # modification, are permitted provided that the following conditions
  19. # are met:
  20. # 1. Redistributions of source code must retain the above copyright
  21. # notice, this list of conditions and the following disclaimer.
  22. # 2. Redistributions in binary form must reproduce the above copyright
  23. # notice, this list of conditions and the following disclaimer in the
  24. # documentation and/or other materials provided with the distribution.
  25. #
  26. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``AS
  27. # IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28. # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29. # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS
  30. # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  31. # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  32. # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  33. # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  34. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  35. # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  36. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  37. include(CMakeParseArguments)
  38. function(FIND_EFL_LIBRARY _name)
  39. CMAKE_PARSE_ARGUMENTS(PARAM "" "LIBRARY" "HEADERS;HEADER_PREFIXES" ${ARGN})
  40. string(TOUPPER ${_name} _name_upper)
  41. set(_version_found FALSE)
  42. foreach (_current_header ${PARAM_HEADERS})
  43. find_path(${_current_header}_INCLUDE_DIR NAMES ${_current_header} PATH_SUFFIXES ${PARAM_HEADER_PREFIXES})
  44. list(APPEND ${_name}_INCLUDE_DIRS "${${_current_header}_INCLUDE_DIR}")
  45. if (NOT _version_found)
  46. set(_header_path "${${_current_header}_INCLUDE_DIR}/${_current_header}")
  47. if (EXISTS ${_header_path})
  48. file(READ "${_header_path}" _header_contents)
  49. string(REGEX MATCH "#define +${_name_upper}_VERSION_MAJOR +([0-9]+)" _dummy "${_header_contents}")
  50. set(_version_major "${CMAKE_MATCH_1}")
  51. string(REGEX MATCH "#define +${_name_upper}_VERSION_MINOR +([0-9]+)" _dummy "${_header_contents}")
  52. set(_version_minor "${CMAKE_MATCH_1}")
  53. if (_version_major AND _version_minor)
  54. set(_version_found TRUE)
  55. endif ()
  56. endif ()
  57. endif ()
  58. endforeach ()
  59. find_library(${_name}_LIBRARIES NAMES ${PARAM_LIBRARY})
  60. set(${_name}_INCLUDE_DIRS ${${_name}_INCLUDE_DIRS} PARENT_SCOPE)
  61. set(${_name}_LIBRARIES ${${_name}_LIBRARIES} PARENT_SCOPE)
  62. set(${_name}_VERSION "${_version_major}.${_version_minor}" PARENT_SCOPE)
  63. endfunction()