Hi,

Two weeks ago, I added some changes to the cmake build system to
improve static building. There is no documentation for this yet but
I'll give an overview in this mail. I'll add the complete version to
the docs/wiki.

* Linux

There are two use cases for static building which determine the best approach:
- static build to have a single relocatable executable (e.g. to offer
for download)  <-- in trunk before r4150)
- static build for use on a single machine (e.g. to use with postgres)
 <-- default for trunk r4150

The second case is described here since it is the easiest. This was
not the default before r4150 which might have been confusing for some
(i.e. BUILD_SHARED=OFF produced mixed static/shared objects). To
compile a full static executable (or archive), the "-static" gcc
compile flag should be used. In practice, one would now perform the
following steps:

mkdir build ; cd build
cmake -DBUILD_SHARED:BOOL=OFF ..
make
...
ldd src/libopenbabel.a
      not a dynamic executable

The babel tool is also build using this archive and includes
tools/static_plugins.cpp (See below). To compile your own program, you
can alter the tools/CMakeLists.txt file, write your own or simply use
a line like:

g++ mytool.cpp mycode.cpp  -static -I.../openbabel/include
-l.../openbabel/build/src/ -lopenbabel .../tools/static_plugins.cpp

This is gcc only right now.

* Windows

For windows, the main objective is to obtain a single exe that can be
moved on a single desktop or multiple windows machines without having
to worry about the dlls (i.e. Microsoft Visual C++ Runtime, formats,
zlib).

** MSVC

First, static builds should be obtained for at least zlib. The libxml
and inchi are optional. There are binaries available but these might
not work if the MSVC version is not the same. When running cmake, set
BUILD_SHARED to OFF and BUILD_TYPE to Release (Still need to add debug
build I think). This produces a static archive that can be used in
your projects. To build a static executable make sure to select the
/MT compiler option. The resulting exe's only depend on kernel32.dll
which is available on every windows machine.

** cygwin & mingw

I haven't tested these platforms but they should be very similar to
linux. Static libraries for libz and libxml are installed (or can be
installed) and -static should do the same I hope. Please correct me if
I'm wrong.

* Both platforms: Plugins

Formats are normally build using shared modules. The classes in these
modules are normally instantiated when the files are found and loaded.
Including the formats in the archive library does not work since
unused code is removed from the final executable. The solution is to
make the formats directly part of your executable. This can be done by
adding the cpp format files to your project directly or include them
form a file that is part of your project. The tools/static_formats.cpp
file can be used as a template. (On older computers this might take
some time to compile, if this fails (out of memory), the file should
be split up)

There is one caveat though. Since formats are normally build as
modules, there may be namespace conflicts between format files. The
easiest workaround seems to be to give the conflicting formats their
own namespace:

#include ...

namespace OpenBabel {
namespace SomeFormat {

  // format implementation...

}
}

* Not working / todo

** Other compilers: verify that mingw/cygwin work, intel's icc, ...?
** The static babel doesn't include xml & inchi (If we have support
for inchi as a library, inchi should also work)
** Ideally there would be no namespace conflicts (Are there any
objections to adding these namspaces to conflicting formats for
release?)


I'll post the linux relocatable binaries information later since it
involves using a chroot etc. Please let me know if it doesn't work or
if you have suggestions.

Tim

On Thu, Oct 7, 2010 at 5:00 PM, Igor Filippov [Contr]
<filipp...@mail.nih.gov> wrote:
> I need disable-dynamic-modules too, can you post your Makefile?
>
> Thanks,
> Igor
>
> On Thu, 2010-10-07 at 10:55 -0400, Steffen Neumann wrote:
>> Hi,
>>
>> just FYI, I managed to fix the pgchem Makefile,
>> and have a working pgchem with ob-2.2.99
>>
>> Yours,
>> Steffen
>>
>> On Wed, 2010-10-06 at 08:38 +0200, Steffen Neumann wrote:
>> > Is there any equivalent in the cmake build environment ?
>> > I am porting postgres pgchem to svn trunk, and I am unsure
>> > whether the dlopen magic for formats will work from within postgres.
>>
>
>
>
> ------------------------------------------------------------------------------
> Beautiful is writing same markup. Internet Explorer 9 supports
> standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
> Spend less time writing and  rewriting code and more time creating great
> experiences on the web. Be a part of the beta today.
> http://p.sf.net/sfu/beautyoftheweb
> _______________________________________________
> OpenBabel-Devel mailing list
> OpenBabel-Devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/openbabel-devel
>

------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
OpenBabel-Devel mailing list
OpenBabel-Devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbabel-devel

Reply via email to