Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake: specifying build toolchain

Very new to CMake, and so far I'm finding it to be extremely helpful. I have a set of custom libraries that I would like to build for multiple platforms using cross-compilation. The toolchains are installed, and I can hand-create the Makefiles that I need to do so, but I would like to be able to make use of CMake.

Is there a way to tell cmake which toolchain to use, either at the command line or in the CMakeLists.txt file?

like image 535
Will Avatar asked Feb 23 '11 22:02

Will


People also ask

How do I specify architecture in CMake?

With the MSVC toolchain you can also use set(CMAKE_EXE_LINKER_FLAGS "/machine:x86") (sub in your architecture) in your cmake files. On Windows/MSVC, 64 and 32 bit are actually different compilers, unlike e.g gcc where architectue is a flag you'll pass to a compiler.

What is Cmake_toolchain_file?

It is the path to a file which is read early in the CMake run and which specifies locations for compilers and toolchain utilities, and other target platform and compiler related information.

What is CMake Sysroot?

The CMAKE_SYSROOT content is passed to the compiler in the --sysroot flag, if supported. The path is also stripped from the RPATH / RUNPATH if necessary on installation. The CMAKE_SYSROOT is also used to prefix paths searched by the find_* commands.


1 Answers

Have a look here: basically, you define a "toolchain file" that sets things like the system name, paths to compilers and so on. You then call cmake like so:

cmake /path/to/src -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain/foo-bar-baz.cmake 
like image 141
Jack Kelly Avatar answered Oct 02 '22 17:10

Jack Kelly