[CMake] Help: How to generate one library from multiple
directories
Mike Jackson
imikejackson at gmail.com
Fri Jan 11 12:09:57 EST 2008
On Jan 11, 2008, at 11:54 AM, Yang, Y. wrote:
> Hi, all.
>
> I just start to use cmake and a newbie. Now I want to generate one
> library from multiple directories.
> However, when I use add_library(libname, source_file) in each folder;
> I found that the latter generated lib file would overwrite the
> previous
> lib file.
>
> How can I link those objects from multiple folder into one lib file.
>
> Thanks forward.
>
> best regards.
>
> Yang
>
One way would be to have in your top level CMakeLists.txt file the
list of all sources that go into the library. If your project is
small enough you do not need to have a CMakeLists.txt file in each
directory.
#-------- CMakeLists.txt ---------------
SET (Lib_sources
${CMAKE_CURRENT_SOURCE_DIR}/dir1/source.cpp
${CMAKE_CURRENT_SOURCE_DIR}/dir2/foo.cpp
)
ADD_LIBRARY(myLibrary ${Lib_sources})
#---------------------------------------
--
Mike Jackson Senior Research Engineer
Innovative Management & Technology Services
More information about the CMake
mailing list