Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. # - Module for deep (recursive) search of files.
  2. #
  3. # All subroutines using path prefixes as start of search and going down of path tree.
  4. # Path-hint's arguments and CMAKE_PREFIX_PATH's used as path prefixes (in this order).
  5. # Pattern for search is "${prefix}*${name}", where "*" indicates the nesting level
  6. # of 0 to 3.
  7. #
  8. # Interface is:
  9. #
  10. # deep_find_path(<out_var> <name_to_find> [<path_hint1> ...])
  11. # - search with <name_to_find> as a name in the pattern above, return path
  12. # without <name_to_find>.
  13. #
  14. # deep_find_archive(<out_var> <corename> [<path_hint1> ...])
  15. # - search static library (archive), <corename> is a name without any "lib"-prefixes
  16. # or extentions, return full file path.
  17. #
  18. # deep_find_library(<out_var> <corename> [<path_hint1> ...])
  19. # - search shared library same as function above.
  20. #
  21.  
  22.  
  23. function(deep_find_path path_out_ name_to_find_)
  24. # deep_find_path(<out_var> <name_to_find> [<path_hint1> ...])
  25.  
  26. foreach(prefix_ ${ARGN} ${CMAKE_PREFIX_PATH})
  27. foreach(intertemplate_ "/" "/*/" "/*/*/" "/*/*/*/")
  28. file(GLOB finded_ FOLLOW_SYMLINKS
  29. "${prefix_}${intertemplate_}${name_to_find_}")
  30.  
  31. if(finded_)
  32. list(GET finded_ 0 finded_)
  33. string(REPLACE "//" "/" finded_ "${finded_}")
  34. string(REGEX REPLACE "${name_to_find_}$" "" finded_ "${finded_}")
  35. string(REGEX REPLACE "/+$" "" finded_ "${finded_}")
  36. set(${path_out_} "${finded_}" PARENT_SCOPE)
  37. return()
  38. endif()
  39. endforeach(intertemplate_)
  40. endforeach(prefix_)
  41.  
  42. set(${path_out_} "${path_out_}-NOTFOUND" PARENT_SCOPE)
  43. endfunction(deep_find_path)
  44.  
  45.  
  46. function(_deep_find_lib_internal path_out_ names_to_find_ prefixes_)
  47. foreach(prefix_ ${prefixes_})
  48. foreach(intertemplate_ "/" "/*/" "/*/*/" "/*/*/*/")
  49. set(start_ "${prefix_}${intertemplate_}")
  50.  
  51. foreach(name_ ${names_to_find_})
  52. file(GLOB finded_ FOLLOW_SYMLINKS "${start_}${name_}")
  53.  
  54. if(finded_)
  55. list(GET finded_ 0 finded_)
  56. string(REPLACE "//" "/" finded_ "${finded_}")
  57. set(${path_out_} "${finded_}" PARENT_SCOPE)
  58. return()
  59. endif()
  60. endforeach(name_)
  61. endforeach(intertemplate_)
  62. endforeach(prefix_)
  63.  
  64. set(${path_out_} "${path_out_}-NOTFOUND" PARENT_SCOPE)
  65. endfunction(_deep_find_lib_internal)
  66.  
  67.  
  68. function(deep_find_archive path_out_ corename_)
  69. # deep_find_archive(<out_var> <corename> [<path_hint1> ...])
  70.  
  71. set(names_to_find_
  72. lib${corename_}.la
  73. lib${corename_}.dll.a
  74. lib${corename_}.a
  75. ${corename_}.lib
  76. ${corename_}_static.lib
  77. )
  78. set(prefixes_ ${ARGN} ${CMAKE_PREFIX_PATH})
  79.  
  80. _deep_find_lib_internal(finded_ "${names_to_find_}" "${prefixes_}")
  81. if(finded_)
  82. set(${path_out_} "${finded_}" PARENT_SCOPE)
  83. else()
  84. set(${path_out_} "${path_out_}-NOTFOUND" PARENT_SCOPE)
  85. endif()
  86. endfunction(deep_find_archive)
  87.  
  88.  
  89. function(deep_find_library path_out_ corename_)
  90. # deep_find_library(<out_var> <corename> [<path_hint1> ...])
  91.  
  92. set(names_to_find_
  93. lib${corename_}.so
  94. ${corename_}.so
  95. lib${corename_}.dylib
  96. ${corename_}.dylib
  97. ${corename_}.dll
  98. )
  99. set(prefixes_ ${ARGN} ${CMAKE_PREFIX_PATH})
  100.  
  101. _deep_find_lib_internal(finded_ "${names_to_find_}" "${prefixes_}")
  102. if(finded_)
  103. set(${path_out_} "${finded_}" PARENT_SCOPE)
  104. else()
  105. set(${path_out_} "${path_out_}-NOTFOUND" PARENT_SCOPE)
  106. endif()
  107. endfunction(deep_find_library)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement