Porting to FreeBSD

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
User avatar
dpello
Posts: 6
Joined: Sat May 14, 2016 11:51 am

Porting to FreeBSD

Postby dpello » Sat May 14, 2016 12:07 pm

Hello!
I'm making a FreeBSD port of FreeCAD, and I had to make several little changes for it to compile and run. Some of them are just including some headers or adding some conditional preprocessor options (like adding || defined(FC_OS_BSD) in several places) but some of them are a bit bigger.

The main changes are related to the use of the the deprecated function ftime() (that's now being replaced for gettimeofday()) that in FreeBSD requires the static lib -lcompat and is a nightmare to build as you can't link static and dynamic libraries (as some of the FreeCAD core functions are compiled as dynamic libraries), and the code for finding the home path in Application::FindHomePath(), that for Linux uses /proc/self/exe, that is not available on BSDs, so I had to add a FC_OS_FREEBSD conditional and use a sysctl call to get it.

I have several patches for the FreeBSD port system, but perhaps some of them can be included in the FreeCAD code. Any interest on this?

BTW, with the changes FreeCAD runs just fine on FreeBSD.

References:
man ftime: "This function is obsolete. Don't use it. If the time in seconds suffices, time(2) can be used; gettimeofday(2) gives microseconds;"
User avatar
yorik
Site Admin
Posts: 12034
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels, Belgium
Contact:

Re: Porting to FreeBSD

Postby yorik » Sat May 14, 2016 2:03 pm

dpello wrote:I have several patches for the FreeBSD port system, but perhaps some of them can be included in the FreeCAD code. Any interest on this?
By all means, yes!
wmayer
Site Admin
Posts: 16460
Joined: Thu Feb 19, 2009 10:32 am

Re: Porting to FreeBSD

Postby wmayer » Sat May 14, 2016 2:28 pm

The main changes are related to the use of the the deprecated function ftime() (that's now being replaced for gettimeofday()) that in FreeBSD requires the static lib -lcompat and is a nightmare to build as you can't link static and dynamic libraries (as some of the FreeCAD core functions are compiled as dynamic libraries),
I don't know if you found a good solution for this. If not, I think you can also use Qt's QTime class internally or maybe the boost library offers something useful.
User avatar
dpello
Posts: 6
Joined: Sat May 14, 2016 11:51 am

Re: Porting to FreeBSD

Postby dpello » Sat May 14, 2016 2:55 pm

wmayer wrote: I don't know if you found a good solution for this. If not, I think you can also use Qt's QTime class internally or maybe the boost library offers something useful.
I just replaced ftime() with the now standard getimeofday(), It was just used in two files. The thing is it's still used in windows, so I added conditional compiling and redefined the timeb struct when compiling on "not windows", something like this:

Base/TimeInfo.h:

Code: Select all

#if defined(FC_OS_WIN32)
#include <sys/timeb.h>
#else
#include <sys/time.h>
#endif

...

#if !defined(FC_OS_WIN32)
struct timeb
{
        int64_t time;
        unsigned short millitm;
};
#endif
and then in Base/TimeInfo.cpp:

Code: Select all

void TimeInfo::setCurrent(void)
{
#if defined (WIN32)
    _ftime( &timebuffer );
#else
    struct timeval t;
    gettimeofday(&t, NULL);
    timebuffer.time = t.tv_sec;
    timebuffer.millitm = t.tv_usec / 1000;
#endif
}
I made some tests before to check that the second and millisecond returned by both are the same.

Where will be a good place to send the patches? Open an Issue? Make a github fork?
Thanks.
wmayer
Site Admin
Posts: 16460
Joined: Thu Feb 19, 2009 10:32 am

Re: Porting to FreeBSD

Postby wmayer » Sat May 14, 2016 4:13 pm

Where will be a good place to send the patches? Open an Issue? Make a github fork?
If you already have a github account then I think a fork is the most convenient. If you don't have an account you don't need to create one extra for this. Then you can also attach the patch file to this thread.

Thanks.
User avatar
dpello
Posts: 6
Joined: Sat May 14, 2016 11:51 am

Re: Porting to FreeBSD

Postby dpello » Sat May 14, 2016 7:50 pm

I'm sending a pull request in github then.
Thanks!
User avatar
dpello
Posts: 6
Joined: Sat May 14, 2016 11:51 am

Re: Porting to FreeBSD

Postby dpello » Sun May 15, 2016 8:49 am

Pull Request sent and Travis CI build tests passed.
wmayer
Site Admin
Posts: 16460
Joined: Thu Feb 19, 2009 10:32 am

Re: Porting to FreeBSD

Postby wmayer » Sun May 15, 2016 10:27 am

Thanks! It's merged now.
User avatar
dpello
Posts: 6
Joined: Sat May 14, 2016 11:51 am

Re: Porting to FreeBSD

Postby dpello » Sun May 15, 2016 11:54 am

Great!
There is another thing I forgot to mention. As you can see, I'm new to FreeCAD code base, so I'm still trying to get a global image of all the parts.

In the FreeBSD port Makefiles (not related with the freecad makefiles), I'm needing to pass a define for KDL_USE_NEW_TREE_INTERFACE for the Mod/Robot to compile. As this looks something specific to the FreeBSD library versions or something like that, I didn't include that on the patches, but perhaps I can also add a conditional ( if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD) ) to the CMakeLists.txt of Mod/Robot, to include a add_definitions(-DKDL_USE_NEW_TREE_INTERFACE).
What do you think? If it's ok, I'll test it on my system and then I'll make another pull request.
Thanks!
wmayer
Site Admin
Posts: 16460
Joined: Thu Feb 19, 2009 10:32 am

Re: Porting to FreeBSD

Postby wmayer » Sun May 15, 2016 1:04 pm

Not sure which problem you want to solve but there was an issue with KDL for OSX. To fix this a build option has been added to link Robot to an external KDL version. Maybe that's an option for FreeBSD, too. You find it in the cmake panel.