[cmake-developers] [PATCH 1/6] Use find on UNIX for fast executable lookup
Rolf Eike Beer
eike at sf-mail.de
Thu Sep 4 11:15:55 EDT 2014
Am 04.09.2014 15:11, schrieb Adam Strzelecki:
> It makes whole executable process quicker on UNIX, especially for large
> bundles
> containing many files, since using find narrows results to only files
> having
> executable flags then all further tests follow.
> ---
> Modules/BundleUtilities.cmake | 19 ++++++++++++++++++-
> 1 file changed, 18 insertions(+), 1 deletion(-)
>
> diff --git a/Modules/BundleUtilities.cmake
> b/Modules/BundleUtilities.cmake
> index 0046c97..7e2b173 100644
> --- a/Modules/BundleUtilities.cmake
> +++ b/Modules/BundleUtilities.cmake
> @@ -378,7 +378,24 @@ endfunction()
> function(get_bundle_all_executables bundle exes_var)
> set(exes "")
>
> - file(GLOB_RECURSE file_list "${bundle}/*")
> + if(UNIX)
> + find_program(find_cmd "find")
> + mark_as_advanced(find_cmd)
> + endif()
> +
> + # find command is much quicker than checking every file one by one
> on Unix
> + # which can take long time for large bundles, and since anyway we
> expect
> + # executable to have execute flag set we can narrow the list much
> quicker.
> + if(find_cmd)
> + execute_process(COMMAND "${find_cmd}" "${bundle}" -type f -perm
> +0111
> + OUTPUT_VARIABLE file_list
> + OUTPUT_STRIP_TRAILING_WHITESPACE
> + )
> + string(REPLACE "\n" ";" file_list ${file_list})
> + else()
> + file(GLOB_RECURSE file_list "${bundle}/*")
> + endif()
> +
> foreach(f ${file_list})
> is_file_executable("${f}" is_executable)
> if(is_executable)
> --
I wonder if the "right" solution would instead be to add some additional
flags to GLOB/GLOB_RECURSE where one could e.g. specify that the file is
executable, or is a directory. Looking at GetPrerequisites.cmake,
FindDoxygen.cmake, and CMakeDetermineCompilerId.cmake this could be a
good idea for other places, too.
Eike
More information about the cmake-developers
mailing list