[CMake] Sharing objects between executables

Alexander Neundorf a.neundorf-work at gmx.net
Tue Oct 4 12:17:02 EDT 2011


On Tuesday 04 October 2011, pellegrini wrote:
> Hi all,
> 
> I would need your advise about the strategy to adopt when two
> executables share common object files.
> 
> Here is the context. I have a project that consists in a program (e.g.
> console_prog) that was historically a console program
> on top of which a GUI (gui_prog) was built. The gui_prog calling
> directly the console program via an input file generated by the GUI.
> 
> As the gui by itself does not mean anything without its console partner,
> I built a CMakeLists.tx file that contains two add_executables:
> 
>    - add_executable(console_prog console_prog.f90 module1.f90
> module2.f90 module3.f90 ...)
>    - add_executable(gui_prog gui_prog.f90 module1.f90  module2.f90)
> 
> My problem is that gui_prog uses some routines included in the source
> files of the console program (e.g. module1.f90 module2.f90).
> I would like to avoid a double build of module1.f90, module2.f90
> 
> I see two possibilities:
>    - building a static libraries out of the common files and linking it
> to both console_prog and gui_prog executables

Yes, I'd say that's the way to go (if I didn't overlook any special issues).

Alex


More information about the CMake mailing list