## Compiling on OS X with CMake

Discussion and help for Compilation problems and platform portability.

### Compiling on OS X with CMake

I'm trying to compile Luxrender on OS X 10.6 using CMake and I'm finding I'm having to do a lot of monkeying with the CMakeLists to get it to work.

First, I had to remove the special case for boost on APPLE (the non-apple version works for me but the other doesn't). I compiled boost 1.41 myself for this and the proprietary naming in there (the XGCC40 and the 39) were messing it up.

Second, I had to add SET(CMAKE_OSX_DEPLOYMENT_TARGET 10.4) so that the deployment target and the SYSROOT matched.

Now I'm finding I hit an error looking for the 'Threads' library which came up in another post on this forum but was never resolved that I can see (at lest not publicly).

So, can anyone speak to the state of compiling with CMake on OS X? Mostly I'd just like to get past this 'Threads' library error but I'm surprised that I have to make some of these changes. I don't work with boost or CMake usually so perhaps I'm speaking beyond myself. Maybe this just needs some attention for OS X.

Thanks!
Seth
Olliebrown

Posts: 53
Joined: Wed Nov 04, 2009 9:15 pm

### Re: Compiling on OS X with CMake

jromang

Posts: 557
Joined: Wed Sep 19, 2007 2:41 am

### Re: Compiling on OS X with CMake

Hi

I always used cmake-->xcode, especially for crossbuilds cause cmake had no DEPLOYMENT_TARGET variable up to 2.7.

Things changed with cmake 2.8.

So now all depends on what you want to compile and on what system ( 10.4, 10.5 or 10.6 )

From what you wrote i guess you build for 10.4 ? So this is right choice then ( sets automatically isysroot + syslibroot for OSX )
Important: make sure you have the SDK present.( 10.4u.sdk is not installed by default afaik )

In this case cmake generate unix-makefiles and make will do.

Else do it like suggested in wiki. ( i still prefer to use xcode IDE to edit files fast if needed )

Boost:
It depends on the source where you got boost from or how you build.
The OSX-line represents what you get compiling boost as mentioned in appropiatethread ( here in forum--> compilation and portability ) --> system-xgcc40-mt-1_39 ff..
I f you have other naming, just use the common line ( needs special flag i forgot atm to have just clean names ), i let the special OSX line in to have
the ability to hold various versions of boost on my dev-system.

Perhaps i change this for Lux 0.7 ( when all are migrated to newest cmake ) looks as we have to change boostversion to 1.41 then anyway to have python 3.1 -support in boost.
( pylux acces from Blender 2.5 for example )
In the meantime boost 1.39 is mandatory to assure serialization-compatibility between master and remotes when doing networking, so you might change to boost 1.39 for now.
In this case , boostlines are correct.

Jens

jensverwiebe

Posts: 3422
Joined: Wed Apr 02, 2008 4:34 pm

### Re: Compiling on OS X with CMake

Ah, okay. This helps a LOT!

I found that just removing the CMake check for Threads was okay. I was able to get some makefiles output.

Glad you mentioned boost 1.39 dependency. I will switch to that.

I have some of my own problems going on right now (old dylibs hanging around in /opt/ that I need to get rid of). I'm going to work through these and post back my final experience here.

I actually don't need to target 10.4 but I figured it wouldn't hurt. I do have the 10.4u sdk installed. I'm not going to bother with PPC binaries, just 10.4 386 32bit binary.

Thanks for the quick response!

Seth
Olliebrown

Posts: 53
Joined: Wed Nov 04, 2009 9:15 pm

### Re: Compiling on OS X with CMake

Hey Ollie

i386 should work rather out of the box ( 64bit need wx 2.9 thats messy still and i have much local changes laying around here )
Edit the TM-panels to a wider size 380--> 400 afaik ( preferred with wxformbuilder, cause the guifiles are generated ), reason:
bigger fonts on OSX and Linux 13px vs. 10px on win ( yeah, crossplatform )

Good luck

Jens

jensverwiebe

Posts: 3422
Joined: Wed Apr 02, 2008 4:34 pm

### Re: Compiling on OS X with CMake

Okay, I got it working! I can output a makefile or an XCode project from CMake. I did still opt to make some changes to the CMakeLists.txt file but I don't think they are necessary (and they're certainly not the right ones if you want to redistribute the resulting binary). Also, I stopped messing around with the 10.4 SDK and just stuck with the native 10.6. It was an adventure getting all the different dependencies to compile to i386 architecture but once I had that figured out the rest went quite well.

I'm actually getting this all ready for a class I'm TAing where we want the students to use Luxrender instead of PBRT. So, I put together my own little guide on compiling on OS X 10.6 for the students. You can check it out here if you are interested:

http://www-users.itlabs.umn.edu/classes ... 0Lux%20Mac

It only makes 32bit Intel binaries linked against the 10.6 SDK so it is not very redistributable but the point is just to get it compiling so we can make changes to the code.

Now I get to do the same for Windows ... but that's for another day.

Cheers!
Seth
Olliebrown

Posts: 53
Joined: Wed Nov 04, 2009 9:15 pm

### Re: Compiling on OS X with CMake

Oh, unneccessary work in some cases

Ollie, on your site you write:
Compiling luxrender for OS X 10.6 is a PAIN! The CMake file is designed around cmake 2.6 and support for snow leopard was not complete until cmake 2.8. Furthermore, many of the dependencies for luxrender must be compiled to target Intel 32bit which is no longer the default under 10.6.

.....The latest tools default to GCC 4.2 instead of 4.0 as in previous versions and will output x64 binaries instead of x86 binaries. The OS X developer community is not quite ready for x64 (and some of lux's deps will fail to compile in this mode) so you need to override this to x86 EVERYWHERE! This means a lot of compiling of dependencies from scratch

Iám always disappointed about such saying: you are the one without the needed knowledge !
It takes away the fun i have providing 64bit builds since may 2008 !!!!
You may change your attitude a bit ?

- the repository has OSXi386 dependencies all available except actual boost and GUI-tuff ( wx and QT ).
- cmake always worked with some tweaks or via XCode ( sdk-handling )
- compiling for usage with 10.4 need a bit attention on having linked in flat_namespace to avoid unix 2003-errors.
- compiling the right arch is just a question of right compiler-flags, you missed toolchains have changed on SnowLeo ( gcc-4.2 has 64bit toolchain by default, gcc-4.0 still 32bit toolchain )

Keep in mind: 32bit builds should be 10.4 compatible --> 10.4u sdk, 64bit should be 10.5-compatible --> 10.5 sdk and
the GPGPU-branch only works with 10.6 cause openCL was inroduced with SL.

- Best speed is archieved atm using Apple-gcc 4.2.

Anyway, compiling works just fine, i just can´t cover any case of setup, take care to read instructions.
OSS does not mean all comes on a silver-tablet, all sources and dependencies are freely available.
Just complaining is not productive in any case, + if you have problems to compile, use the released builds, thats what they are made for.

Jens

jensverwiebe

Posts: 3422
Joined: Wed Apr 02, 2008 4:34 pm

### Re: Compiling on OS X with CMake

Well, I don't think it's ever 'unnecessary'. I learned a lot in the process and that's what really matters to me. I think it's especially important to have this experience (i.e. compiling all the dependencies from scratch) because I will be helping lots of students work through their compilation problems later. But I do know much of what I did was redundant (and maybe at times illogical).

Working with the binary builds is not an option here. We need to be able to change the code and re-compile. We aren't going to be redistributing anything we compile (that's where your talents and all the other distribution experts come in ... assuming we ever make anything you all are interested in of course ).

When I say compiling in OS X 10.6 is a pain, I really mean in general ... and yes I'm being totally subjective here. It's been a pain for me mostly because I came into it expecting things to work just as they did in 10.5 and in 10.4 and such and they didn't. All of my projects broke when I moved to 10.6 and I've been re-treading ever since it came out. Now, I'm an early adopter here (maybe not any more but I was at the beginning) and I expected all that. I just wish it hadn't been so tough ... and well I have mostly myself to blame.

Regardless, I hope I haven't offended (too late perhaps). Many of my decisions were prompted by 'get-'er done' and were certainty influenced by my background knowledge ... which is only rudimentary.

Anyways, thanks again for your input!
Seth
Olliebrown

Posts: 53
Joined: Wed Nov 04, 2009 9:15 pm

### Re: Compiling on OS X with CMake

Ollie

If 10.6 broke everything, just use now compileflags: -m32 -arch i386 to get same behaviour as under former toolchains.
This is btw typical as in configure: tell the compiler the hostsystem and targetsystem. If you would have done some
crosscompiling before in other OS, you would know thats pretty well the same.

Another option: set gcc = gcc-4.0, could be helpful for 10.4 projects anyway.

The last 2 years i was the only one taking care of Lux OSX, so this is all done in my personal style. Noone cared.

The only thing to take care of in OSX is the special environment being mixed 32/64bit-capable + diferent sdk´s and architectures.
But i leave that to to the ppl who wants this "outdated" stuff, following only the mainstream.

P:S: to see the toolchain used by default, type gcc -v in terminal:
Code: Select all
jens-macpro:~ jensverwiebe$gcc -vUsing built-in specs.Target: i686-apple-darwin10Configured with: /var/tmp/gcc/gcc-5646.1~2/src/configure --disable-checking --enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/\$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin10 --with-gxx-include-dir=/include/c++/4.2.1 --program-prefix=i686-apple-darwin10- --host=x86_64-apple-darwin10 --target=i686-apple-darwin10Thread model: posixgcc version 4.2.1 (Apple Inc. build 5646) (dot 1)`

You see ?
P.S.2: The only thing really makes me sad is the alpha-nature of 64bit wx ( cocoa ), lot odf workarounds to get something useful out of that. so---> QT

P.S.3: saw you overhauled your site, good, thats much more positive thus motivating students to try themselves I hint to use cmake in the GUI.app, it is much more comfortable to manage.

Jens

jensverwiebe

Posts: 3422
Joined: Wed Apr 02, 2008 4:34 pm