CMake: how do you copy private frameworks to an application package under OS X?

We create several private frameworks that are copied to our application package during the Xcode build process. I am moving the entire build process to CMake, and this is one area that I could not solve.

I found one utility module: CMakeIngestOSXBundleLibraries.cmake, but its a little unclear how it can be used, or if it does what we want. I would like it to start every time the application is created immediately after it is connected. It makes me think that I should do something like

IF (APPLE) add_custom_command( TargetName POST_BUILD CMakeIngestOSXBundleLibraries.cmake ) ENDIF (APPLE) 

but I don’t think it is right. Does anyone have any experience?

+4
source share
1 answer

That's what I'm doing:

1) In my 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 line of "set_target_properties" sets up the structure for always searching in the application set in the Frameworks subfolder.

2) In my top-level CMakeLists.txt file, I add the unified binary setting to the output directory:

 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 application file “CMakeLists.txt” 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 my python script, which builds the src and dest path, and actually copies the Framework.

The final trick is that since this is only a Mac, I can rely on the Xcode environment variable in a Python script:

  config= os.environ["CONFIGURATION"] 

This allows me to compile the full path to the actual binary location of the framework and the application.

The only thing I wish for was that there was a CMake variable that went to the current Configuration in the context of ADD_CUSTOM_COMMAND ... It would be nice not to resort to using Xcode.

+1
source

All Articles