PDA

View Full Version : Mac-specific issues for qmake and framework dependencies



jiaco
9th July 2010, 15:09
My question concerns how to make my own frameworks and how to make applications that use these frameworks without using the install_name_tool on Mac OSX. My progress so far is quite good, but I am obviously not there yet and could really use help. This is all being developed on Mac OSX 10.6.4 with Qt 4.6.2 Open Source.

I have developed a functional set of 4 shared libraries and many applications that use them on linux and windows without issue. My attempt to port it into mac has been nothing but a headache. I will try to present here a simplified example of the problem.

MyLibA - .h and .cpp files for A-group functionality
MyLibB- .h and .cpp files for B-group functionality (depends on MyLibA)

MyApp - application that depends on both MyLibA/B.

qmake.pri is a file included by all 3 pro files and for mac looks like this:


QMAKE_COPY="cp -fp"
isEmpty( TGT ) : error( You must set TGT for TARGET $${_FILE_} )

VERSION=4.1.0
MY_LIB=/Library/Frameworks

A_LIB=MyLibA
B_LIB=MyLibB

contains( TEMPLATE, lib ) {
CONFIG += lib_bundle explicitlib
DESTDIR = $${MY_LIB}

FRAMEWORK_HEADERS.version = Versions
FRAMEWORK_HEADERS.files = $${HEADERS}
FRAMEWORK_HEADERS.path = Headers

QMAKE_BUNDLE_DATA += FRAMEWORK_HEADERS
QMAKE_FRAMEWORK_BUNDLE_NAME = $${TGT}
QMAKE_FRAMEWORK_VERSION = $${VERSION}
}
contains( TEMPLATE, app ) {
DESTDIR = /Applications
TARGET=$${TGT}
}
MY_A_LIB=$${A_LIB}
MY_A_INC=$${A_LIB}".framework/Headers"
MY_B_LIB=$${B_LIB}
MY_B_INC=$${B_LIB}".framework/Headers"

contains( CONFIG, alib ) {
INCLUDEPATH += $${MY_LIB}/$${MY_A_INC}
LIBS += -framework $${MY_A_LIB}
}
contains( CONFIG, blib ) {
INCLUDEPATH += $${MY_LIB}/$${MY_B_INC}
LIBS += -framework $${MY_B_LIB}
}


Then both Lib qmake.pro files are like this:


TEMPLATE=LIB
TGT=MyLibA

#TGT=MyLibB
#CONFIG += alib

HEADERS += a.h a2.h
SOURCES += a.cpp a2.cpp

include( ../qmake.pri )


And MyApp has a pro file like this:


TEMPLATE=APP
TGT=MyApp

CONFIG += alib blib

HEADERS = myApp.h
SOURCES = myApp.cpp main.cpp

include( ../qmake.pri )


Everyone compiles and installs into the proper locations and the issue is that I need to run install_name_tool on both the libraries and the application before it will successfully run.



#inside /Library/Frameworks

install_name_tool -change MyLibA.framework/Versions/4.1.0/MyLibA /Library/Frameworks/MyLibA.frameworks/Versions/4.1.0/MyLibA /Library/Frameworks/MyLibA.frameworks/Versions/4.1.0/MyLibA
install_name_tool -change MyLibA.framework/Versions/4.1.0/MyLibA /Library/Frameworks/MyLibA.frameworks/Versions/4.1.0/MyLibA /Library/Frameworks/MyLibB.frameworks/Versions/4.1.0/MyLibB
install_name_tool -change MyLibB.framework/Versions/4.1.0/MyLibB /Library/Frameworks/MyLibB.frameworks/Versions/4.1.0/MyLibB /Library/Frameworks/MyLibB.frameworks/Versions/4.1.0/MyLibB

#inside /Applications

install_name_tool -change MyLibA.framework/Versions/4.1.0/MyLibA /Library/Frameworks/MyLibA.frameworks/Versions/4.1.0/MyLibA MyApp.app/Contents/MacOS/MyApp
install_name_tool -change MyLibB.framework/Versions/4.1.0/MyLibB /Library/Frameworks/MyLibB.frameworks/Versions/4.1.0/MyLibB MyApp.app/Contents/MacOS/MyApp



Now I am praying that someone can help me fix this so that I do not have to run this install_name_tool as even with it all scripted up, it does not feel right and I assume I am still missing something...

Thanks in advance -- and lots of names where changed to protect their identity and such, so if there are typos, it was done here in the forum, like I said, I can get it to work, I just cannot figure out how to get rid of the install_name_tool step.

axeljaeger
13th July 2010, 19:25
I guess you will have to run install_name_tool in any case: Your application searches for the framework at some location: Either in /Library/Frameworks or inside the bundle. But even for searching inside the bundle, the path has to be adopted to something like @bundle_path.

jiaco
16th July 2010, 21:53
Thanks for the reply, I have now a bash script that will run otool and then install_name_tool and does the job fine, it is even applied through a command inside my qmake file.

The only issue now is that after running qmake and make, I have to run make macinstall (the name of the target) as I have not been able to automate the process any further than that.

I guess I sort of figured this must be a common problem and that I had overlooked something.

axeljaeger
19th July 2010, 10:59
Just an idea to automate further:
If you are using the subdirs-template in your topmost directory, you can include a directory that just contains a makefile. QMake will execute that makefile. This makefile could be used to trigger your macinstall-task.