Skip to content

Commit

Permalink
generate iOS framework in cmake (#722)
Browse files Browse the repository at this point in the history
* import ye ole’ Info.plist from polly framework scripts

https://github.com/ruslo/polly/blob/master/scripts/Info.plist

* add DRISHTI_TOP_DIR reference

* import framework boilerplate https://cmake.org/cmake/help/latest/prop_tgt/FRAMEWORK.html#framework

* framework fixes

* adapt Info.plist to Info.plist.in template and add configure_file() step to populate required variables
* disable code signing to avoid issues with install stage of framework, since it isn’t needed and the install step modifications invalidate the build tree code signing
* add config_file() step to generate fields in the Info.plist
* set “@rpath”  in target properties since the normal shared lib hooks don’t work for frameworks
* fixup drishti_include_install_dir path in framework case since PUBLIC_HEADERS doesn’t include everything
* add FRAMEWORK section to install targets

* bump patch version for cmake updates 0.12.5

* define DRISHTI_SDK_MAX_FACES

* Set FRAMEWORK DESTINATION to "."

See "On systems supporting OS X Frameworks and Application Bundles...":
* https://cmake.org/cmake/help/latest/command/find_package.html

See also:
* https://github.com/forexample/ios-dynamic-framework/blob/bde7e3f14d5dbaabf7846f29508f6a5cd955d3a3/bar/CMakeLists.txt#L127

* Remove trailing whitespaces

* iOS framework: Do not install headers explicitly

Headers are part of the iOS framework already,
there is no need to install them explicitly

* iOS: Improve INSTALL_NAME_DIR

https://github.com/forexample/ios-dynamic-framework/blob/bde7e3f14d5dbaabf7846f29508f6a5cd955d3a3/bar/CMakeLists.txt#L45-L46

* Remove trailing whitespaces

* FACEFILTER_CODE_SIGN -> DRISHTI_CODE_SIGN

* iOS: Load dynamic framework into FaceFilter app

* Update submodule

* Support iOS framework in example

* bin/jenkins.sh: Set CMAKE_CONFIGURATION_TYPES
  • Loading branch information
headupinclouds authored Sep 1, 2018
1 parent 3930201 commit ee86763
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 69 deletions.
19 changes: 18 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules")
### Drishti project ###
#######################

project(drishtisdk VERSION 0.12.4)
project(drishtisdk VERSION 0.12.5)

set(DRISHTI_TOP_DIR "${CMAKE_CURRENT_LIST_DIR}")

#################
### Languages ###
Expand Down Expand Up @@ -66,6 +68,7 @@ if(DRISHTI_BUILD_MERGED_SDK)
endif()

option(DRISHTI_BUILD_ACF "Drishti ACF lib" ON)
option(DRISHTI_CODE_SIGN "iOS code signing" ON)

message("CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")

Expand Down Expand Up @@ -350,6 +353,20 @@ try_compile(
### Includes (to be deprecated ###
##################################

if(IOS AND DRISHTI_BUILD_SHARED_SDK)
list(LENGTH CMAKE_CONFIGURATION_TYPES len)
if(NOT len EQUAL "1")
message(FATAL_ERROR "Not supported")
endif()

set(
DRISHTI_FRAMEWORK_LOCATION
"${CMAKE_CURRENT_BINARY_DIR}/src/lib/drishti/${CMAKE_CONFIGURATION_TYPES}-iphoneos/drishti.framework"
)
else()
set(DRISHTI_FRAMEWORK_LOCATION "")
endif()

add_subdirectory(src)

#################################
Expand Down
3 changes: 2 additions & 1 deletion bin/jenkins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,10 @@ case "${TYPE}" in
GAUZE_ANDROID_USE_EMULATOR=${GAUZE_ANDROID_USE_EMULATOR} \
GAUZE_ANDROID_EMULATOR_GPU=${GAUZE_ANDROID_EMULATOR_GPU} \
GAUZE_ANDROID_EMULATOR_PARTITION_SIZE=40 \
CMAKE_CONFIGURATION_TYPES="${CONFIG}" \
HUNTER_CONFIGURATION_TYPES="${CONFIG}" \
HUNTER_SUPPRESS_LIST_OF_FILES=ON \
FACEFILTER_CODE_SIGN=OFF
DRISHTI_CODE_SIGN=OFF

;;
"android-studio")
Expand Down
22 changes: 22 additions & 0 deletions cmake/Modules/templates/Info.plist.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>@CF_BUNDLE_SHORT_VERSION_STRING@</string>
<key>CFBundleVersion</key>
<string>@CF_BUNDLE_VERSION@</string>
<key>CFBundleName</key>
<string>@CF_BUNDLE_NAME@</string>
<key>CFBundleIdentifier</key>
<string>@CF_BUNDLE_IDENTIFIER@</string>
</dict>
</plist>
15 changes: 14 additions & 1 deletion src/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,20 @@ find_package(spdlog CONFIG REQUIRED)
if(NOT TARGET drishti::drishti)
# add the drishti package, possibly using GIT_SELF feature
hunter_add_package(drishti)
find_package(drishti CONFIG REQUIRED)

if(IOS AND DRISHTI_BUILD_SHARED_SDK)
set(DRISHTI_FRAMEWORK_LOCATION "${DRISHTI_ROOT}/drishti.framework")
add_library(drishti::drishti INTERFACE IMPORTED)
set_target_properties(
drishti::drishti
PROPERTIES
INTERFACE_COMPILE_OPTIONS "-F${DRISHTI_ROOT}"
INTERFACE_LINK_LIBRARIES "-F${DRISHTI_ROOT} -framework drishti"
)
else()
find_package(drishti CONFIG REQUIRED)
set(DRISHTI_FRAMEWORK_LOCATION "")
endif()
endif()

set(base_deps drishti::drishti cxxopts::cxxopts ${OpenCV_LIBS} spdlog::spdlog)
Expand Down
2 changes: 1 addition & 1 deletion src/examples/drishti-upload
Submodule drishti-upload updated 1 files
+5 −1 config.cmake
2 changes: 0 additions & 2 deletions src/examples/facefilter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
option(FACEFILTER_CODE_SIGN "iOS code signing" ON)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

hunter_add_package(sugar)
Expand Down
28 changes: 19 additions & 9 deletions src/examples/facefilter/app/facefilter/ios/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,19 @@ foreach(resource ${drishti_assets})
list(APPEND FACEFILTER_RESOURCES ${${resource}})
endforeach()

if(IOS AND DRISHTI_BUILD_SHARED_SDK)
set_source_files_properties(
"${DRISHTI_FRAMEWORK_LOCATION}"
PROPERTIES
GENERATED YES
MACOSX_PACKAGE_LOCATION Frameworks
)
endif()

add_executable(FaceFilter
${FACEFILTER_SWIFT_SRCS}
FaceFilter-Bridging-Header.h
FaceFilter-Bridging-Header.h
${DRISHTI_FRAMEWORK_LOCATION}

# Resources
${FACEFILTER_RESOURCES}
Expand All @@ -29,10 +39,10 @@ add_executable(FaceFilter
set(CMAKE_MACOSX_RPATH 1)
# when building, don't use the install RPATH already
# (but later on when installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)

set_target_properties(
FaceFilter
Expand All @@ -44,22 +54,22 @@ set_target_properties(
XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES

# By default this setting is empty => archives not showing up in Xcode organizer.
# http://stackoverflow.com/a/8102602/2288008y
# http://stackoverflow.com/a/8102602/2288008y
XCODE_ATTRIBUTE_INSTALL_PATH "${CMAKE_BINARY_DIR}/ProductRelease"

# If this setting is "YES" application can't pass archive validation.
# http://stackoverflow.com/a/24040412/2288008
XCODE_ATTRIBUTE_COMBINE_HIDPI_IMAGES "NO"
XCODE_ATTRIBUTE_COMBINE_HIDPI_IMAGES "NO"
RESOURCE "${FACEFILTER_RESOURCES}"
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.elucideye.facefilter"

# dyld: Library not loaded: @rpath/libswiftAVFoundation.dylib
# Unable to load Swift runtime library (image not found): https://stackoverflow.com/a/24972407a
# Unable to load Swift runtime library (image not found): https://stackoverflow.com/a/24972407a
XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "@executable_path/../Frameworks\n@loader_path/Frameworks"
INSTALL_RPATH "@executable_path/../Frameworks\n@loader_path/Frameworks"

XCODE_ATTRIBUTE_SWIFT_OBJC_BRIDGING_HEADER "${CMAKE_CURRENT_LIST_DIR}/FaceFilter-Bridging-Header.h"

XCODE_ATTRIBUTE_PRODUCT_NAME "FaceFilter"
XCODE_ATTRIBUTE_BUNDLE_IDENTIFIER "com.elucideye.facefilter"
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.elucideye.facefilter"
Expand All @@ -82,15 +92,15 @@ if(DRISHTI_OPENGL_ES3)
)
endif()

if(FACEFILTER_CODE_SIGN)
if(DRISHTI_CODE_SIGN)
set_target_properties(
FaceFilter
PROPERTIES
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer"
)
endif()

target_link_libraries(FaceFilter PUBLIC
target_link_libraries(FaceFilter PUBLIC
facefilter_renderer
facefilter_bindings
"-framework CoreMedia"
Expand Down
Loading

0 comments on commit ee86763

Please sign in to comment.