[CMake] Check directory exists

David Cole david.cole at kitware.com
Thu Jan 31 13:25:58 EST 2008


>From the good old days before IS_DIRECTORY was invented, you can also use a
trailing "/" trick (hack?) with EXISTS to see if a directory exists and is a
directory...

IF(EXISTS "${maybedir}/")
with a trailing "/" will return false if ${maybedir} is a file that exists,
but true if ${maybedir} is a directory that exists...

I use this to parse only directories out of FILE(GLOB file_list "*")
results.

HTH,
David

On 1/31/08, James Bigler <bigler at cs.utah.edu> wrote:
>
> Oh, that's a different question.  You want this command, then (in the man
> page).
>
>                  IF(IS_DIRECTORY directory-name)
>
>                True if the given name is a directory.  Behavior  is  well-
>                defined only for full paths.
>
> So you probably want something like this:
>
> IF(EXISTS "${dir}" AND IS_DIRECTORY "${dir}")
>
> James
>
> pepone.onrez wrote:
> > Yes i read this
> > but i want to test if is a directory no a directory or a file
> >>
> >>
> >> On Jan 31, 2008 7:04 PM, James Bigler <bigler at cs.utah.edu> wrote:
> >>
> >>>  From the man page:
> >>>
> >>>                 IF(EXISTS file-name)
> >>>                 IF(EXISTS directory-name)
> >>>
> >>>               True  if  the  named file or directory exists.  Behavior
> >>> is
> >>>               well-defined only for full paths.
> >>>
> >>>
> >>> pepone.onrez wrote:
> >>>> There is any way for check if a directory exists using CMake ?
> >>>>
> >>>> Thanks
> >>>>
> >>>>
> >>>>
> >>>>
> >>>
> ------------------------------------------------------------------------
> >>>> _______________________________________________
> >>>> CMake mailing list
> >>>> CMake at cmake.org
> >>>> http://www.cmake.org/mailman/listinfo/cmake
> >>> _______________________________________________
> >>> CMake mailing list
> >>> CMake at cmake.org
> >>> http://www.cmake.org/mailman/listinfo/cmake
> >>>
> >>
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > CMake mailing list
> > CMake at cmake.org
> > http://www.cmake.org/mailman/listinfo/cmake
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/cmake/attachments/20080131/91b86efa/attachment.htm


More information about the CMake mailing list