[CMake] Framework Installation Directory / Framework copying

Glenn Hughes ghughes02138 at gmail.com
Wed Dec 9 16:05:50 EST 2009


Thanks Mike,	

I pretty much got my build process on the Mac working. The thing that
took me awhile to understand were the different running contexts that
bits of the CMake script are processed within. What I want is a little
different than the standard way that things are done in the CMake way
of handling Frameworks and bundles. I basically always want the
Frameworks copied into the app, not just during the install phase.

Here's what I'm doing:

1) In my framework CMakeLists.txt file, I have the following:

IF (APPLE)
 	SET_TARGET_PROPERTIES( MyFramework PROPERTIES FRAMEWORK true)
	SET_TARGET_PROPERTIES( MyFramework PROPERTIES
XCODE_ATTRIBUTE_INSTALL_PATH @executable_path/../Frameworks/  )
ENDIF (APPLE)

The second "set_target_properties" line configures the framework to
always be looked for in the application bundle in the Frameworks
sub-folder.

2) In my top-level CMakeLists.txt file, I add setup a unified binary
output directory (thanks Mike!):

SET (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Bin)
SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Bin )
SET (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Bin )

3) Then, in my applications' CMakeLists.txt file, I have the following:

IF (APPLE)
 	ADD_CUSTOM_COMMAND(
 		TARGET MyApp
 		POST_BUILD
  		COMMAND ${PYTHON_EXECUTABLE}
 	    	ARGS ${CMAKE_HOME_DIRECTORY}/CopyFramework.py
		--binary ${PROJECT_BINARY_DIR}/Bin
		--framework MyFramework.framework
       		--app MyApp.app

     )
ENDIF (APPLE)

This calls out to my python script, which does the work of assembling
the src and dest paths, and actually copying the Framework.

The final trick is that since this is a Mac only thing, I can rely on
an Xcode environment variable within the Python script:
		config= os.environ["CONFIGURATION"]

This allows me to assemble the complete path to the actual binary
locations of the framework and the app.

The one thing I wish was that there was a CMake variable that would
expand to the current Config within the context of the
ADD_CUSTOM_COMMAND... It'd be nice to not have to resort to using the
Xcode environment variable.

Thanks again
Glenn


More information about the CMake mailing list