[CMake] Dependencies and libraries..How does it work?

Glenn Coombs glenn.coombs at gmail.com
Fri Jun 17 07:06:54 EDT 2011


If the library you are trying to build is one that is totally under your
control then really it should be a subdirectory of your MY_APP source tree
so that you can call add_subdirectory() on it.  If MY_LIB is shared across
multiple projects then you can always arrange for it to appear as a
subdirectory of MY_APP when you check the code out from your revision
control system.  We do this with cvs modules but I'm sure that git and
mercurial have similar capabilities.

If you still can't get MY_LIB to be a subdirectory of MY_APP then you might
be able to build it using add_directory with the second argument:

add_subdirectory(${LIB_SRC} mylib)

I haven't used add_subdirectory like that myself but it appears from the
docs that it might do what you want.

--
Glenn

On 17 June 2011 11:03, David Springate <david.springate at gmail.com> wrote:

> Thanks for that helpful summary Jacob - and indeed you are correct I was
> getting very confused (overtime is getting to me!) and forgetting of course
> cmake doesn't actually *build* the product - but I do want it to generate
> the makefiles that the project is dependant on, as you outlined.
>
> Now, my setup is basically as you outlined in your example - except that
> the library is not located in a subdirectory of the main_tree.
> I have an environment variable (let's call it LIB_SRC) that contains the
> path to the root of my library source.
>
> How can I inform the app's CMakeLists.txt file that the lib source is
> located at LIB_SRC so that the 'target_link_libraries(MY_APP MY_LIB)' call
> doesn't fail?
> I'm guessing that add_subdirectory isn't ideal in this case..
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110617/16409291/attachment.htm>


More information about the CMake mailing list