Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake Xcode generator - add capability "hardened runtime"

Tags:

xcode

macos

cmake

Problem is quite simple. I have multi platform project (Windows/Mac OS).

Now in case of Mac OS I need to enable "Hardened runtime" in capabilities section of my bundle (it is launchd daemon).

I wish my Xcode project is generated by cmake (I don't want to maintain multiple project files). If I can overcome this problem by modifying build process (for example by adding some flags to xcodebuidl command) it should be fine, but I prefer when everything is defined in CMakeLists.txt files.

Xcode project Capabilities view

like image 879
Marek R Avatar asked Jan 27 '23 08:01

Marek R


1 Answers

You can use the property XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME, which is a boolean.

Set that property on your macOS target, e.g.

set_property(TARGET target PROPERTY XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME YES)

Or if you provide more properties for the target it might look like this:

set_target_properties(target PROPERTIES
    MACOSX_BUNDLE TRUE
    MACOSX_BUNDLE_BUNDLE_NAME "yourTargetName"
    MACOSX_RPATH TRUE
    MACOSX_FRAMEWORK_IDENTIFIER com.host.target
    XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@loader_path/Libraries"
    RESOURCE "${RESOURCE_FILES}"
    XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME YES
)
like image 135
TheNextman Avatar answered Jan 29 '23 10:01

TheNextman