[CMake] macro withunexpected results

ope ope-devel at gmx.de
Fri Aug 24 13:24:39 EDT 2007


Hi,

I wrote a macro for use as:

collect_subproject_directory_names("${CMAKE_SOURCE_DIR}/extra"
EXTRA_PROJECT_DIRS)
message(STATUS "Adding ${EXTRA_PROJECT_DIRS}")
add_subdirectories(${EXTRA_PROJECT_DIRS})

where

$ ls -1 extra
boost
CMakeLists.txt
est
threadpool

and the macros self:

macro(COLLECT_SUBPROJECT_DIRECTORY_NAMES dirname varname)
  file(GLOB LIBRARY_CMAKE_FILES RELATIVE ${dirname} "*/CMakeLists.txt")
  string(REPLACE "${CMAKE_SOURCE_DIR}/" "" DIRNAME_SHORT "${dirname}")
  MESSAGE(STATUS "Scanning for sub projects in ${DIRNAME_SHORT}:")
  foreach(LIB_CMAKE_FILE ${LIBRARY_CMAKE_FILES})
    get_filename_component(LIB_DIR ${LIB_CMAKE_FILE} PATH)
    set(${varname} ${${varname}} ${LIB_DIR})
  endforeach(LIB_CMAKE_FILE ${LIBRARY_CMAKE_FILES})
endmacro(COLLECT_SUBPROJECT_DIRECTORY_NAMES)

macro(ADD_SUBDIRECTORIES dirlist)
  set(prefix " + ")
  MESSAGE(STATUS "add_subdirectories: ${ARGN}")
  foreach(subdir ${dirlist})
    MESSAGE(STATUS "${prefix}${subdir}")
    add_subdirectory(${subdir})
  endforeach(subdir ${dirlist})
endmacro(ADD_SUBDIRECTORIES)

using this gets:

...
-- Scanning for sub projects in extra:
-- Adding est;boost;threadpool
-- add_subdirectories: boost;threadpool
--  + est
...

It seems, COLLECT_SUBPROJECT_DIRECTORY_NAMES works as expected, but the
ADD_SUBDIRECTORIES is wired wrong - even if I can't find any fault. Is
is there a bug?

Thanks
Olaf



More information about the CMake mailing list