Sunday 17 February 2013

Compile OpenCASCADE Community Edition the Easy Way! (Update)

Introduction:

After a very late last night as a result from the following: splitting my head for three hours on Finite Element Modelling and for some reason watching Back to the Future:Part II whilst figuring out some code for the section plane, unbelievably I managed to wake up reasonably fresh.

Before starting on the chore of further University work this afternoon. I've been playing with compiling OpenCascade Community Edition in attempt to remove the shackles of Ubuntu's dictated policy of offering old packages.



All of this was inspired by a message on IRC #freecad over the past week about compiling OpenCascade with debug flags, so we actually have useful output when OpenCascade crashes without a warning (mostly from an unhandled exceptions on our part).

Benefits:

  • The other benefits are testing some new features - only recently has a commit been made to improve performance of boolean operations that will soon be merged - see discussusion
  • Full debug build so we can trace crashes correctly
  • Living life on the edge of your seat!

The first compile went really well, however, after attempting to compile FreeCAD I found that there were a few missing libraries that prevent FreeCAD from building. These were the visualisation and Model Exachange packages used by SMESH and Part for the IGES and STEP formats import.  I am not sure if these should have been detected by FreeCAD's cmake but anyway, trial and error prevails.

I also attempted to build OCE using TBB which is a threading library that can be used to speed up operations, however from what I read this is only used in a few algorithms.

Note:

Compiling OpenCascade does take a long time, around probably 50% longer than FreeCAD for a clean build. On my six core AMD Bulldozer computer, it took in the region of 18 minutes in total to compile with each core at 100%. Also remember that you will need additional time to compile FreeCAD again. Once this has been done, recompiling is very quick.



Be prepared to find something useful to do in the mean and drink tea or even a beer for a good half an hour.

Compiling OCE OpenCascade Community Edition (Easy Guide):


Reminder: expect 20-30 Minutes to compile:

Clone the repository:

Grab the latest git source from the official Open Cascascade Community Edition from the github page. The source is around 240mb when fully expanded and may take a while to download on a slow internet connection.

git clone https://github.com/tpaviot/oce.git

Create a build directory:

Create a suitable build directory, this can be in the main source folder but preferably outside to prevent potential conflicts
mkdir oceBuild && cd oceBuild

Install libftgl-dev in Package Manager:

You need to install following development package for libftgl to compile the Visualisation Package in OCE. This will depend on your Distribution. 

Install libtb2 & libtbb-dev in Package Manager:

For enabling TBB - Threaded Building Blocks Library to be used in multithreading, you will need to ensure that these are installed on your system. Below are the package names in Ubuntu.

Remove any previous Opencascade libraries provided by distro:

I don't think OpenCascade and OCE can be run in parallel on the same machine - correct me if I'm wrong. Therefore you will need to remove any of these on your system.  

Configure the sources using CMake

Configure the OCE sources running the following cmake command in the current directory. This will install OCE to your /usr directory. 

cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr/ \
      -DOCE_INSTALL_PREFIX:PATH=/usr/ \
      -DOCE_WITH_FREEIMAGE=OFF \
      -DOCE_WITH_GL2PS=OFF \
      -DOCE_VISUALISATION=ON \
      -DOCE_DATAEXCHANGE=ON \
      -DOCE_MULTITHREAD_LIBRARY=TBB \
      -DCMAKE_BUILD_TYPE=Debug \
      ../oce

If you're installing on Ubuntu or Debian based distribution, it's advisable to change the install directory to /usr/local to isolate user compiled packages (@yorik) - (I need to confirm if FreeCAD can detect the location of the OCE header files from the location)

-DCMAKE_INSTALL_PREFIX:PATH=/usr/local \

You may find that there are some missing development dependencies, so if there are you will have to install these using your package manager. I found generally if you could install FreeCAD you wouldn't experience any problems atleast on Ubuntu.

Create a release build (Improve Performance):

You may not want debug flags enabled so that you can have full compiler optimisations and full performance when using FreeCAD: change the line previously from
DCMAKE_BUILD_TYPE=Debug \
to
DCMAKE_BUILD_TYPE=Release \ 

Begin Compiling:

When you start compiling OCE  be prepared to wait a while. Replace 6 with the number of cores or independent threads that can be run on your computer to speed up compiling by running concurrent make operations.
make -j6 -pipe

There has been some discussion whether the '-pipe' argument can reduce compiling times. If someone has enough time to make a comparison with OCE it would be interesting to see the difference.

Install:

Usually I install any compiled software to my user directory, but that wouldn't be straightforward. Therefore CMake was configured to install to /usr directory for simplicity later on. 
sudo make install
 
 

Installing on Debain / Ubuntu Systems:

Another helpful hint from @yorik is to install using the built in utility checkinstall. This provides a convenient method of uninstalling OCE using the system's package manager. Once you have finished compiling, run the following command:

sudo checkinstall

Type (y) to accept the defaults, then you will be presented with a menu to further describe the package - do this at your own leisure:

Once checkinstall is completed - this will take a while, it will produce a .deb package and OCE will have been installed to your system and registered in your system package manager.
 

Recompile FreeCAD:

There will be changes to the development sources since we are using a different edition of OpenCascade with FreeCAD. You will need to clean all the sources. From your previous FreeCAD build directory make sure run the following before recompiling (see previous post on compiling FreeCAD :

sudo make clean

If OCE was compiled and installed correctly, whilst configuring FreeCAD you will find the following log message (OpenCASCADE Community Edition has been found):



Recompile once again and you should have FreeCAD working with the latest OCE!

Hopefully people will have understand the guide and will now have a working version of OCE that is is used by FreeCAD. If there seems to be problems or something isn't clear, please let me know and I will update the guide. 

9 comments:

  1. Thanks for the guide, I didn't know about that debug mode and that it would say what went wrong when an OCC operation fails. This is tremendously useful! I'll compile mine at once...

    Two considerations about your guide: 1) Usually on debian-based systems the standard is to put your home-compiled stuff inside /usr/local instead of /usr, so you clearly separate what is compiled by yourself from what comes from debian, and normally all corresponding lib. bin, share subfolders are already set in default search paths so there is nothing more to do, and 2) there is a cool utility called checkinstall that you can use instead of make install, that produces a .deb package instead of just copying files, so it is easy to remove later if needed. I use it a lot with stuff I compile myself...

    ReplyDelete
    Replies
    1. Hi Yorik, Thanks for the information on Debian packaging, I will first try it out and then add it to the guide - I've never compiled a package before, so it be worth giving that a go.

      For today now I've run OCE without any problems. Seems a viable choice really if you have a good enough computer to compile it.

      Delete
  2. Thanks! I had to install xorg-dev packages due to missing X11_Xmu_LIB. I was curious if I should use j4 (physical cores) or j8 (logical cores, HT). The results for notebook i7 3632QM (2.2 GHz base frequency, turbo up to 3.2 when 1 core active or 3.0 when 4 cores active, 4C/8T):
    -j4, 2.9GHz per core: 20 minutes
    -j8, 2.6GHz per core: 17 minutes

    ReplyDelete
    Replies
    1. the number after the j is the number of jobs that make will perform parallel - I would imagine that matching the number of max threads available (8 with HT) would make more sense. This number isn't restricted to number of threads - you can have more but it may actually slow down compiling - presumably if all CPU's are at 100% load increasing j doesn't make sense.

      The next thing I am going to look at it is using possibly using a virtual ram drive to temporarily store the source code on and see if that improves performance. It's apparently relatively simple in linux from what I have heard!

      Delete
  3. Hi Luke
    Thanks for this.

    I run multiple versions of OCE, I haven't yet had any problems that I know of :-), you just have to change the install path to something different for the different versions...However when you want to compile FreeCAD it will find the default install automatically, you have to specifically tell FreeCAD to look at the version of OCE you want it to compile FreeCAD against.

    Which brings me to another useful tip, install "cmake gui" and use that rather than typing the cmake command line flags. It has the advantage of showing you the changeable flags and also has a tool tip that gives further information about the options available for that flag. E.G. it will say "compile type" then have a text box, the tool tip says something like "option are Debug, release"...etc.

    Then when it comes time to compile FreeCAD, first run cmake gui and select the correct directory containing the correct version of OCE to compile FreeCAD against.

    Of course using git gui or not is a matter personal taste but it probably is easier for beginners.

    Jim

    ReplyDelete
  4. i want to ask a question what is better to have oce or the last version of opencascade? for example last version of opencascade is 6.6.0.1 it should have less bugs than Oce 0.11 or not? does having oce vs opencascade make freecad to work different? less bugs? or for freecad it the same?
    regards
    Dam

    ReplyDelete
  5. Hi Dam,

    It's a difficult question actually, but both have a very similar source and share the same API which is why we can use both in FreeCAD. Oce is a community based derivative of Open Cascade where the developers seem to apply fixes themselves and from OpenCascade rather than feature development - I would assume also assume their releases are more frequent.

    In the end, I doubt there is much difference. What I certainly say is that you try to obtain the latest stable version offered. We see people use OpenCascade 6.3 which can be buggy in places and slow.

    Luke

    ReplyDelete
  6. Silly question i'm sure. But how do you launch it after it's installed? I can't find it and I'm not sure what to type into the terminal.

    ReplyDelete
    Replies
    1. Dear Patrick,

      OpenCascade is a primarily a set of libraries that are used in conjunction with other applications such as FreeCAD. There are also bindings for other programming langaugs, such as python (pythonocc.org / freecad) which provide the components that can be used to use the modelling features and algorithms included in the libraries.

      There are example programs included and there is also a command line tool somewhere but I'm not sure what its location is or if these are included when you compile OpenCascade by default

      Delete