<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hej David,<br>
<br>
You're either very confusing in explaining your needs or you just
don't understand what CMake does. CMake knows that it needs to build
MY_LIB before MY_APP, because supposedly you have written code in
the lists-file that tells CMake so.<br>
<br>
I can't be sure, but I feel you really need to check out the
documentation a bit more; on the other hand, if you never created a
build-system before I think the available documentation is quite
overwhelming and maybe close to incomprehensible. It certainly took
me quite a while to figure out how to convert my manually coded
Makefiles into CMake lists-files properly. <br>
<br>
Anyways: let me spit it out a bit for you. Suppose this is the
structure of your sources:<br>
main_tree/<br>
source1.cc<br>
source2.cc<br>
my_app.cc<br>
my_lib/<br>
src1.cc<br>
src2.cc<br>
<br>
(Note that I made the my_lib directory a sub-directory; this is not
strictly necessary, but certainly preferable)<br>
Now we create a lists-file in the sub-dir. I'll not write all the
details, but provide the main parts you'll need:<br>
<br>
add_library(MY_LIB src1.cc src2.cc)<br>
<br>
Hej.... that's all there is to it. Of course you could and
(probably) should create a variable that stores the sources for
MY_LIB. Now CMake knows about the library and what sources to use
for it. Let's move to the main dir. Here we do:<br>
<br>
add_subdirectory(my_lib)<br>
add_executable(MY_APP my_app.cc)<br>
target_link_libraries(MY_APP MY_LIB)<br>
<br>
That's all there is to it. Now CMake knows that there is some
executable MY_APP that is to be compiled from my_app.cc (of course
the list of sources is not limited to one) and also that it needs
MY_LIB to link it. CMake will automatically make sure the library
gets build before linking - it must, since the executable can't be
build without the library to begin with. Your job is to write a
lists-file that describes dependencies - CMake will then figure out
how the project is to be build and creates Makefiles for it (BTW:
reading your mail I got the feeling that maybe you are under the
impression that CMake actually builds the project - if that's case,
you misunderstood. CMake will create Makefiles for you; subsequently
you'll have to call make to build the project - make help will get
you a listing of all targets CMake created for you. Or in yet other
words: the two lines of code you wrote will never, ever, build
anything. It will only create Makefiles.)<br>
<br>
Since you are new to CMake I'd also urge you to have a look at
<a class="moz-txt-link-freetext" href="http://www.cmake.org/cmake/help/cmake_tutorial.html">http://www.cmake.org/cmake/help/cmake_tutorial.html</a> <br>
<br>
Hope this helps.<br>
<br>
Greetsz, Jakob<br>
<br>
<br>
On 06/17/2011 11:06 AM, David Springate wrote:
<blockquote
cite="mid:BANLkTim+7vJ9FZgZV-=ryiPwWA9V415M+g@mail.gmail.com"
type="cite">Hi,<br>
<br>
Thanks for the reply - but I think you might have misunderstood my
question.<br>
<br>
I want to setup CMake so that when I call Cmake like so (for
MY_APP):<br>
mkdir build && cd build<br>
cmake .. -G Xcode<br>
<br>
that the cmake call will be able to 'know' that it needs MY_LIB,
find where the MY_LIB CMakeLists.txt file is, build it, and then
continue with the cmake call for MY_APP.<br>
<br>
Any ideas?<br>
<br>
David<br>
<br>
<div class="gmail_quote">On 17 June 2011 08:18, J.S. van Bethlehem
<span dir="ltr"><<a moz-do-not-send="true"
href="mailto:j.s.van.bethlehem@astro.rug.nl">j.s.van.bethlehem@astro.rug.nl</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
0.8ex; border-left: 1px solid rgb(204, 204, 204);
padding-left: 1ex;">
Hej David,<br>
<br>
>From your description I think all your build script needs
to do is:<br>
<br>
mkdir build && cd build<br>
cmake ..<br>
make MY_APP<br>
<br>
Further, assuming your library also gets build with CMake, you
probably have an add_directory(../MY_LIB ../MY_LIB) in your
main lists-file (otherwise you should) and then the
link_directories() command is not needed. I created sort of a
'standard' machinery for building a list of 'sub-packages'
using CMake. It's not well documented and probably still has
many issues, but I could mail it to you if you think it may
help you get started and if you're interested.<br>
<br>
Greetsz,<br>
Jakob<br>
<br>
On 06/16/2011 11:54 PM, David Springate wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
0.8ex; border-left: 1px solid rgb(204, 204, 204);
padding-left: 1ex;">
Hi,<br>
<br>
I am new to CMake - and whilst I am immediately impressed
with it's relative ease of use - I have a 'noob' question,
I'm sure!<br>
<br>
I have the following:<br>
A library called MY_LIB that builds with a cmake command (I
have created a nice CMakeLists.txt file)<br>
An application called MY_APP that builds a nice application
- and even links in MY_LIB using:<br>
link_directories("../MY_LIB")<br>
target_link_libraries(MY_APP MY_LIB)<br>
<br>
Now, first of all I know that I'm not supposed to use
relative paths.. but we'll call a side issue.. (though I'd
be happy to hear the correct way of doing things!) - the
real problem that I have is this:<br>
<br>
Give than MY_LIB is built using CMake and MY_APP is built
using CMake.. how can I setup my build scripts so that I can
call CMake once for MY_APP, it'll realise that it needs
MY_LIB, which hasn't yet been built, invoke CMake for MY_LIB
and then link itself with MY_APP?<br>
<br>
I ask because I use libraries heavily to organise my code
(and reuse) and would love to switch to CMake for all my
building (XCode 4 has forced my hand!) but I can't seem to
figure this out.<br>
<br>
Please help a newcomer out - any help is greatly
appreciated!<br>
<br>
Thanks,<br>
<br>
David<br>
</blockquote>
_______________________________________________<br>
</blockquote>
</div>
</blockquote>
<br>
</body>
</html>