cmake 3.5
.
I have tried the following code in my CMake project.
Let's say SUBDIRS
contains a list of directories:
1.
foreach(subdir ${SUBDIRS})
if(IS_DIRECTORY ${subdir})
MESSAGE( STATUS "Including dir " ${subdir} )
include_directories(${subdir})
endif()
endforeach()
2.
set(include_dirs "")
foreach(subdir ${SUBDIRS})
if(IS_DIRECTORY ${subdir})
list(APPEND include_dirs ${subdir})
endif()
endforeach()
include_directories(${include_dirs})
3.
set(include_dirs "")
foreach(subdir ${SUBDIRS})
if(IS_DIRECTORY ${subdir})
set(include_dirs "${include_dirs} ${subdir}")
endif()
endforeach()
include_directories(${include_dirs})
None of the source code above works.
Looks like I must declare specifically each path:
include_directories(path/to/dir1
path/to/dir2
...)
I have noticed that
include_directories("path/to/dir1" "path/to/dir2")
works as well, in contrast to
include_directories("path/to/dir1 path/to/dir2")
which doesn't work. I think it reflects the foreach()
problem.
Any suggestions? Thanks.
----------- edit -----------
The message from 1.
: MESSAGE( STATUS "Including dir " ${subdir} )
provides the output:
including dir path/to/dir1
including dir path/to/dir2