[cmake-developers] ExternalProject and git clone

David Cole dlrdave at aol.com
Tue Sep 10 13:54:39 EDT 2013


> (I still want to ensure that the folder is empty before removing it, 
but
> I don't know how to check if a directory is empty, suggestions?)

Forgot about this in my other reply.... You can check if a directory is 
empty by doing a quick file(GLOB on it and counting the number of 
results.

This code, saved as a *.cmake script, and then run with -P in various 
directories:

    set(dir ".")

    file(GLOB r1 "${dir}/*")
    list(LENGTH r1 n1)
    message("n1='${n1}'")

    file(GLOB r2 "${dir}/*.*")
    list(LENGTH r2 n2)
    message("n2='${n2}'")

convinces me that n1 and n2 should both be 0 in an empty directory, and 
non-0 in a directory that contains any subdirs or files, even invisible 
ones like .git.


HTH,
David




More information about the cmake-developers mailing list