[CMake] iOS multi-arch library target and xcodebuild

Jason Cooper cmake at lakedaemon.net
Wed Apr 1 12:58:23 EDT 2015


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


More information about the CMake mailing list