Skip to content

Commit

Permalink
register_install_codesign_target takes an optional ENTITLEMENTS singl…
Browse files Browse the repository at this point in the history
…eValueKeyword now, sign E+ with it

Without the com.apple.security.cs.disable-library-validation I can't later on pip install C-extensions into the python_lib/ folder. This is done on OpenStudio SDK in particular...
  • Loading branch information
jmarrec committed Nov 4, 2024
1 parent 1ca900f commit 07e8314
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 13 deletions.
52 changes: 40 additions & 12 deletions cmake/CodeSigning.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,18 @@ endfunction()

function(register_install_codesign_target TARGET_NAME DESTINATION COMPONENT)

set(prefix "")
set(valueLessKeywords "")
set(singleValueKeywords ENTITLEMENTS)
set(multiValueKeywords "")
cmake_parse_arguments(
PARSE_ARGV 3 # We have 3 positional keywords that are required
"${prefix}"
"${valueLessKeywords}"
"${singleValueKeywords}"
"${multiValueKeywords}"
)

if(NOT TARGET ${TARGET_NAME})
message(FATAL_ERROR "${TARGET_NAME} is not a valid target")
endif()
Expand All @@ -401,17 +413,33 @@ function(register_install_codesign_target TARGET_NAME DESTINATION COMPONENT)
return()
endif()

install(
CODE "
include(\"${CMAKE_CURRENT_FUNCTION_LIST_FILE}\")
codesign_files_macos(
FILES \"\${CMAKE_INSTALL_PREFIX}/${DESTINATION}/$<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET_NAME},MACOSX_BUNDLE>>,$<TARGET_BUNDLE_DIR_NAME:${TARGET_NAME}>,$<TARGET_FILE_NAME:${TARGET_NAME}>>\"
SIGNING_IDENTITY \"${CPACK_CODESIGNING_DEVELOPPER_ID_APPLICATION}\"
IDENTIFIER \"${CPACK_CODESIGNING_MACOS_IDENTIFIER}.${TARGET_NAME}\"
FORCE VERBOSE $<$<BOOL:$<TARGET_PROPERTY:${TARGET_NAME},MACOSX_BUNDLE>>:DEEP>
)
"
COMPONENT ${COMPONENT}
)
if (_ENTITLEMENTS)
install(
CODE "
include(\"${CMAKE_CURRENT_FUNCTION_LIST_FILE}\")
codesign_files_macos(
FILES \"\${CMAKE_INSTALL_PREFIX}/${DESTINATION}/$<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET_NAME},MACOSX_BUNDLE>>,$<TARGET_BUNDLE_DIR_NAME:${TARGET_NAME}>,$<TARGET_FILE_NAME:${TARGET_NAME}>>\"
SIGNING_IDENTITY \"${CPACK_CODESIGNING_DEVELOPPER_ID_APPLICATION}\"
IDENTIFIER \"${CPACK_CODESIGNING_MACOS_IDENTIFIER}.${TARGET_NAME}\"
FORCE VERBOSE $<$<BOOL:$<TARGET_PROPERTY:${TARGET_NAME},MACOSX_BUNDLE>>:DEEP>
ENTITLEMENTS \"${_ENTITLEMENTS}\"
)
"
COMPONENT ${COMPONENT}
)
else()
install(
CODE "
include(\"${CMAKE_CURRENT_FUNCTION_LIST_FILE}\")
codesign_files_macos(
FILES \"\${CMAKE_INSTALL_PREFIX}/${DESTINATION}/$<IF:$<BOOL:$<TARGET_PROPERTY:${TARGET_NAME},MACOSX_BUNDLE>>,$<TARGET_BUNDLE_DIR_NAME:${TARGET_NAME}>,$<TARGET_FILE_NAME:${TARGET_NAME}>>\"
SIGNING_IDENTITY \"${CPACK_CODESIGNING_DEVELOPPER_ID_APPLICATION}\"
IDENTIFIER \"${CPACK_CODESIGNING_MACOS_IDENTIFIER}.${TARGET_NAME}\"
FORCE VERBOSE $<$<BOOL:$<TARGET_PROPERTY:${TARGET_NAME},MACOSX_BUNDLE>>:DEEP>
)
"
COMPONENT ${COMPONENT}
)
endif()

endfunction()
9 changes: 9 additions & 0 deletions cmake/python_entitlements.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- This is needed because otherwise you can't pip install stuff into the python_lib folder -->
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
</dict>
</plist>
2 changes: 1 addition & 1 deletion src/EnergyPlus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,6 @@ endif()

if(APPLE AND CPACK_CODESIGNING_DEVELOPPER_ID_APPLICATION)
include("${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/CodeSigning.cmake")
register_install_codesign_target(energyplus "." Unspecified)
register_install_codesign_target(energyplus "." Unspecified ENTITLEMENTS "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/python_entitlements.xml")
register_install_codesign_target(energyplusapi "." Unspecified)
endif()

0 comments on commit 07e8314

Please sign in to comment.