Xcode: Add support for combined install on iOS

This patch solves the problem of installing both: Device and Simulator
libraries on iOS. Before only one of them was installed.

If the IOS_INSTALL_COMBINED property is set on a target, a
special install hook will be activated which builds the corresponding
target and combines both at the install location.

The original patch was contributed by Ruslan Baratov, and polished by
Gregor Jasny.
This commit is contained in:
Ruslan Baratov
2015-10-08 03:09:34 +03:00
committed by Gregor Jasny
parent 34f5ef564a
commit 565d080a9a
16 changed files with 532 additions and 0 deletions
@@ -94,3 +94,39 @@ if(NOT XCODE_VERSION VERSION_LESS 7)
run_cmake(XcodeTbdStub)
unset(RunCMake_TEST_OPTIONS)
endif()
if(NOT XCODE_VERSION VERSION_LESS 6)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/XcodeIOSInstallCombined-build)
set(RunCMake_TEST_NO_CLEAN 1)
set(RunCMake_TEST_OPTIONS
"-DCMAKE_INSTALL_PREFIX:PATH=${RunCMake_TEST_BINARY_DIR}/_install"
"-DCMAKE_IOS_INSTALL_COMBINED=YES")
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
run_cmake(XcodeIOSInstallCombined)
run_cmake_command(XcodeIOSInstallCombined-build ${CMAKE_COMMAND} --build .)
run_cmake_command(XcodeIOSInstallCombined-install ${CMAKE_COMMAND} --build . --target install)
unset(RunCMake_TEST_BINARY_DIR)
unset(RunCMake_TEST_NO_CLEAN)
unset(RunCMake_TEST_OPTIONS)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/XcodeIOSInstallCombinedPrune-build)
set(RunCMake_TEST_NO_CLEAN 1)
set(RunCMake_TEST_OPTIONS
"-DCMAKE_INSTALL_PREFIX:PATH=${RunCMake_TEST_BINARY_DIR}/_install"
"-DCMAKE_IOS_INSTALL_COMBINED=YES")
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
run_cmake(XcodeIOSInstallCombinedPrune)
run_cmake_command(XcodeIOSInstallCombinedPrune-build ${CMAKE_COMMAND} --build .)
run_cmake_command(XcodeIOSInstallCombinedPrune-install ${CMAKE_COMMAND} --build . --target install)
unset(RunCMake_TEST_BINARY_DIR)
unset(RunCMake_TEST_NO_CLEAN)
unset(RunCMake_TEST_OPTIONS)
endif()
@@ -0,0 +1,30 @@
function(verify_architectures file)
execute_process(
COMMAND xcrun otool -vf ${RunCMake_TEST_BINARY_DIR}/_install/${file}
OUTPUT_VARIABLE otool_out
ERROR_VARIABLE otool_err
RESULT_VARIABLE otool_result)
if(NOT otool_result EQUAL "0")
message(SEND_ERROR "Could not retrieve fat headers: ${otool_err}")
return()
endif()
string(REGEX MATCHALL "architecture [^ \n\t]+" architectures ${otool_out})
string(REPLACE "architecture " "" actual "${architectures}")
list(SORT actual)
set(expected arm64 armv7 i386 x86_64)
if(NOT actual STREQUAL expected)
message(SEND_ERROR
"The actual library contains the architectures:\n ${actual} \n"
"which do not match expected ones:\n ${expected} \n"
"otool output:\n${otool_out}")
endif()
endfunction()
verify_architectures(bin/foo_app.app/foo_app)
verify_architectures(lib/libfoo_static.a)
verify_architectures(lib/libfoo_shared.dylib)
verify_architectures(lib/foo_bundle.bundle/foo_bundle)
verify_architectures(lib/foo_framework.framework/foo_framework)
@@ -0,0 +1,27 @@
cmake_minimum_required(VERSION 3.3)
project(IOSInstallCombined CXX)
set(CMAKE_OSX_SYSROOT iphoneos)
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
set(CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT "dwarf")
set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "NO")
set(CMAKE_OSX_ARCHITECTURES "armv7;arm64;i386;x86_64")
add_executable(foo_app MACOSX_BUNDLE main.cpp)
install(TARGETS foo_app BUNDLE DESTINATION bin)
add_library(foo_static STATIC foo.cpp)
install(TARGETS foo_static ARCHIVE DESTINATION lib)
add_library(foo_shared SHARED foo.cpp)
install(TARGETS foo_shared LIBRARY DESTINATION lib)
add_library(foo_bundle MODULE foo.cpp)
set_target_properties(foo_bundle PROPERTIES BUNDLE TRUE)
install(TARGETS foo_bundle LIBRARY DESTINATION lib)
add_library(foo_framework SHARED foo.cpp)
set_target_properties(foo_framework PROPERTIES FRAMEWORK TRUE)
install(TARGETS foo_framework FRAMEWORK DESTINATION lib)
@@ -0,0 +1,26 @@
function(verify_architectures file)
execute_process(
COMMAND xcrun otool -vf ${RunCMake_TEST_BINARY_DIR}/_install/${file}
OUTPUT_VARIABLE otool_out
ERROR_VARIABLE otool_err
RESULT_VARIABLE otool_result)
if(NOT otool_result EQUAL "0")
message(SEND_ERROR "Could not retrieve fat headers: ${otool_err}")
return()
endif()
string(REGEX MATCHALL "architecture [^ \n\t]+" architectures ${otool_out})
string(REPLACE "architecture " "" actual "${architectures}")
list(SORT actual)
set(expected armv7 x86_64)
if(NOT actual STREQUAL expected)
message(SEND_ERROR
"The actual library contains the architectures:\n ${actual} \n"
"which do not match expected ones:\n ${expected} \n"
"otool output:\n${otool_out}")
endif()
endfunction()
verify_architectures(lib/libfoo.dylib)
@@ -0,0 +1,2 @@
.*Unexpected architecture `i386` detected.*
.*Unexpected architecture `arm64` detected.*
@@ -0,0 +1,36 @@
cmake_minimum_required(VERSION 3.3)
project(XcodeIOSInstallCombinedPrune CXX)
set(CMAKE_OSX_SYSROOT iphoneos)
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
set(CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT "dwarf")
add_library(foo SHARED foo.cpp)
install(TARGETS foo DESTINATION lib)
add_library(baz SHARED foo.cpp)
set_target_properties(
foo baz
PROPERTIES
XCODE_ATTRIBUTE_ARCHS[sdk=iphoneos*] armv7
XCODE_ATTRIBUTE_VALID_ARCHS[sdk=iphoneos*] armv7
XCODE_ATTRIBUTE_ARCHS[sdk=iphonesimulator*] x86_64
XCODE_ATTRIBUTE_VALID_ARCHS[sdk=iphonesimulator*] x86_64
)
add_library(boo SHARED foo.cpp)
set_target_properties(
boo
PROPERTIES
XCODE_ATTRIBUTE_ARCHS[sdk=iphoneos*] arm64
XCODE_ATTRIBUTE_VALID_ARCHS[sdk=iphoneos*] arm64
XCODE_ATTRIBUTE_ARCHS[sdk=iphonesimulator*] i386
XCODE_ATTRIBUTE_VALID_ARCHS[sdk=iphonesimulator*] i386
)
add_custom_command(
TARGET foo
POST_BUILD
COMMAND lipo -create $<TARGET_FILE:baz> $<TARGET_FILE:boo> -output $<TARGET_FILE:foo>
)
+3
View File
@@ -0,0 +1,3 @@
int main(int argc, const char * argv[]) {
return 0;
}