2 # vcpkg_clean_executables_in_bin
4 Remove specified executables found in `${CURRENT_PACKAGES_DIR}/bin` and `${CURRENT_PACKAGES_DIR}/debug/bin`. If, after all specified executables have been removed, and the `bin` and `debug/bin` directories are empty, then also delete `bin` and `debug/bin` directories.
8 vcpkg_clean_executables_in_bin(
15 A list of executable filenames without extension.
18 Generally, there is no need to call this function manually. Instead, pass an extra `AUTO_CLEAN` argument when calling `vcpkg_copy_tools`.
21 * [czmq](https://github.com/microsoft/vcpkg/blob/master/ports/czmq/portfile.cmake)
24 function(vcpkg_clean_executables_in_bin)
25 # parse parameters such that semicolons in options arguments to COMMAND don't get erased
26 cmake_parse_arguments(PARSE_ARGV 0 _vct "" "" "FILE_NAMES")
28 if(NOT DEFINED _vct_FILE_NAMES)
29 message(FATAL_ERROR "FILE_NAMES must be specified.")
32 foreach(file_name IN LISTS _vct_FILE_NAMES)
34 "${CURRENT_PACKAGES_DIR}/bin/${file_name}${VCPKG_TARGET_EXECUTABLE_SUFFIX}"
35 "${CURRENT_PACKAGES_DIR}/debug/bin/${file_name}${VCPKG_TARGET_EXECUTABLE_SUFFIX}"
36 "${CURRENT_PACKAGES_DIR}/bin/${file_name}.pdb"
37 "${CURRENT_PACKAGES_DIR}/debug/bin/${file_name}.pdb"
41 function(try_remove_empty_directory directory)
42 if(NOT EXISTS "${directory}")
46 if(NOT IS_DIRECTORY "${directory}")
47 message(FATAL_ERROR "${directory} is supposed to be an existing directory.")
51 # For an empty directory,
52 # file(GLOB items "${directory}" "${directory}/*")
53 # will return a list with one item.
54 file(GLOB items "${directory}/" "${directory}/*")
55 list(LENGTH items items_count)
57 if(${items_count} EQUAL 0)
58 file(REMOVE_RECURSE "${directory}")
62 try_remove_empty_directory("${CURRENT_PACKAGES_DIR}/bin")
63 try_remove_empty_directory("${CURRENT_PACKAGES_DIR}/debug/bin")