[CMake] Universal binaries

Matthew J Smith indigojo at blogistan.co.uk
Sun Nov 5 18:45:10 EST 2006


Having successfully got CMake to install my resources to where I  
wanted them in the bundle (thanks Axel), I'm now struggling to get it  
to build my universal binary properly.  The instructions I found  
after much Googling were to set the variable  
"CMAKE_OSX_ARCHITECTURES" to "ppc;i386", which I did.  It builds the  
object files, but at the linking stage produces this output:

/usr/bin/c++    -arch ppc -arch i386 -isysroot /Developer/SDKs/ 
MacOSX10.4u.sdk -headerpad_max_install_names -fPIC "CMakeFiles/ 
Speedcrunch.dir/aboutbox.o" "CMakeFiles/Speedcrunch.dir/configdlg.o"  
"CMakeFiles/Speedcrunch.dir/crunch.o" "CMakeFiles/Speedcrunch.dir/ 
deletevardlg.o" "CMakeFiles/Speedcrunch.dir/editor.o" "CMakeFiles/ 
Speedcrunch.dir/evaluator.o" "CMakeFiles/Speedcrunch.dir/functions.o"  
"CMakeFiles/Speedcrunch.dir/hmath.o" "CMakeFiles/Speedcrunch.dir/ 
insertfunctiondlg.o" "CMakeFiles/Speedcrunch.dir/insertvardlg.o"  
"CMakeFiles/Speedcrunch.dir/keypad.o" "CMakeFiles/Speedcrunch.dir/ 
main.o" "CMakeFiles/Speedcrunch.dir/number.o" "CMakeFiles/ 
Speedcrunch.dir/result.o" "CMakeFiles/Speedcrunch.dir/settings.o"  
"CMakeFiles/Speedcrunch.dir/moc_aboutbox.o" "CMakeFiles/ 
Speedcrunch.dir/moc_configdlg.o" "CMakeFiles/Speedcrunch.dir/ 
moc_crunch.o" "CMakeFiles/Speedcrunch.dir/moc_deletevardlg.o"  
"CMakeFiles/Speedcrunch.dir/moc_editor.o" "CMakeFiles/Speedcrunch.dir/ 
moc_evaluator.o" "CMakeFiles/Speedcrunch.dir/moc_functions.o"  
"CMakeFiles/Speedcrunch.dir/moc_hmath.o" "CMakeFiles/Speedcrunch.dir/ 
moc_insertfunctiondlg.o" "CMakeFiles/Speedcrunch.dir/ 
moc_insertvardlg.o" "CMakeFiles/Speedcrunch.dir/moc_keypad.o"  
"CMakeFiles/Speedcrunch.dir/moc_number.o" "CMakeFiles/Speedcrunch.dir/ 
moc_result.o" "CMakeFiles/Speedcrunch.dir/moc_settings.o" "CMakeFiles/ 
Speedcrunch.dir/qrc_crunch.o"   -o Speedcrunch.app/Contents/MacOS/ 
Speedcrunch  -F/usr/local/Trolltech/Qt-4.2.1-Universal/lib -framework  
QtCore -lpthread -framework QtGui -framework Qt3Support
/usr/bin/ld: for architecture ppc
/usr/bin/ld: warning can't open dynamic library: /Developer/SDKs/ 
MacOSX10.4u.sdk/usr/local/Trolltech/Qt-4.2.1-Universal/lib/ 
QtSql.framework/Versions/4/QtSql referenced from: /usr/local/ 
Trolltech/Qt-4.2.1-Universal/lib/Qt3Support.framework/Qt3Support  
(checking for undefined symbols may be affected) (No such file or  
directory, errno = 2)

This (and a lot more) is repeated for the i386 architecture as well.   
In other words, it's looking for the Qt library inside the Mac SDK,  
which suggests that it's feeding the linker the wrong flags.

I enclose my CMakeLists.txt again (revised, obviously) in case anyone  
can tell me what, if anything, I'm doing wrong, or whether it's a bug  
in CMake.

Matt

-- 

http://www.blogistan.co.uk/qt/

-------------- next part --------------
project(speedcrunch) 

IF( APPLE )
  set( PROGNAME Speedcrunch )
  set( MACOSX_BUNDLE_ICON_FILE Speedcrunch.icns )
  set( MACOSX_BUNDLE_SHORT_VERSION_STRING 0.7-beta2 )
  set( MACOSX_BUNDLE_VERSION 0.7-beta2 )
  set( MACOSX_BUNDLE_LONG_VERSION_STRING 0.7-beta2 )
  set( CMAKE_OSX_ARCHITECTURES ppc;i386 ) #Comment out if not universal binary
ELSE( NOT APPLE )
  set( PROGNAME speedcrunch )
ENDIF( APPLE )

cmake_minimum_required(VERSION 2.4.0)
set(CMAKE_COLOR_MAKEFILE ON)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_INCLUDE_CURRENT_DIR TRUE)

# note: sort files alphabetically !

# sources
set(speedcrunch_SOURCES 
aboutbox.cpp
configdlg.cpp
crunch.cpp
crunchico.rc  # special
deletevardlg.cpp
editor.cpp
evaluator.cpp
functions.cpp
hmath.cpp
insertfunctiondlg.cpp
insertvardlg.cpp
keypad.cpp
main.cpp
number.c
result.cpp
settings.cpp
)

# headers
set(speedcrunch_HEADERS
aboutbox.h
configdlg.h
crunch.h
deletevardlg.h
editor.h
evaluator.h
functions.h
hmath.h
insertfunctiondlg.h
insertvardlg.h
keypad.h
number.h
result.h
settings.h
)

# forms
set(speedcrunch_FORMS listdialog.ui)

# resources
set(speedcrunch_RESOURCES crunch.qrc)

# translations
set(speedcrunch_TRANSLATIONS
crunch_cs.qm
crunch_de.qm
crunch_es.qm
crunch_fr.qm
crunch_id.qm
crunch_it.qm
crunch_pl_PL.qm
crunch_pt_BR.qm
crunch_pt.qm
crunch_ru.qm
crunch_sl.qm
)

# we still need those Q3 classes
set( QT_USE_QT3SUPPORT TRUE )  

# enable warnings
ADD_DEFINITIONS( -Wall )

# setup for Qt4
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})

# build everything
qt4_add_RESOURCES( speedcrunch_RESOURCES_SOURCES ${speedcrunch_RESOURCES} )
QT4_WRAP_UI( speedcruch_FORMS_HEADERS ${speedcrunch_FORMS} )
QT4_WRAP_CPP( speedcrunch_HEADERS_MOC ${speedcrunch_HEADERS} )
INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR} )
IF( APPLE )
  #Comment this out if you are not building a universal binary
  #add_definitions( -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk )
  ADD_EXECUTABLE( ${PROGNAME} MACOSX_BUNDLE ${speedcrunch_SOURCES} ${speedcrunch_HEADERS_MOC} ${speedcrunch_RESOURCES_SOURCES} ${speedcruch_FORMS_HEADERS} )
  #Next line for universal binaries only
  #set_target_properties( ${PROGNAME}
    #PROPERTIES 
    #LINK_FLAGS -arch ppc -arch i386 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk )
  ADD_CUSTOM_TARGET( Speedcrunch_RESOURCE_DIR COMMAND mkdir ${CMAKE_CURRENT_BINARY_DIR}/${PROGNAME}.app/Contents/Resources
    COMMAND cp ${MACOSX_BUNDLE_ICON_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${PROGNAME}.app/Contents/Resources
    COMMAND cp *.qm ${CMAKE_CURRENT_BINARY_DIR}/${PROGNAME}.app/Contents/Resources )
  ADD_DEPENDENCIES( ${PROGNAME} Speedcrunch_RESOURCE_DIR )
  #SET_SOURCE_FILES_PROPERTIES( ${speedcrunch_RESOURCES} ${speedcrunch_TRANSLATIONS} crunch.ico
    #PROPERTIES
    #MACOSX_PACKAGE_LOCATION Resources )
ELSE( NOT APPLE )
  ADD_EXECUTABLE( ${PROGNAME} ${speedcrunch_SOURCES} ${speedcrunch_HEADERS_MOC} ${speedcrunch_RESOURCES_SOURCES} ${speedcrunch_FORMS_HEADERS} )
ENDIF( APPLE )

target_link_libraries(${PROGNAME} ${QT_LIBRARIES})

# set(EXECUTABLE_OUTPUT_PATH ${speedcrunch_BINARY_DIR}/../bin)

# install executable and translation files
# note: it will install to CMAKE_INSTALL_PREFIX, which can be set e.g
#  cmake ../branches/0.7 -DCMAKE_INSTALL_PREFIX=/usr
install(TARGETS ${PROGNAME} DESTINATION bin)
install(FILES ${speedcrunch_TRANSLATIONS} DESTINATION share/crunch)
-------------- next part --------------



More information about the CMake mailing list