Importing CommonCrypto as a Swift framework

Stack Overflow:

I think I have an improvement to Mike Weller’s excellent work.

Add a Run Script phase before the Compile Sources phase containing this bash:

# This if-statement means we'll only run the main script if the
# CommonCrypto.framework directory doesn't exist because otherwise
# the rest of the script causes a full recompile for anything
# where CommonCrypto is a dependency
# Do a "Clean Build Folder" to remove this directory and trigger
# the rest of the script to run


if [ -d "${FRAMEWORK_DIR}" ]; then
echo "${FRAMEWORK_DIR} already exists, so skipping the rest of the script."
exit 0

mkdir -p "${FRAMEWORK_DIR}/Modules"
cat <<EOF > "${FRAMEWORK_DIR}/Modules/module.modulemap"
module CommonCrypto [system] {
	header "${SDKROOT}/usr/include/CommonCrypto/CommonCrypto.h"
	export *

ln -sf "${SDKROOT}/usr/include/CommonCrypto" "${FRAMEWORK_DIR}/Headers"

This script constructs a bare bones framework with the module.map in the correct place and then relies on Xcode’s automatic search of BUILT_PRODUCTS_DIR for frameworks.

I linked the original CommonCrypto include folder as the framework’s Headers folder so the result should also function for Objective C projects.