[Cmake] Collecting files from subdirs

Andy Cedilnik andy.cedilnik at kitware.com
Thu Mar 27 13:54:06 EST 2003


Hi Nils,

I just answered this to Denny:

All CMake variables (except cached ones) are local to subtree.

So, what you really want is this:

#CMake file for the adapter library.
PROJECT(AdapterLibrary)
#group in some logical manner, either functional or alphabetical.
SET(SRCS
)

IF(WIN32)
  INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/win32/CMakeLists.txt)
  FOREACH(src ${WIN_SRCS})
    SET(SRCS ${SRCS} "${CMAKE_CURRENT_SOURCE_DIR}/win32/${src}")
  ENDFOREACH(src)
ENDIF(WIN32)

ADD_LIBRARY(Adapter ${SRCS})



//win32 directory.
#CMake file for the win32 adapter library.

#group in some logical manner, either functional or alphabetical.
SET(WIN_SRCS
        LocalAdapter.cpp
)

                                Andy


On Thu, 2003-03-27 at 12:42, Nils H. Busch wrote:
> probably something very easy, but I can't get it to work.
> I want to add source files from several subdirs in one cmake var to use
> it in a call to
> ADD_LIBRARY(somelib ${SRCS}).
> This is to collect source files from several subdirs and make one
> library out of it.
> I have tried a few things, but my list is always empty.
> Something like in a top-level CmakeLists.txt
> SET(SRCS "")
> SUBDIRS(dir1 dir 2)
> and then in subdir CMakeLists.txt
> SET(SRCS "${SRCS} foo")
> does not work.
> 
> I'd like to retain the structure of those subdirs to organize code, but
> combine it into one library.
> Any hints?





More information about the CMake mailing list