Reputation: 119
I have a c++ project which directory structure like below:
server/
code/
BASE/
Thread/
Log/
Memory/
Net/
cmake/
CMakeList.txt
BASE/
CMakeList.txt
Net/
CMakeList.txt
here is part of /cmake/CMakeList.txt:
MACRO(SUBDIRLIST result curdir)
FILE(GLOB children RELATIVE ${curdir} ${curdir}/*)
SET(dirlist "")
FOREACH(child ${children})
IF(IS_DIRECTORY ${curdir}/${child})
SET(dirlist ${dirlist} ${child})
ENDIF()
ENDFOREACH()
SET(${result} ${dirlist})
ENDMACRO()
add_subdirectory(Base)
then use macro in /cmake/Base/CMakeList.txt:
SET(SUBDIR, "")
SUBDIRLIST(SUBDIRS, ${BASE_SRC_DIR})
message("SUBDIRS : " ${SUBDIRS})
output: SUBDIRS :
I check ${dirlist} by output it's value in macro, I get directory list expected,but when message("result " ${result}) after SET(${result} ${dirlist}),I can not get output expected , what's wrong with my CMakeLists.txt?
Upvotes: 4
Views: 2948
Reputation: 78300
There are a couple of minor issues here:
SET(dirlist "")
could be just SET(dirlist)
. Likewise, SET(SUBDIR, "")
could be just SET(SUBDIRS)
(I guess "SUBDIR" is a typo and should be "SUBDIRS". Also you don't want the comma in the set
command - probably another typo?)${result}
in the macro, use message("result: ${${result}}")
, since you're not appending ${child}
to result
each time, but to ${result}
. In your example ${result}
is SUBDIRS
, so ${${result}}
is ${SUBDIRS}
.SUBDIRLIST
, don't use a comma between the arguments.SUBDIRS
, include ${SUBDIRS}
in the quotes, i.e. message("SUBDIRS: ${SUBDIRS}")
or you'll lose the semi-colon separators.Other than those, your macro seems fine.
Upvotes: 2