Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling for iOS with CMake

Tags:

I've compiled a C++ static library by using CMake as my building tool and I want to link it to my iOS app.
I created a simple 'Empty' application in Xcode and linked my library called libengine.a to it.
I tried to compile my iOS project and the linker gave me this warning:

ignoring file /Users/.../build/engine/libengine.a,  file was built for archive which is not the architecture being linked (i386): /Users/.../build/engine/libengine.a 

As I understand it, I need to compile my library for ARM processors. The problem is I don't know how.
I think CMake really lacks good tutorials.
Anyways, my CMake scripts are attached below.

Any help would be greatly appreciated.
Thanks, Tal.

Here is my main CMake script:

cmake_minimum_required(VERSION 2.8)  project(movie-night)  if (DEFINED PLATFORM)     include(toolchains/ios.cmake) endif()  add_definitions(-Wall)  set(DEBUG)  if (DEFINED DEBUG)     add_definitions(-g) endif()  if (DEFINED RELEASE)     add_definitions(-O3) endif()  add_subdirectory(engine) add_subdirectory(ui)  add_subdirectory(test) 

Here is my toolchains/ios.cmake file:

set(CMAKE_SYSTEM_NAME Darwin) set(CMAKE_SYSTEM_PROCESSOR arm) 
like image 617
Tal Zion Avatar asked Sep 27 '12 22:09

Tal Zion


2 Answers

Just use this toolchain file: http://code.google.com/p/ios-cmake/ and use it as

cmake -DCMAKE_TOOLCHAIN_FILE=path_to_your_toolchain_file 

Then, in CMakeLists.txt:

SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch armv7") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch armv7") 
like image 133
dreamzor Avatar answered Sep 28 '22 08:09

dreamzor


By following cmake-toolchains documentation I did like below:

cmake -G Xcode -B build \     -DCMAKE_SYSTEM_NAME=iOS \     -DCMAKE_Swift_COMPILER_FORCED=true \     -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 

Note: That assignment CMAKE_OSX_DEPLOYMENT_TARGET=11.0 is not a mistake when targeting iOS.

like image 33
Vlad Avatar answered Sep 28 '22 07:09

Vlad