Adam Lee
Adam Lee

Reputation: 25738

Does CMake support include directories recursively?

Obviously XCode support include directories and all its sub directories. I am wondering if CMake support this mode?

I am currently using include_directores

Upvotes: 0

Views: 4242

Answers (1)

coincoin
coincoin

Reputation: 4685

If you want to add recursively files

You have to use the GLOB_RECURSE mode from FILE for that.

If you want to recursively add subdirectories

You can use this convenient macro for instance (taken from VTK Cmake examples)

MACRO(HEADER_DIRECTORIES return_list)
    FILE(GLOB_RECURSE new_list *.h)
    SET(dir_list "")
    FOREACH(file_path ${new_list})
        GET_FILENAME_COMPONENT(dir_path ${file_path} PATH)
        SET(dir_list ${dir_list} ${dir_path})
    ENDFOREACH()
    LIST(REMOVE_DUPLICATES dir_list)
    SET(${return_list} ${dir_list})
ENDMACRO()

A remark from the CMake doc (which I personnaly do not follow) :

We do not recommend using GLOB to collect a list of source files from your source tree

Upvotes: 2

Related Questions