[CMake] How to add a libaray for another libaray?

Kermit Mei kermit.mei at gmail.com
Wed Dec 10 15:46:52 EST 2008


James Bigler wrote:
> There are a couple of things that either you have done wrong or I 
> don't understand.  This is how I would implement things:
>
> core/CMakeLists.txt
>
> SET(SRC_LIST ConfigHolder.cpp DictItem.cpp Reciter.cpp ForgetCurve.cpp 
> Task.cpp Dict.cpp Manager.cpp WordList.cpp)
> ADD_LIBRARY(core ${SRC_LIST})
>
> ui/CMakeLists.txt
>
> # You can also use CMAKE_SOURCE_DIR if FREERECITE_SOURCE_DIR is the 
> top of your CMake tree
> ADD_DIRECTORIES(${CMAKE_SOURCE_DIR}/core)
>
> ADD_LIBRARY(ui Cui.cpp)
> # Tell CMake that ui needs to link agains core
> TARGET_LINK_LIBRARIES(ui core)
>
> CMakeLists.txt
> ADD_EXECUTABLE(myprogram main.cpp)
> # myprogram depends on ui library
> TARGET_LINK_LIBRARIES(myprogram ui)
>
> You don't need to use LINK_DIRECTORIES, because CMake knows where core 
> was built and how to link it against ui.
>
> James
>
Thanks for your help. I see;p



More information about the CMake mailing list