[CMake] CMake & subdirectories

Filipe Sousa filipe at ipb.pt
Thu Nov 10 10:10:02 EST 2005


On Thursday 10 November 2005 14:56, Dan Tihelka wrote:
> Hi all,
>
> I have just started to use the CMake, and I have already ordered the
> book. However, until the book will come, I need to solve the following
> problem.
>
> I have a library (let us call it MyLibrary), which I need to build using
> CMake -- the library was created several years ago, but it was built
> under MSVC only. Now I need to build it for Linux, and possibly other
> unix platforms.
>
> The source code of the library is organized as follows:
>
> src (contains only global *.h)
>
>   + IO (contains *h as well as *.cpp)
>
>   + Math (contains *h as well as *.cpp)
>
>   +  many others, even more recursive.
>
>
> OK, I made the following files:
>
> CMakeLists.txt:
>
>     PROJECT(MyLibrary)
>     INCLUDE_DIRECTORIES( ... )
>     SUBDIRS(src)
>
> src/CMakeLists.txt::
>
>     SUBDIRS(IO Math  --and other recursive directories --- )
>
>
> src/IO/CMakeLists.txt::
>
>         SET(SRC --- all .cpp files listed here)
>         ADD_LIBRARY(MyLibrary${SRC})
>
>
> src/Math/CMakeLists.txt::
>
>         SET(SRC --- all .cpp files listed here)
>         ADD_LIBRARY(MyLibrary${SRC})
>
> and similarly for all the other directories. When a directory contains
> other subdirectories, SUBDIRS() is also listed in the CMakeLists, just
> after the ADD_LIBRARY.
>
> But, there is the problem. all seems to be OK, but  libMyLibrary.a is
> created in each subdirectory, containing only sources from that
> subdirectory. However, I need one library in src/ directory, containing
> sources from all the subdirectories. What is wrong on my definitions?
> Did I forget something?



SET(SRC
  IO/source1.cpp IO/source2.cpp ....
  Math/source1.cpp Math/source2.cpp ...
  ...
  )
ADD_LIBRARY(MyLibrary ${SRC})


> Thank you very much for your help,
> Dan
>
>
> P.S. Unfortunately, the source cannot be just copied into one directory,
> as it is under CVS control.
>
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake

--
Filipe Sousa
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/cmake/attachments/20051110/e7db2b4f/attachment.pgp


More information about the CMake mailing list