Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake detect empty directory during build time

Tags:

cmake

I have a custom command that is executed if a directory exists. I need to know if the directory is not empty before executing another command.

Question: How to read, detect or get the number of files of a directory?

like image 734
Joel Avatar asked Dec 26 '22 01:12

Joel


1 Answers

You can run regular CMake code as script using cmake -P as part of build process. The script itself would contain somethng like

file(GLOB RESULT DIR)
list(LENGTH RESULT RES_LEN)
if(RES_LEN EQUAL 0)
# DIR is empty, do something
endif()
like image 132
arrowd Avatar answered Dec 28 '22 19:12

arrowd