0

Background

My goal is to compile OpenCV for ios with support for the armv7s (the s is the hard part) architecture but have been unable to make any progress. My most recent theory is that the problem is that the cmake files that come with the library use gcc as a compiler which I do not think supports armv7s (if I am wrong please tell me). I am completely new to cmake however and have not been able to change the compiler.

The reason I suspect the compiler is because of the line

set (CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD_32_BIT)" CACHE string  "Build architecture for iOS")

which as far as I know should include armv7s. Changing that line to

set (CMAKE_OSX_ARCHITECTURES "armv6;armv7;armv7s;i386" CACHE string  "Build architecture for iOS")

had no effect.

I know there are explanations of how to set the compiler here, here, and here. My problem is that I am trying to change an existing cmake system and don't know what ramifications my changes could have. The code in question can be downloaded here. To build the framework I run the python script in OpenCV-2.4.2/ios

python build_framework.py ~/Desktop

from what I can tell the relevant cmake files are located in OpenCV-2.4.2/ios/cmake. There are only 3 and all are fairly short. My most recent attempt was to change two lines in the toolchains

CMAKE_FORCE_C_COMPILER (gcc gcc)
CMAKE_FORCE_CXX_COMPILER (g++ g++)

to

SET (DEVROOT    "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer")
SET (CC         "${DEVROOT}/usr/bin/llvm-gcc-4.2")
SET (CXX        "${DEVROOT}/usr/bin/llvm-g++-4.2")
CMAKE_FORCE_C_COMPILER          (${CC} CLang)
CMAKE_FORCE_CXX_COMPILER        (${CXX} CLang)

in an attempt to copy this SO question.

Question

  1. My first and most important question is if this is out of my depth. I have been assuming that changing the compiler/target architecture would be a simple flag set somewhere but I am becoming less convinced that is true. Also, there is an entire directory OpenCV-2.4.2/cmake filled with much larger cmake files that I have been avoiding in the hopes I don't need to worry about their contents. Is this a problem I am going to be able to solve in less than 10 hours?
  2. If you answered yes to the previous question, can you give me any direction? Suggested reading? Am I justified in ignoring the contents of OpenCV-2.4.2/cmake? I have been shooting in the dark for quite a while now without success.
  3. If it turns out this is as simple as I originally hoped, how do I do it?

Update

I never did figure out how to do this, but there is an xcode version of the library here from which the compiling settings can be changed easily.

Community
  • 1
  • 1
Hammer
  • 10,109
  • 1
  • 36
  • 52

2 Answers2

0

Set CMAKE_C_COMPILIER and CMAKE_CXX_COMPILIER to what you need.

Edit: this supposes you already had success with building this for armv7.
Edit2: this will just change the compiler.

dreamzor
  • 5,795
  • 4
  • 41
  • 61
  • I put set(CMAKE_C_COMPILIER "llvm-gcc-4.2") set(CMAKE_CXX_COMPILIER "llvm-g++-4.2") at the very beginning of what I think is the cmake entry point. It ran with no errors but had no effect on the General configuration for OpenCV 2.4.2 display. gcc and g++ are still the compilers – Hammer Sep 24 '12 at 20:10
  • Do you mean the toolchain file? – dreamzor Sep 24 '12 at 20:11
  • no i put it in iOS.cmake, should it be in the toolchain file? – Hammer Sep 24 '12 at 20:11
  • Well, i haven't seen your .toolchain and .cmake files, but i suppose so. At least, it's a common thing to do. – dreamzor Sep 24 '12 at 20:14
  • I put them in the toolchain files, no effect. If you want to see the files they can be downloaded from the posted link – Hammer Sep 24 '12 at 20:16
0

I see a lot of links in your question, but didn't find original link with information how to cross compile with CMake.

You should not change anything in existing build system.

In general you need to create toolchain file for your target architecture and run cmake with it.

cmake -DCMAKE_TOOLCHAIN_FILE=< your toolchain file > < path to CMakeLists.txt from opencv >

Sergei Nikulov
  • 5,029
  • 23
  • 36