6

I'm trying set-up my cross-compile build using CMake. So far I'm setting the cross compiler file calling CMake like this from the command line:

#Call cmake with the given options
cmake -D CMAKE_TOOLCHAIN_FILE=$cross_cmp_file \
      -D BUILD_TESTS:BOOLEAN=$build_test \
      ../src 

This works just fine.

Now I'm trying to set the CMAKE_TOOLCHAIN_FILE variable from the GUI by adding:

#CMAKE cross compiler file
set(CMAKE_TOOLCHAIN_FILE "Toolchain file" CACHE FILEPATH "../arm-crosscompile.cmake")

To my CMakeLists.txt.

This actually shows the variable in the GUI but when I press the "Configure" button, the c++ compiler that appear in the CMAKE_CXX_COMPILER variable is the one by default and not the one specified in the toolchain file.

How can I set the toolchain file from the Cmake-GUI?

El Marce
  • 3,144
  • 1
  • 26
  • 40

2 Answers2

18

Finally got it. Simple enough.

The first time you press the "Configure" button you will get to specify the generator parameters, select any generator for your project. Then select the option "Specify toolchain file for cross-compiling" and click next:

Specifying the toolchain file for cross compiling:

Click Next. In the following dialog, input the path to the cross-compilation file and you're done.

El Marce
  • 3,144
  • 1
  • 26
  • 40
  • 1
    Which one normally is "the cross-compilation file"? Can you give an example? Thanks. – Janos Oct 30 '18 at 10:32
  • 1
    The cross compilation file is a CMake script that specifies which compiler to use, among other configurations. You should obtain/create one for your specific platform. In the question you can see I'm using `arm-crosscompile.cmake` – El Marce Jan 15 '19 at 23:22
3

Do you set the variable before or after the call to project()?

The compiler detection happens inside that call so it has to be set before getting there.

Although I'm not sure you're able to change these settings after the first run.

Usually you'd set the toolchain the first time you run Cmake using the wizard style dialog.

Mario
  • 35,726
  • 5
  • 62
  • 78
  • thanks for your answer. I didn’t know there was a wizard style dialog. How do I install it and execute it in linux? Thanks again. – El Marce May 01 '15 at 06:58
  • @ElMarce actually I think that's part of the Windows version only. It does the first time you configure. – Mario May 01 '15 at 11:14
  • You can delete the cache which resets the configuration. – optional Apr 14 '17 at 09:40
  • 1
    @optional Of course, but that's essentially starting over. Rather than doing that you'd better use a second working/build directory. – Mario Apr 14 '17 at 18:13