Re: [CMake] Building in stages.

2010-06-22 Thread Michael Hertling
On 06/21/2010 05:41 PM, Magnus Therning wrote:
> On Mon, Jun 21, 2010 at 16:10, Michael Wild  wrote:
>>
>>> I'm looking for some suggestions on how to tackle a problem with staged
>>> builds.
>>>
>>> In trying to convert a project which uses omake to build OCaml files I've
>>> stumbled on the issue that building one sub-part (bar) of the project needs
>>> the result of another sub-part (foo).  The twist is that foo is required
>>> already at the dependency-discovery stage of bar[1].  Is there some clever 
>>> way
>>> of working around this?
>>>
>>> One obvious solution would be to simply skip automatic generation of
>>> dependencies for bar, but that feels a little naughty.  It feels about as
>>> naughty as how the previous build system just worked by ordering[2].
>>>
>>> Hopefully there's some better way of achieving this, any suggestions?
>>>
>>> /M
>>>
>>> [1] For those initiated in OCaml and its tools stack the former sub-part
>>> builds a custom filter for camlp4 which is then used in the latter sub-part.
>>> [2] omake is very similar to make and in this case the build of foo just
>>> happened before bar, and there was no attempt at automatic generation of
>>> dependencies at all.
>>
>> Well, if you need foo to be built before bar, just use add_dependencies(bar 
>> foo). File-level dependency scanning happens just before bar is built, so if 
>> I understand your question correctly, you should be fine now...
> 
> No, I need foo to be built before bar is inspected to gather its
> dependencies.  And dependencies for both foo and bar are gathered when
> calling `cmake` to generate the Makefiles. [...]

Look at the following CMakeLists.txt files:

CMakeLists.txt:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(PRESTAGE C)
# Prebuild foo:
FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/prestage)
EXECUTE_PROCESS(
COMMAND ${CMAKE_COMMAND} ${CMAKE_SOURCE_DIR}/foo
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/prestage
)
EXECUTE_PROCESS(
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}/prestage
)
# Use it to generate bar.c:
EXECUTE_PROCESS(
COMMAND ${CMAKE_BINARY_DIR}/prestage/foo
OUTPUT_FILE ${CMAKE_BINARY_DIR}/bar.c
)
# Business as usual:
ADD_SUBDIRECTORY(foo)
ADD_SUBDIRECTORY(bar)

foo/CMakeLists.txt:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/foo.c "
\#include 
int main(void)
{
printf(\"void bar(void){}\\n\"); return 0;
}
")
ADD_EXECUTABLE(foo ${CMAKE_CURRENT_BINARY_DIR}/foo.c)

bar/CMakeLists.txt:

ADD_LIBRARY(bar SHARED ${CMAKE_BINARY_DIR}/bar.c)

The top-level CMakeLists.txt uses EXECUTE_PROCESS() and "cmake --build"
to build "foo" in directory "prestage"; thereafter, it is used in the
remaining configuration process. As proof, "foo" generates the source
file for "bar" before the latter's subdirectory is entered by CMake.
Perhaps, you can adapt this approach to your purposes, i.e. to have
"foo" take part in gathering dependencies for "bar", but regarding
"cmake --build", in particular, I don't know if it works on systems
other than *nix, too.

Regards,

Michael
___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] Building in stages.

2010-06-22 Thread Magnus Therning
On Tue, Jun 22, 2010 at 07:48, Michael Wild  wrote:
[...]
> Ahh, now I understand. You need foo already at cmake-time, not at make-time. 
> Ideally you'd want to run ocamldep at make-time to determine the file-level 
> dependencies, like cmake does for C/C++/Fortran/Java. However, I don't think 
> there's a way to do so currently. IMHO this would be a good feature-request 
> in the bug tracker.

Yes, indeed :-)  And how disappointing that CMake doesn't support it already :-(

I created http://public.kitware.com/Bug/view.php?id=10862
Please add clarifying words as needed :-)

/M

-- 
Magnus Therning(OpenPGP: 0xAB4DFBA4)
magnus@therning.org  Jabber: magnus@therning.org
http://therning.org/magnus identi.ca|twitter: magthe
___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] Building in stages.

2010-06-22 Thread Michael Wild

On 22. Jun, 2010, at 7:27 , Magnus Therning wrote:

> On Mon, Jun 21, 2010 at 17:46, Aeschbacher, Fabrice
>  wrote:
>> I would try following in foo/CmakeLists.txt:
>> 
>>   add_custom_command(TARGET foo
>>  POST_BUILD
>>  COMMAND touch bar/CMakeLists.txt
>>   )
>> 
>> This will force CMake to re-build the makefiles for 'bar' (because its
>> CMakeLists.txt has been modified)
>> 
>> And of course, add_dependencies(bar foo)
> 
> It might, but it still feels like a rather strange way to go about it.
> 
> I'll make yet another attempt to explain the situation, hopefully better so
> that it becomes more clear what the problem is.
> 
> There are three tools involved:
> 
>  camlp4 - an extensible pre-processor, it makes it possible to modify OCaml
>   and even add syntax
>  ocamldep - a tool that inspects a source file and tells you what it depends
> on, it can be told to use a preprocessor through its -pp argument
>  ocamlc - the OCaml compiler, it can be told to use a preprocessor through
>   its -pp argument
> 
> Somewhat simplified the project I'm converting to use CMake has two parts:
> 
>  foo - an extension to camlp4
>  bar - an OCaml module, wich uses the syntax extensions implemented in foo
> 
> So if I understand you, these would roughly be the steps I need to take:
> 
> 1. Call 'cmake' (manual)
>This must skip dependency generation for bar; foo isn't built yet and
>hence ocamldep will not be able to parse the source for bar.
> 2. Call 'make' (manual)
>Builds foo, and as a last thing touch the CMakeLists.txt for bar.
> 
> Now you're saying that because of the post-build step in 2 the following will
> happen automatically, right?
> 
> 3. Call to 'cmake' (automatic)
>Now foo has been built so the correct dependencies for bar can be
>determined.  (I have yet to find out exactly *how* I can determine that
>foo already is built, but that sounds like it shouldn't be too difficult.)
> 
> 4. Call to 'make' (automatic)
>Now the Makefile for bar contains the correct dependency information and
>the build can continue.
> 
> Have I understood you correctly?
> 
> /M

Ahh, now I understand. You need foo already at cmake-time, not at make-time. 
Ideally you'd want to run ocamldep at make-time to determine the file-level 
dependencies, like cmake does for C/C++/Fortran/Java. However, I don't think 
there's a way to do so currently. IMHO this would be a good feature-request in 
the bug tracker.

Michael
___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


Re: [CMake] Building in stages.

2010-06-22 Thread Magnus Therning
On Mon, Jun 21, 2010 at 17:46, Aeschbacher, Fabrice
 wrote:
> I would try following in foo/CmakeLists.txt:
>
>   add_custom_command(TARGET foo
>      POST_BUILD
>      COMMAND touch bar/CMakeLists.txt
>   )
>
> This will force CMake to re-build the makefiles for 'bar' (because its
> CMakeLists.txt has been modified)
>
> And of course, add_dependencies(bar foo)

It might, but it still feels like a rather strange way to go about it.

I'll make yet another attempt to explain the situation, hopefully better so
that it becomes more clear what the problem is.

There are three tools involved:

  camlp4 - an extensible pre-processor, it makes it possible to modify OCaml
   and even add syntax
  ocamldep - a tool that inspects a source file and tells you what it depends
 on, it can be told to use a preprocessor through its -pp argument
  ocamlc - the OCaml compiler, it can be told to use a preprocessor through
   its -pp argument

Somewhat simplified the project I'm converting to use CMake has two parts:

  foo - an extension to camlp4
  bar - an OCaml module, wich uses the syntax extensions implemented in foo

So if I understand you, these would roughly be the steps I need to take:

1. Call 'cmake' (manual)
This must skip dependency generation for bar; foo isn't built yet and
hence ocamldep will not be able to parse the source for bar.
2. Call 'make' (manual)
Builds foo, and as a last thing touch the CMakeLists.txt for bar.

Now you're saying that because of the post-build step in 2 the following will
happen automatically, right?

3. Call to 'cmake' (automatic)
Now foo has been built so the correct dependencies for bar can be
determined.  (I have yet to find out exactly *how* I can determine that
foo already is built, but that sounds like it shouldn't be too difficult.)

4. Call to 'make' (automatic)
Now the Makefile for bar contains the correct dependency information and
the build can continue.

Have I understood you correctly?

/M

-- 
Magnus Therning(OpenPGP: 0xAB4DFBA4)
magnus@therning.org  Jabber: magnus@therning.org
http://therning.org/magnus identi.ca|twitter: magthe
___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] Building in stages.

2010-06-21 Thread Aeschbacher, Fabrice
I would try following in foo/CmakeLists.txt:

   add_custom_command(TARGET foo
  POST_BUILD
  COMMAND touch bar/CMakeLists.txt
   )

This will force CMake to re-build the makefiles for 'bar' (because its 
CMakeLists.txt has been modified)

And of course, add_dependencies(bar foo)

Hope it helps,
Fabrice Aeschbacher

> -Ursprüngliche Nachricht-
> Von: cmake-boun...@cmake.org [mailto:cmake-boun...@cmake.org] 
> Im Auftrag von Magnus Therning
> Gesendet: Montag, 21. Juni 2010 17:41
> An: Michael Wild
> Cc: Cmake Mailing List
> Betreff: Re: [CMake] Building in stages.
> 
> On Mon, Jun 21, 2010 at 16:10, Michael Wild  wrote:
> >
> >> I'm looking for some suggestions on how to tackle a 
> problem with staged
> >> builds.
> >>
> >> In trying to convert a project which uses omake to build 
> OCaml files I've
> >> stumbled on the issue that building one sub-part (bar) of 
> the project needs
> >> the result of another sub-part (foo).  The twist is that 
> foo is required
> >> already at the dependency-discovery stage of bar[1].  Is 
> there some clever way
> >> of working around this?
> >>
> >> One obvious solution would be to simply skip automatic 
> generation of
> >> dependencies for bar, but that feels a little naughty.  It 
> feels about as
> >> naughty as how the previous build system just worked by 
> ordering[2].
> >>
> >> Hopefully there's some better way of achieving this, any 
> suggestions?
> >>
> >> /M
> >>
> >> [1] For those initiated in OCaml and its tools stack the 
> former sub-part
> >> builds a custom filter for camlp4 which is then used in 
> the latter sub-part.
> >> [2] omake is very similar to make and in this case the 
> build of foo just
> >> happened before bar, and there was no attempt at automatic 
> generation of
> >> dependencies at all.
> >
> > Well, if you need foo to be built before bar, just use 
> add_dependencies(bar foo). File-level dependency scanning 
> happens just before bar is built, so if I understand your 
> question correctly, you should be fine now...
> 
> No, I need foo to be built before bar is inspected to gather its
> dependencies.  And dependencies for both foo and bar are gathered when
> calling `cmake` to generate the Makefiles.  This is how my OCaml
> support works at the moment.  If you have suggestions for how to move
> the dependency generation to compile time (i.e. when calling `make`)
> then I'd be very glad to hear it.  Or even better, be pointed to an
> example of how to achieve that.
> 
> /M
> 
> -- 
> Magnus Therning(OpenPGP: 0xAB4DFBA4)
> magnus@therning.org  Jabber: magnus@therning.org
> http://therning.org/magnus identi.ca|twitter: magthe
> ___
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at 
> http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the CMake FAQ at: 
> http://www.cmake.org/Wiki/CMake_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] Building in stages.

2010-06-21 Thread Magnus Therning
On Mon, Jun 21, 2010 at 16:10, Michael Wild  wrote:
>
>> I'm looking for some suggestions on how to tackle a problem with staged
>> builds.
>>
>> In trying to convert a project which uses omake to build OCaml files I've
>> stumbled on the issue that building one sub-part (bar) of the project needs
>> the result of another sub-part (foo).  The twist is that foo is required
>> already at the dependency-discovery stage of bar[1].  Is there some clever 
>> way
>> of working around this?
>>
>> One obvious solution would be to simply skip automatic generation of
>> dependencies for bar, but that feels a little naughty.  It feels about as
>> naughty as how the previous build system just worked by ordering[2].
>>
>> Hopefully there's some better way of achieving this, any suggestions?
>>
>> /M
>>
>> [1] For those initiated in OCaml and its tools stack the former sub-part
>> builds a custom filter for camlp4 which is then used in the latter sub-part.
>> [2] omake is very similar to make and in this case the build of foo just
>> happened before bar, and there was no attempt at automatic generation of
>> dependencies at all.
>
> Well, if you need foo to be built before bar, just use add_dependencies(bar 
> foo). File-level dependency scanning happens just before bar is built, so if 
> I understand your question correctly, you should be fine now...

No, I need foo to be built before bar is inspected to gather its
dependencies.  And dependencies for both foo and bar are gathered when
calling `cmake` to generate the Makefiles.  This is how my OCaml
support works at the moment.  If you have suggestions for how to move
the dependency generation to compile time (i.e. when calling `make`)
then I'd be very glad to hear it.  Or even better, be pointed to an
example of how to achieve that.

/M

-- 
Magnus Therning(OpenPGP: 0xAB4DFBA4)
magnus@therning.org  Jabber: magnus@therning.org
http://therning.org/magnus identi.ca|twitter: magthe
___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Re: [CMake] Building in stages.

2010-06-21 Thread Michael Wild

> I'm looking for some suggestions on how to tackle a problem with staged
> builds.
> 
> In trying to convert a project which uses omake to build OCaml files I've
> stumbled on the issue that building one sub-part (bar) of the project needs
> the result of another sub-part (foo).  The twist is that foo is required
> already at the dependency-discovery stage of bar[1].  Is there some clever way
> of working around this?
> 
> One obvious solution would be to simply skip automatic generation of
> dependencies for bar, but that feels a little naughty.  It feels about as
> naughty as how the previous build system just worked by ordering[2].
> 
> Hopefully there's some better way of achieving this, any suggestions?
> 
> /M
> 
> [1] For those initiated in OCaml and its tools stack the former sub-part
> builds a custom filter for camlp4 which is then used in the latter sub-part.
> [2] omake is very similar to make and in this case the build of foo just
> happened before bar, and there was no attempt at automatic generation of
> dependencies at all.

Well, if you need foo to be built before bar, just use add_dependencies(bar 
foo). File-level dependency scanning happens just before bar is built, so if I 
understand your question correctly, you should be fine now...

HTH

Michael
___
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake