Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # - Module for deep (recursive) search of files.
- #
- # All subroutines using path prefixes as start of search and going down of path tree.
- # Path-hint's arguments and CMAKE_PREFIX_PATH's used as path prefixes (in this order).
- # Pattern for search is "${prefix}*${name}", where "*" indicates the nesting level
- # of 0 to 3.
- #
- # Interface is:
- #
- # deep_find_path(<out_var> <name_to_find> [<path_hint1> ...])
- # - search with <name_to_find> as a name in the pattern above, return path
- # without <name_to_find>.
- #
- # deep_find_archive(<out_var> <corename> [<path_hint1> ...])
- # - search static library (archive), <corename> is a name without any "lib"-prefixes
- # or extentions, return full file path.
- #
- # deep_find_library(<out_var> <corename> [<path_hint1> ...])
- # - search shared library same as function above.
- #
- function(deep_find_path path_out_ name_to_find_)
- # deep_find_path(<out_var> <name_to_find> [<path_hint1> ...])
- foreach(prefix_ ${ARGN} ${CMAKE_PREFIX_PATH})
- foreach(intertemplate_ "/" "/*/" "/*/*/" "/*/*/*/")
- file(GLOB finded_ FOLLOW_SYMLINKS
- "${prefix_}${intertemplate_}${name_to_find_}")
- if(finded_)
- list(GET finded_ 0 finded_)
- string(REPLACE "//" "/" finded_ "${finded_}")
- string(REGEX REPLACE "${name_to_find_}$" "" finded_ "${finded_}")
- string(REGEX REPLACE "/+$" "" finded_ "${finded_}")
- set(${path_out_} "${finded_}" PARENT_SCOPE)
- return()
- endif()
- endforeach(intertemplate_)
- endforeach(prefix_)
- set(${path_out_} "${path_out_}-NOTFOUND" PARENT_SCOPE)
- endfunction(deep_find_path)
- function(_deep_find_lib_internal path_out_ names_to_find_ prefixes_)
- foreach(prefix_ ${prefixes_})
- foreach(intertemplate_ "/" "/*/" "/*/*/" "/*/*/*/")
- set(start_ "${prefix_}${intertemplate_}")
- foreach(name_ ${names_to_find_})
- file(GLOB finded_ FOLLOW_SYMLINKS "${start_}${name_}")
- if(finded_)
- list(GET finded_ 0 finded_)
- string(REPLACE "//" "/" finded_ "${finded_}")
- set(${path_out_} "${finded_}" PARENT_SCOPE)
- return()
- endif()
- endforeach(name_)
- endforeach(intertemplate_)
- endforeach(prefix_)
- set(${path_out_} "${path_out_}-NOTFOUND" PARENT_SCOPE)
- endfunction(_deep_find_lib_internal)
- function(deep_find_archive path_out_ corename_)
- # deep_find_archive(<out_var> <corename> [<path_hint1> ...])
- set(names_to_find_
- lib${corename_}.la
- lib${corename_}.dll.a
- lib${corename_}.a
- ${corename_}.lib
- ${corename_}_static.lib
- )
- set(prefixes_ ${ARGN} ${CMAKE_PREFIX_PATH})
- _deep_find_lib_internal(finded_ "${names_to_find_}" "${prefixes_}")
- if(finded_)
- set(${path_out_} "${finded_}" PARENT_SCOPE)
- else()
- set(${path_out_} "${path_out_}-NOTFOUND" PARENT_SCOPE)
- endif()
- endfunction(deep_find_archive)
- function(deep_find_library path_out_ corename_)
- # deep_find_library(<out_var> <corename> [<path_hint1> ...])
- set(names_to_find_
- lib${corename_}.so
- ${corename_}.so
- lib${corename_}.dylib
- ${corename_}.dylib
- ${corename_}.dll
- )
- set(prefixes_ ${ARGN} ${CMAKE_PREFIX_PATH})
- _deep_find_lib_internal(finded_ "${names_to_find_}" "${prefixes_}")
- if(finded_)
- set(${path_out_} "${finded_}" PARENT_SCOPE)
- else()
- set(${path_out_} "${path_out_}-NOTFOUND" PARENT_SCOPE)
- endif()
- endfunction(deep_find_library)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement