[CMake] iOS multi-arch library target and xcodebuild

Parag Chandra parag at ionicsecurity.com
Wed Apr 1 13:43:25 EDT 2015


Hi Jason,

You need to cross-compile in order to target iOS, but if I¹m reading your
command line correctly, you are merely instructing CMake to generate an
Xcode build system for the host OS, which is naturally going to produce a
project that targets Mac OSX. The normal way to cross-compile with CMake
is to feed it a toolchain file, via the CMAKE_TOOLCHAIN_FILE cmd line
option. You may want to take a look at the following project to get an iOS
toolchain file from which to start:

https://code.google.com/p/ios-cmake/source/browse/toolchain/iOS.cmake


You can of course do something similar for Android:

https://github.com/taka-no-me/android-cmake/blob/master/android.toolchain.c
make


Parag Chandra
Senior Software Engineer, Mobile Team
Mobile: +1.919.824.1410

 <https://ionic.com>

Ionic Security Inc.
1170 Peachtree St. NE STE 400, Atlanta, GA 30309











On 4/1/15, 12:58 PM, "Jason Cooper" <cmake at lakedaemon.net> wrote:

>All,
>
>I'm in a situation I largely dislike.  :-)  Executing a project with two
>large
>unknowns.  The unknowns are cmake and xcode.
>
>I'm attempting to automate building the dylib's (and .so once I start on
>Android) for yajl:
>
>  https://github.com/lloyd/yajl.git
>
>My goal is to run a cron job that pulls the latest git repo, builds the
>project, runs tests, and makes the binary library available for the devs
>of the larger projects.  My inspiration is this openssl build script:
>
>  https://gist.github.com/foozmeat/5154962
>
>I've looked at the rather old example, Tests/iOSNavApp/ in the cmake
>repo. I've also read everything I could find with $SEARCH_ENGINE.  Using
>the attached patch, I can do the following in yajl:
>
>$ mkdir build.ios
>$ cd build.ios
>$ cmake -GXcode ..
>$ xcodebuild -target yajl-ios -configuration Debug
>
>The build is successful, but:
>
>$ file yajl-2.1.1/lib/Debug/libyajl.2.1.1.dylib
>yajl-2.1.1/lib/Debug/libyajl.2.1.1.dylib: Mach-O 64-bit dynamically
>linked shared library x86_64
>
>My goal is to have the multi-arch lib for armv7, arm64, and x86_64 (iOS
>and simulator).  Could anyone offer some insight into what I'm doing
>wrong?
>
>thx,
>
>Jason.
>
>FYI: this is based on a commit I haven't pushed upstream yet.  It
>changes the .gitignore to match /build* instead of /build/.
>
>-------------->8--------------------------------------
>diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
>index 99cf9e955258..340ffa800a98 100644
>--- a/src/CMakeLists.txt
>+++ b/src/CMakeLists.txt
>@@ -39,6 +39,31 @@ ADD_LIBRARY(yajl_s STATIC ${SRCS} ${HDRS} ${PUB_HDRS})
> 
> ADD_LIBRARY(yajl SHARED ${SRCS} ${HDRS} ${PUB_HDRS})
> 
>+ADD_CUSTOM_TARGET(yajl_s-ios DEPENDS yajl_s)
>+
>+ADD_CUSTOM_TARGET(yajl-ios DEPENDS yajl)
>+
>+set_target_properties(
>+	yajl-ios
>+	PROPERTIES
>+	XCODE_ATTRIBUTE_PRODUCT_NAME
>+	"libYaJL"
>+	XCODE_ATTRIBUTE_WRAPPER_EXTENSION
>+	"xctest"
>+	XCODE_ATTRIBUTE_BUNDLE_IDENTIFIER
>+	"com.github.lloyd.yajl"
>+)
>+set_target_properties(
>+	yajl-ios
>+	PROPERTIES
>+	XCODE_ATTRIBUTE_PRODUCT_NAME[variant=Debug]
>+	"libYaJL-Dbg"
>+	XCODE_ATTRIBUTE_WRAPPER_EXTENSION[variant=Debug]
>+	"xctest"
>+	XCODE_ATTRIBUTE_BUNDLE_IDENTIFIER[variant=Debug]
>+	"com.github.lloyd.yajl.debug"
>+)
>+
> #### setup shared library version number
> SET_TARGET_PROPERTIES(yajl PROPERTIES
>                       DEFINE_SYMBOL YAJL_SHARED
>@@ -50,6 +75,9 @@ IF(APPLE)
>   MESSAGE("INSTALL_NAME_DIR: ${CMAKE_INSTALL_PREFIX}/lib")
>   SET_TARGET_PROPERTIES(yajl PROPERTIES
>                         INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")
>+	set(CMAKE_OSX_SYSROOT iphoneos8.1)
>+	set(CMAKE_OSX_ARCHITECTURES "armv7;arm64;x86_64")
>+	set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos;-iphonesimulator")
> ENDIF(APPLE)
> 
> #### build up an sdk as a post build step
>-- 
>
>Powered by www.kitware.com
>
>Please keep messages on-topic and check the CMake FAQ at:
>http://www.cmake.org/Wiki/CMake_FAQ
>
>Kitware offers various services to support the CMake community. For more
>information on each offering, please visit:
>
>CMake Support: http://cmake.org/cmake/help/support.html
>CMake Consulting: http://cmake.org/cmake/help/consulting.html
>CMake Training Courses: http://cmake.org/cmake/help/training.html
>
>Visit other Kitware open-source projects at
>http://www.kitware.com/opensource/opensource.html
>
>Follow this link to subscribe/unsubscribe:
>http://public.kitware.com/mailman/listinfo/cmake



More information about the CMake mailing list