[CMake] Compiling universal binaries for Mac OS X

Brad King brad.king at kitware.com
Fri Nov 11 19:11:13 EST 2005


Jaroslav Snajdr wrote:
> We use CMake to build our software on Mac OS X and right now we are 
> trying to port the program to the Intel Mac platform. Apple has support 
> for creating so-called universal binaries. I compile one executable for 
> PPC, one executable for Intel and finally I merge them into one file 
> (universal binary) with Apple-supplied "lipo" utility.
> 
> Is there any support in CMake for this kind of build process? Is anyone 
> else on this list also going to build universal binaries for Mac OS X? 

As far as I know this has not been done before with CMake.  How do you 
plan to build the per-architecture executables?  Can they all be built 
on the same machine with different compiler flags?  If so then you will 
want to create one build tree per architecture.  Once all the 
executables are built you can use the tool to combine them yourself. 
This could be done in a shell script or in a "cmake -P" script.

Using CMake 2.2 you might also want to look at the new-style ctest 
scripts which can drive multiple builds/tests/installs from a single 
script.  Unfortunately there is not much documentation for these scripts 
yet, but here is an example of their appearance:

CTEST_START(Nightly)
CTEST_UPDATE(SOURCE "${CTEST_SOURCE_DIRECTORY}" RETURN_VALUE res)
CTEST_CONFIGURE(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
CTEST_BUILD(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
CTEST_TEST(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
CTEST_MEMCHECK(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
CTEST_COVERAGE(BUILD "${CTEST_BINARY_DIRECTORY}" RETURN_VALUE res)
CTEST_SUBMIT(RETURN_VALUE res)

You could have multiple CTEST_CONFIGURE and CTEST_BUILD commands to 
build for the different architectures.

-Brad


More information about the CMake mailing list