[CMake] Compiling object files.

2013-04-03 Thread Daniel Carrera
Hello,

Summary: How do I use CMake to compile object files? Or is this the
wrong question to ask? (i.e. *should* I be compiling object files?)

Details:
-
I am starting to learn CMake, so I am not even sure I am formulating
my questions the right way... I have a large Makefile that I want to
try to convert to CMake. I did not write the Makefile and I know
little about build systems. But I am interested in CMake and I want to
experiment anyway. My first question is how to convert something like
this:

cparam.o:  cparam.f90 cparam.local cparam.inc cparam_pencils.inc
if [  ]; then \
rm -f cparam.inc; \
rm -f cparam_pencils.inc; \
ln -s cparam.inc cparam.inc; \
ln -s cparam_pencils.inc cparam_pencils.inc; \
fi
$(FC) $(FFLAGS) $(FFLAGS_GENERAL) $(F90FLAGS) -o cparam.o -c cparam.f90


I cannot imagine what the if statement could possibly accomplish, but
I trust that CMake would make the whole thing unnecessary. So I figure
(hope) that all I have to do is tell CMake to make the object file
cparam.o. The problem is that I cannot find anything in the
instructions for making object files. All I see is commands like:


add_executable(hello  hello.f90 world.f90)

add_library(particles backend.f90 vector.f90 const.f90)


There is no add_object function or anything like it... Maybe I am
going about it the wrong way. Maybe I should not be thinking in terms
of making object files at all. Perhaps I should be planning to do
something like:

add_executable(myprogram ${HUGE_LIST_OF_200_FILES})

My worry with this approach is that I see no room to convert the
Makefile incrementally. I was thinking of compiling just one object
file, check that that works and has the right symbols, and then move
to the next object file. Whereas this other option looks like an all
or nothing proposition.

I would welcome any words of advice here.

Cheers,
Daniel.
--
Lord of the rings calendar in your Linux/Unix/Mac terminal:
cat /usr/share/calendar/calendar.lotr
--

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] Compiling object files.

2013-04-03 Thread landa
Hello Daniel,

I'm also starting with CMake and I had a problem to link an object to my
project. I will describe you what I did because it works for me but keep in
mind that maybe there is a better way.

First, you can compile object files with the command execute_process:

 execute_process(
   COMMAND
   $(FC) $(FFLAGS) $(FFLAGS_GENERAL) $(F90FLAGS) -o
cparam.lib -c cparam.f90
   )

Note that it is not cparam.o but cparam.lib.

Then you can link it to your project as a library with the command
target_link_libraries:

 target_link_libraries(
your_project
cparam.lib
)

Hope it can help you.
Damien



--
View this message in context: 
http://cmake.3232098.n2.nabble.com/Compiling-object-files-tp7583910p7583911.html
Sent from the CMake mailing list archive at Nabble.com.
--

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] Compiling object files.

2013-04-03 Thread Johannes Zarl
Hi Daniel,

On Wednesday, 3. April 2013, 16:06:36, Daniel Carrera wrote:
 Summary: How do I use CMake to compile object files? Or is this the
 wrong question to ask? (i.e. *should* I be compiling object files?)

Short answer: normally you don't and you shouldn't add statements to compile 
object files.

CMake is a build system generator, not a build-system in itself. I.e. you only 
tell cmake I want to build library A from source files a.cpp and b.cpp, and I 
want to link my application C , which is created from c.cpp, to the library 
A. CMake then generates the build system (e.g. Makefiles or a Visual Studio 
solution) for you.

 Details:
 -
 I am starting to learn CMake, so I am not even sure I am formulating
 my questions the right way... I have a large Makefile that I want to
 try to convert to CMake. I did not write the Makefile and I know
 little about build systems. But I am interested in CMake and I want to
 experiment anyway. 

If you have problems with the terminology and concepts behind cmake, I would 
recommend browsing through the wiki ( 
http://www.cmake.org/Wiki/CMake#Basic_Introductions ). While it can be 
overwhelming at first, there is a wealth of information to be found there.

 My first question is how to convert something like
 this:
 
 cparam.o:  cparam.f90 cparam.local cparam.inc cparam_pencils.inc
 if [  ]; then \
 rm -f cparam.inc; \
 rm -f cparam_pencils.inc; \
 ln -s cparam.inc cparam.inc; \
 ln -s cparam_pencils.inc cparam_pencils.inc; \
 fi
 $(FC) $(FFLAGS) $(FFLAGS_GENERAL) $(F90FLAGS) -o cparam.o -c
 cparam.f90
 
 
 I cannot imagine what the if statement could possibly accomplish, but
 I trust that CMake would make the whole thing unnecessary. 

The if statement is effectively just a block-comment. You can just ignore it 
and its contents.

 So I figure
 (hope) that all I have to do is tell CMake to make the object file
 cparam.o. The problem is that I cannot find anything in the
 instructions for making object files. All I see is commands like:
 
 
 add_executable(hello  hello.f90 world.f90)
 
 add_library(particles backend.f90 vector.f90 const.f90)
 
 
 There is no add_object function or anything like it... Maybe I am
 going about it the wrong way. Maybe I should not be thinking in terms
 of making object files at all. Perhaps I should be planning to do
 something like:
 
 add_executable(myprogram ${HUGE_LIST_OF_200_FILES})

That's the right way to go. Although if you have over 200 input files, you 
might want to group them into libraries if that's appropriate.

 My worry with this approach is that I see no room to convert the
 Makefile incrementally. I was thinking of compiling just one object
 file, check that that works and has the right symbols, and then move
 to the next object file. Whereas this other option looks like an all
 or nothing proposition.

Converting incrementally can't be done IMO (at least not without significant 
overhead). Since you would probably use the Makefile generator of cmake, you 
would probably just end up with cmake overwriting your makefiles or similar 
problems.

I hope that cleared up some of the confusion. Please do ask again if there are 
problems...

  Johannes
--

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] Compiling object files.

2013-04-03 Thread Daniel Carrera
Hi Johannes,

On 3 April 2013 17:44, Johannes Zarl johannes.z...@jku.at wrote:
 Short answer: normally you don't and you shouldn't add statements to compile
 object files.

 CMake is a build system generator, not a build-system in itself. I.e. you only
 tell cmake I want to build library A from source files a.cpp and b.cpp, and I
 want to link my application C , which is created from c.cpp, to the library
 A. CMake then generates the build system (e.g. Makefiles or a Visual Studio
 solution) for you.

Thanks. I guess that makes sense.


 If you have problems with the terminology and concepts behind cmake, I would
 recommend browsing through the wiki (
 http://www.cmake.org/Wiki/CMake#Basic_Introductions ). While it can be
 overwhelming at first, there is a wealth of information to be found there.

Thanks. I have been impressed by the quantity of CMake documentation.
There is not as much for Fortran, but I think that by now I've learnt
most of the Fortran-specific stuff. I will keep reading through the
docs. As you said, it is a bit overwhelming at first.


 There is no add_object function or anything like it... Maybe I am
 going about it the wrong way. Maybe I should not be thinking in terms
 of making object files at all. Perhaps I should be planning to do
 something like:

 add_executable(myprogram ${HUGE_LIST_OF_200_FILES})

 That's the right way to go. Although if you have over 200 input files, you
 might want to group them into libraries if that's appropriate.


Thanks. At least now I have the right idea. I think I will try to come
up with logical groupings that can be turned into libraries.


 Converting incrementally can't be done IMO (at least not without significant
 overhead). Since you would probably use the Makefile generator of cmake, you
 would probably just end up with cmake overwriting your makefiles or similar
 problems.


I don't mean that I expect to compile the entire program with a
half-Makefile, half-CMake system. I like your idea of making
libraries. If I can make a library with a handful of files and I can
verify that the compile didn't fail and the library has the correct
symbols, I would call that a successful incremental step.

 I hope that cleared up some of the confusion. Please do ask again if there are
 problems...

Very helpful. Thanks.

Cheers,
Daniel.
--

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