Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMake to the project #220

Merged
merged 1 commit into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ DerivedData/
*.xccheckout
*.moved-aside
!Podfile.lock
.idea
cmake-build-debug

# OS junk
.DS_Store
Expand Down
26 changes: 26 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
cmake_minimum_required( VERSION 3.8 )

project( Clutch )

set( PRODUCT_NAME Clutch )
set( EXECUTABLE_NAME Clutch )
set( PRODUCT_BUNDLE_IDENTIFIER kjc.Clutch )
set( MACOSX_BUNDLE_SHORT_VERSION_STRING "2.0.4" )
set( MACOSX_BUNDLE_BUNDLE_VERSION "1" )
set( DEVICE_FAMILY "1,2" )
set( DEPLOYMENT_TARGET 8.0 CACHE STRING "" )
set( CODE_SIGN_IDENTITY "iPhone Developer" )

if( NOT CMAKE_BUILD_TYPE )
set( CMAKE_BUILD_TYPE Release )
endif( NOT CMAKE_BUILD_TYPE )

if( CMAKE_BUILD_TYPE STREQUAL Debug )
add_definitions( -DDEBUG )
endif()

include_directories( ${CMAKE_CURRENT_SOURCE_DIR} )

include( cmake/DebugUtils.cmake )
include( cmake/AddFramework.cmake )
add_subdirectory( Clutch )
161 changes: 161 additions & 0 deletions Clutch/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
cmake_minimum_required( VERSION 3.8 )

set( SOURCE_COMMANDS
ClutchCommands.h
ClutchCommands.m )
source_group( "Commands" FILES ${SOURCE_COMMANDS} )
list( APPEND SOURCE_FILES ${SOURCE_COMMANDS} )

set( SOURCE_OPERATIONS
ZipOperation.h
ZipOperation.m
BundleDumpOperation.h
BundleDumpOperation.m
FinalizeDumpOperation.h
FinalizeDumpOperation.m )
source_group( "Operations" FILES ${SOURCE_OPERATIONS} )
list( APPEND SOURCE_FILES ${SOURCE_OPERATIONS} )

set( SOURCE_DUMPERS
ASLRDisabler.h
ASLRDisabler.m
ARMDumper.h
ARMDumper.m
ARM64Dumper.h
ARM64Dumper.m
FrameworkDumper.h
FrameworkDumper.m
Framework64Dumper.h
Framework64Dumper.m
FrameworkLoader.h
FrameworkLoader.m )
source_group( "Dumpers" FILES ${SOURCE_DUMPERS} )
list( APPEND SOURCE_FILES ${SOURCE_DUMPERS} )

set( SOURCE_PROTOCOL_PARENT_DUMPER
BinaryDumpProtocol.h
Dumper.h
Dumper.m )
source_group( "Dumpers\\Protocol + Parent Dumper" FILES ${SOURCE_PROTOCOL_PARENT_DUMPER} )
list( APPEND SOURCE_FILES ${SOURCE_PROTOCOL_PARENT_DUMPER} )

set( SOURCE_APPLICATION
Application.h
Application.m
Extension.h
Extension.m
Framework.h
Framework.m )
source_group( "Application" FILES ${SOURCE_APPLICATION} )
list( APPEND SOURCE_FILES ${SOURCE_APPLICATION} )

set( SOURCE_CLUTCH_BUNDLE
Binary.h
Binary.m
ClutchBundle.h
ClutchBundle.m )
source_group( "Application\\ClutchBundle" FILES ${SOURCE_CLUTCH_BUNDLE} )
list( APPEND SOURCE_FILES ${SOURCE_CLUTCH_BUNDLE} )

set( SOURCE_MAIN
KJApplicationManager.h
KJApplicationManager.m
Device.h
Device.m
main.m
ClutchPrint.h
ClutchPrint.m )
source_group( "" FILES ${SOURCE_MAIN} )
list( APPEND SOURCE_FILES ${SOURCE_MAIN} )

set( PRECOMPILED_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/Clutch-Prefix.pch )
set( SOURCE_SUPPORTING_FILES
../LSApplicationProxy.h
${PRECOMPILED_HEADER}
SCInfoBuilder.h
SCInfoBuilder.m
sha1.c
sha1.h
Clutch.entitlements
mach_vm.h
NSTask.h
scinfo.h
scinfo.m
LSApplicationWorkspace.h
FBApplicationInfo.h
Info.plist
NSFileHandle+Private.h
NSFileHandle+Private.m
NSBundle+Clutch.h
NSBundle+Clutch.m )
source_group( "Supporting Files" FILES ${SOURCE_SUPPORTING_FILES} )
list( APPEND SOURCE_FILES ${SOURCE_SUPPORTING_FILES} )

set( SOURCE_OPTOOL
optool.h
optool-defines.h
optool-headers.h
optool-headers.m
optool-operations.h
optool-operations.m
NSData+Reading.h
NSData+Reading.m )
source_group( "Supporting Files\\optools" FILES ${SOURCE_OPTOOL} )
list( APPEND SOURCE_FILES ${SOURCE_OPTOOL} )

set( SOURCE_ZIP
ZipArchive.h
ZipArchive.m )
source_group( "Supporting Files\\Zip" FILES ${SOURCE_ZIP} )
list( APPEND SOURCE_FILES ${SOURCE_ZIP} )

set( RESOURCE_SCRIPTS
move_and_sign.sh )
source_group( "scripts" FILES ${RESOURCE_SCRIPTS} )
list( APPEND SOURCE_FILES ${RESOURCE_SCRIPTS} )

configure_file( Clutch.entitlements Clutch.entitlements COPYONLY )
configure_file( Info.plist.in Info.plist COPYONLY )

add_subdirectory( MiniZip )

add_executable( Clutch MACOSX_BUNDLE ${SOURCE_FILES} $<TARGET_OBJECTS:MiniZip> )
AddFramework( Clutch Foundation )
AddFramework( Clutch UIKit )
AddFramework( Clutch MobileCoreServices )
target_include_directories( Clutch PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} )

if( CMAKE_GENERATOR STREQUAL Xcode )
set_target_properties( Clutch
PROPERTIES
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in"
XCODE_ATTRIBUTE_SDKROOT iphoneos
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "${PRODUCT_BUNDLE_IDENTIFIER}"
XCODE_ATTRIBUTE_CODE_SIGN_STYLE "Manual"
XCODE_ATTRIBUTE_CODE_SIGN_INJECT_BASE_ENTITLEMENTS YES
XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET}
XCODE_ATTRIBUTE_ARCHS "$(ARCHS_STANDARD)"
XCODE_ATTRIBUTE_ENABLE_BITCODE YES
XCODE_ATTRIBUTE_SKIP_INSTALL YES
XCODE_ATTRIBUTE_CLANG_ENABLE_MODULES YES
XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT dwarf-with-dsym
XCODE_ATTRIBUTE_GCC_PREFIX_HEADER "${PRECOMPILED_HEADER}"
XCODE_ATTRIBUTE_GCC_PRECOMPILE_PREFIX_HEADER YES
XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY ${DEVICE_FAMILY}
XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES
XCODE_ATTRIBUTE_INSTALL_PATH "$(LOCAL_APPS_DIR)"
XCODE_ATTRIBUTE_ENABLE_TESTABILITY YES
XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN YES )
else()
target_compile_options( Clutch
PRIVATE
-include "${PRECOMPILED_HEADER}"
-miphoneos-version-min=${DEPLOYMENT_TARGET}
-fobjc-arc
-fmodules )
endif()

add_custom_command( TARGET Clutch POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/build"
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:Clutch> "${CMAKE_BINARY_DIR}/build/"
COMMAND codesign -fs- --entitlements "${CMAKE_CURRENT_BINARY_DIR}/Clutch.entitlements" "${CMAKE_BINARY_DIR}/build/Clutch" )
37 changes: 37 additions & 0 deletions Clutch/Info.plist.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>2.0.4</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>Stub</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
36 changes: 36 additions & 0 deletions Clutch/MiniZip/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
cmake_minimum_required( VERSION 3.8 )

project( MiniZip LANGUAGES C )

set( HEADERS_FILES
crypt.h
ioapi.h
unzip.h
zip.h )

set( SOURCE_FILES
ioapi.c
unzip.c
zip.c )
source_group( "" FILES ${HEADERS_FILES} ${SOURCE_FILES} )

add_library( MiniZip OBJECT ${HEADERS_FILES} ${SOURCE_FILES} )
target_include_directories( MiniZip PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} )

if( CMAKE_GENERATOR STREQUAL Xcode )
set_target_properties( MiniZip
PROPERTIES
XCODE_ATTRIBUTE_SDKROOT iphoneos
XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET}
XCODE_ATTIRBUTE_ENABLE_BITCODE YES
XCODE_ATTIRBUTE_SKIP_INSTALL YES
XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT dwarf-with-dsym
XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY ${DEVICE_FAMILY}
XCODE_ATTRIBUTE_INSTALL_PATH "$(LOCAL_APPS_DIR)"
XCODE_ATTRIBUTE_ENABLE_TESTABILITY YES
XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN YES )
else()
target_compile_options( MiniZip
PRIVATE
-miphoneos-version-min=${DEPLOYMENT_TARGET} )
endif()
14 changes: 14 additions & 0 deletions cmake/AddFramework.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
macro( AddFramework TARGET NAME )
find_library( FRAMEWORK_${NAME}
NAMES ${NAME}
PATHS ${CMAKE_OSX_SYSROOT}/System/Library
PATH_SUFFIXES Frameworks
CMAKE_FIND_FRAMEWORK only
NO_DEFAULT_PATH )
if( ${FRAMEWORK_${NAME}} STREQUAL FRAMEWORK_${NAME}-NOTFOUND )
message( ERROR ": Framework ${NAME} not found" )
else()
target_link_libraries( ${TARGET} ${FRAMEWORK_${NAME}} )
message( STATUS "Framework ${NAME} found at ${FRAMEWORK_${NAME}}" )
endif()
endmacro( AddFramework )
38 changes: 38 additions & 0 deletions cmake/DebugUtils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
function( DumpVariables )
set( options MARK HCF )
set( oneValueArgs )
set( multiValueArgs VARS )
cmake_parse_arguments( DumpVariables "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )

get_cmake_property( _CMAKE_VARIABLES VARIABLES )
set( MARK ${DumpVariables_MARK} )
set( HCF ${DumpVariables_HCF} )
if( DumpVariables_VARS )
set( VARS "${DumpVariables_VARS}" )
else()
set( VARS ${_CMAKE_VARIABLES} )
endif()

if( MARK )
message( "" )
message( "#####################" )
message( "DumpVariables - BEGIN" )
endif()

foreach( _CMAKE_VARIABLE ${_CMAKE_VARIABLES} )
if( _CMAKE_VARIABLE IN_LIST VARS )
message( STATUS "${_CMAKE_VARIABLE}=${${_CMAKE_VARIABLE}}" )
endif()
endforeach( _CMAKE_VARIABLE )

if( MARK )
message( "DumpVariables - END" )
message( "#####################" )
message( "" )
endif()

if( HCF )
message( FATAL_ERROR "HCF - DumpVariables" )
endif()
endfunction( DumpVariables )

44 changes: 44 additions & 0 deletions cmake/iphoneos.toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
set( CMAKE_SYSTEM_NAME Darwin )
set( SDK iphoneos CACHE STRING "" )
set( CMAKE_OSX_ARCHITECTURES armv7 armv7s arm64 CACHE STRING "" )

execute_process( COMMAND xcrun --sdk ${SDK} --find clang
OUTPUT_VARIABLE CMAKE_C_COMPILER
OUTPUT_STRIP_TRAILING_WHITESPACE )
set( CMAKE_C_COMPILER ${CMAKE_C_COMPILER} CACHE PATH "clang executable" )

execute_process( COMMAND xcrun --sdk ${SDK} --find clang++
OUTPUT_VARIABLE CMAKE_CXX_COMPILER
OUTPUT_STRIP_TRAILING_WHITESPACE )
set( CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER} CACHE PATH "clang++ executable" )

execute_process( COMMAND xcrun --sdk ${SDK} --find swiftc
OUTPUT_VARIABLE CMAKE_Swift_COMPILER
OUTPUT_STRIP_TRAILING_WHITESPACE )
set( CMAKE_Swift_COMPILER ${CMAKE_Swift_COMPILER} CACHE PATH "swiftc executable" )

execute_process( COMMAND xcrun --sdk ${SDK} --find libtool
OUTPUT_VARIABLE CMAKE_LIBTOOL
OUTPUT_STRIP_TRAILING_WHITESPACE )
set( CMAKE_LIBTOOL ${CMAKE_LIBTOOL} CACHE PATH "libtool executable" )

execute_process( COMMAND xcrun --sdk ${SDK} --find strip
OUTPUT_VARIABLE CMAKE_STRIP
OUTPUT_STRIP_TRAILING_WHITESPACE )
set( CMAKE_STRIP ${CMAKE_STRIP} CACHE PATH "strip executable" )

execute_process( COMMAND xcrun --sdk ${SDK} --show-sdk-path
OUTPUT_VARIABLE CMAKE_OSX_SYSROOT
OUTPUT_STRIP_TRAILING_WHITESPACE )
set( CMAKE_OSX_SYSROOT ${CMAKE_OSX_SYSROOT} CACHE PATH "sysroot" )

set( CMAKE_CXX_COMPILER_WORKS TRUE )
set( CMAKE_C_COMPILER_WORKS TRUE )
set( CMAKE_Swift_COMPILER_WORKS TRUE )

set( CMAKE_FIND_FRAMEWORK FIRST )
set( CMAKE_SYSTEM_FRAMEWORK_PATH ${CMAKE_OSX_SYSROOT}/System/Library/Frameworks )

set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )