3

I cross-compiled one project witch ccache:

cmake -G"Unix Makefiles" \
      -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_TOOLCHAIN_FILE=mips64el-toolchain.cmake

The following is mips64el-toolchain.cmake:

SET (CMAKE_SYSTEM_NAME Linux)
SET (CMAKE_SYSTEM_PROCESSOR mips64el)

SET (CMAKE_C_COMPILER ccache mips64el-n64-linux-gnu-gcc)
SET (CMAKE_CXX_COMPILER ccache mips64el-n64-linux-gnu-g++)

# here is the target environment located
SET (CMAKE_FIND_ROOT_PATH 
     $ENV{HOME}/x-tools/mips64el-n64-linux-gnu/mips64el-n64-linux-gnu/sysroot)

# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
# programs in the host environment
SET (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

But I found the incorrect values in CMakeCache.txt:

CMAKE_AR:FILEPATH=/usr/bin/ar
CMAKE_STRIP:FILEPATH=/usr/bin/strip

ar and strip are not the cross-compiler ones.

How to set them correctly?

A weeks ago, I found it was a bug of cmake and fixed in

  • Modules/CMakeDetermineCCompiler.cmake
  • Modules/CMakeDetermineCXXCompiler.cmake

For the details, please see also

https://launchpad.net/~likemartinma/+archive/devel

Like
  • 1,470
  • 15
  • 21
  • Could you please explain how exactly did you fix that in those files? A patch would be very helpful. Yocto Linux 2.0 (that we're using here) uses quite an old cmake, and I can't take the fixed one from your ppa. – Alexander Amelkin Jan 12 '17 at 16:44
  • Sorry, it is hard to explain. But you can get the patch from https://launchpad.net/~likemartinma/+archive/ubuntu/devel/+files/cmake_2.8.12-1~raring.debian.tar.gz – Like Jan 12 '17 at 16:58
  • Thanks. Anyway, my problem was that CMake didn't set CMAKE_CROSSCOMPILING in the first place. I had to invoke it as cmake -DCMAKE_SYSTEM_NAME=Linux in order to make it set the cross-compilation option. Then all my ${CMAKE_STRIP}s got the correct prefix. – Alexander Amelkin Jan 13 '17 at 10:05
  • You'd better use CMAKE_TOOLCHAIN_FILE instead. Please follow http://www.vtk.org/Wiki/CMake_Cross_Compiling – Like Jan 14 '17 at 11:02
  • Like, it doesn't look right to me. Especially after reading the article you linked. I don't know and don't want to know the exact path of the toolchain. It may differ. What I wanted is tell CMake I am indeed cross-compiling. And it somehow misses that fact if CMAKE_SYSTEM_NAME is not set. – Alexander Amelkin Jan 16 '17 at 08:47
  • The above links is the official standard solution. You can omit some variables just like CMAKE_C_COMPILER and CMAKE_CXX_COMPILER. – Like Jan 16 '17 at 09:57

1 Answers1

2

Try setting CMAKE_AR for setting ar and CMAKE_STRIP for strip in CMAKE_TOOLCHAIN_FILE.

I'm using CMAKE_AR in one of my projects to set proper ar as Platform was having multiple ar from different vendors.

bikram990
  • 1,085
  • 1
  • 14
  • 36
  • 1
    Thanks. I found the root cause several days ago. I think it is a bug of cmake which it does not handle ccache correctly. I fixed it in Modules/CMakeDetermineCCompiler.cmake and Modules/CMakeDetermineCXXCompiler.cmake. Please see also my Ubuntu ppa: https://launchpad.net/~likemartinma/+archive/devel – Like May 10 '13 at 17:25
  • How did you solved this? It should be searching these tools in `Modules/CMakeFindBinUtils.cmake` – bikram990 May 13 '13 at 05:16