-1

I writing toolchain.cmake file for Linaro toolchain.

include(CMakeForceCompiler)
set(CMAKE_CROSSCOMPILING   TRUE)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR "armv7-a")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wno-psabi -frtti -fexceptions" )
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -Wno-psabi -fexceptions" )
set(CMAKE_C_COMPILER /home/stranger/linaro/android-toolchain-eabi/bin/arm-linux-androideabi-gcc)
set(CMAKE_CXX_COMPILER /home/stranger/linaro/android-toolchain-eabi/bin/arm-linux-androideabi-g++)
CMAKE_FORCE_C_COMPILER("${CMAKE_C_COMPILER}" GNU)
CMAKE_FORCE_CXX_COMPILER("${CMAKE_CXX_COMPILER}" GNU)
set(CMAKE_FIND_ROOT_PATH  home/stranger/linaro/android-toolchain-eabi/arm-linux-androideabi)
include_directories( SYSTEM /home/stranger/android-ndk-r8/platforms/android-14/arch-arm/usr/include)
include_directories( SYSTEM /home/stranger/android-ndk-r8/sources/cxx-stl/gnu-libstdc++/include)
include_directories( SYSTEM /home/stranger/android-ndk-r8/sources/cxx-stl/gnu-libstdc++/libs/armeabi-v7a/include)

I run cmake:

cmake -DBUILD_ANDROID=On -DCMAKE_TOOLCHAIN_FILE=<path to this toolchain.cmake>  -DCMAKE_BUILD_TYPE=Release <path to my cmake project>

But at compile time, i had error about exceptions, instead of defined compiler flags in toolchain file:

error: exception handling disabled, use -fexceptions to enable

As far as I can understand my CMAKE_C_FLAGS_RELEASE, CMAKE_CXX_FLAGS_RELEASE has no effect. Why?

exbluesbreaker
  • 2,160
  • 3
  • 18
  • 30
  • Welcome to Stack Overflow! If you have found the answer to your own question, you can answer it yourself and mark it as accepted so that others can know this question is resolved – Yi Jiang Jun 16 '12 at 16:33
  • Thanks! But there is 6 hours limit for your own answer. – exbluesbreaker Jun 16 '12 at 16:44
  • Don't set [`CMAKE_CROSSCOMPILING`](https://cmake.org/cmake/help/v3.0/variable/CMAKE_CROSSCOMPILING.html#variable:CMAKE_CROSSCOMPILING). It is set by CMake. See referenced doc. – kyb Apr 08 '17 at 17:20

1 Answers1

2

Problem solved, my mistake. I use set(CMAKE_CXX_FLAGS "<flags>") against set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}<flags>" in main project. I was confused, because this CMakeLists.txt works correctly for android-cmake and Google-NDK (instead of all android-cmake toolchain flags was rejected).

exbluesbreaker
  • 2,160
  • 3
  • 18
  • 30