ITK/Cross Compiling: Difference between revisions

From KitwarePublic
< ITK
Jump to navigationJump to search
No edit summary
Line 164: Line 164:
# Build your tool chain in the build system
# Build your tool chain in the build system
#* This is the set of compiler and linker that must be build in the '''build''' system, but will know how to generate code for the Target system.
#* This is the set of compiler and linker that must be build in the '''build''' system, but will know how to generate code for the Target system.
#* In this case we use MinGW as the tool chain
#* In this case we use crosstool-ng to build the tool chain
# Create a TryRun ... file in the '''native''' system
# Create a TryRun ... file in the '''native''' system
#* This could be generated (as a skeleton) with the following commands
#* This could be generated (as a skeleton) with the following commands


=== Building the ToolChain for Windows ===
=== Building the ToolChain for ARM ===


The following is a script developed by Johannes Schindelin (originally intended for [http://pacific.mpi-cbg.de/wiki/index.php/Fiji FIJI])
The process is described in detail here: http://www.kitware.com/blog/home/post/426
 
based on the instructions from: http://www.bootc.net/archives/2012/05/26/how-to-build-a-cross-compiler-for-your-raspberry-pi/
[[Media:Build-windows-cross-compiler.sh.gz‎|Script for Building the Windows (MinGW) Toolchain in Linux]]


=== Gathering Configuration settings in the target system ===
=== Gathering Configuration settings in the target system ===
Line 185: Line 184:
   SET(CMAKE_SYSTEM_VERSION 1)
   SET(CMAKE_SYSTEM_VERSION 1)
   # specify the cross compiler
   # specify the cross compiler
   SET(CMAKE_C_COMPILER  /usr/bin/gcc)
   SET(CMAKE_C_COMPILER
   SET(CMAKE_CXX_COMPILER /usr/bin/g++)
   /home/ibanez/local/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-gcc)
   SET(CMAKE_CXX_COMPILER
  /home/ibanez/local/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-g++)
   # where is the target environment
   # where is the target environment
   SET(CMAKE_FIND_ROOT_PATH /usr)
   SET(CMAKE_FIND_ROOT_PATH
  /home/ibanez/local/x-tools/arm-unknown-linux-gnueabi)
   # search for programs in the build host directories
   # search for programs in the build host directories
   SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
   SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
Line 194: Line 196:
   SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
   SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
   SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
   SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)


and run it with CMake using the command (in an empty directory)
and run it with CMake using the command (in an empty directory)
Line 199: Line 202:
   cmake -DCMAKE_TOOLCHAIN_FILE=./ToolChain.cmake  ~/src/ITK
   cmake -DCMAKE_TOOLCHAIN_FILE=./ToolChain.cmake  ~/src/ITK


This will generate (among many other things) a File called  
This will generate (among many other things) a File called


               TryRunResults.cmake
               TryRunResults.cmake
Line 205: Line 208:
Then, manually populate, the values of each one of the fields.
Then, manually populate, the values of each one of the fields.


The values to be put in this file can be taken from the CMakeCache.txt file of a native build in Windows.
The values to be put in this file can be taken from the CMakeCache.txt file of a native build in the Raspberry Pi.
 


Finally, copy this file to the build system.


=== Using the Configuration in the Host ===
=== Using the Configuration in the Host ===
Line 216: Line 217:
Do the command in the build system.
Do the command in the build system.


     cmake -C ~/TryRunResults.cmake   ~/src/ITK
     cmake -C ~/TryRunResults.cmake -DCMAKE_TOOLCHAIN_FILE=./ToolChain.cmake  ~/src/ITK


once the configuration is completed you can proceed to build ITK by simply typing
once the configuration is completed you can proceed to build ITK by simply typing


     make
     make

Revision as of 21:32, 27 December 2012

This page describes the procedure to follow when cross compiling ITK for another system.

In this page, we will refer to the system as:

  • Target System: The system where the executables are intended to run.
  • Build System: The system where the executables are built.

In Linux Host for Mac Target

In this particular case we illustrate

  • Target System = Mac
  • Build System = Linux

Major steps

  1. Build your tool chain in the build system
    • This is the set of compiler and linker that must be build in the build system, but will know how to generate code for the Target system.
  2. Create a TryRun ... file in the native system
    • This could be generated (as a skeleton) with the following commands

Building the ToolChain for Darwin

The following is a script developed by Johannes Schindelin (originally intended for FIJI)

Script for Building the Darwing Toolchain in Linux

Gathering Configuration settings in the target system

Following the advice of the CMake Wiki [1]

Put the following in a file called ToolChain.cmake

 # this one is important
 SET(CMAKE_SYSTEM_NAME Linux)
 #this one not so much
 SET(CMAKE_SYSTEM_VERSION 1)
 # specify the cross compiler
 SET(CMAKE_C_COMPILER   /usr/bin/gcc)
 SET(CMAKE_CXX_COMPILER /usr/bin/g++)
 # where is the target environment
 SET(CMAKE_FIND_ROOT_PATH  /usr)
 # search for programs in the build host directories
 SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
 # for libraries and headers in the target directories
 SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
 SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

and run it with CMake using the command (in an empty directory)

 cmake -DCMAKE_TOOLCHAIN_FILE=./ToolChain.cmake   ~/src/ITK

This will generate (among many other things) a File called

              TryRunResults.cmake

Then, manually populate, the values of each one of the fields.

The values to be put in this file can be taken from the CMakeCache.txt file of a native build in Darwin.


Finally, copy this file to the build system.

Using the Configuration in the Host

Now that you have copied the TryRunResuls.cmake file to the host system, you can use it as an initial cache for configuring the build.

Do the command in the build system.

   cmake -C ~/TryRunResults.cmake   ~/src/ITK

once the configuration is completed you can proceed to build ITK by simply typing

   make

The full process scripted

The process as a whole has been scripted in the file below

Script for configuring a cross-compilation build

Thanks to Johannes Schindelin for contributing the script.

In Linux Host for Windows Target

In this particular case we illustrate

  • Target System = Windows
  • Build System = Linux

Major steps

  1. Build your tool chain in the build system
    • This is the set of compiler and linker that must be build in the build system, but will know how to generate code for the Target system.
    • In this case we use MinGW as the tool chain
  2. Create a TryRun ... file in the native system
    • This could be generated (as a skeleton) with the following commands

Building the ToolChain for Windows

The following is a script developed by Johannes Schindelin (originally intended for FIJI)

Script for Building the Windows (MinGW) Toolchain in Linux

Gathering Configuration settings in the target system

Following the advice of the CMake Wiki [2]

Put the following in a file called ToolChain.cmake

 # this one is important
 SET(CMAKE_SYSTEM_NAME Linux)
 #this one not so much
 SET(CMAKE_SYSTEM_VERSION 1)
 # specify the cross compiler
 SET(CMAKE_C_COMPILER   /usr/bin/gcc)
 SET(CMAKE_CXX_COMPILER /usr/bin/g++)
 # where is the target environment
 SET(CMAKE_FIND_ROOT_PATH  /usr)
 # search for programs in the build host directories
 SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
 # for libraries and headers in the target directories
 SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
 SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

and run it with CMake using the command (in an empty directory)

 cmake -DCMAKE_TOOLCHAIN_FILE=./ToolChain.cmake   ~/src/ITK

This will generate (among many other things) a File called

              TryRunResults.cmake

Then, manually populate, the values of each one of the fields.

The values to be put in this file can be taken from the CMakeCache.txt file of a native build in Windows.


Finally, copy this file to the build system.

Using the Configuration in the Host

Now that you have copied the TryRunResuls.cmake file to the host system, you can use it as an initial cache for configuring the build.

Do the command in the build system.

   cmake -C ~/TryRunResults.cmake   ~/src/ITK

once the configuration is completed you can proceed to build ITK by simply typing

   make

In Linux Host for ARM Target

In this particular case we illustrate

  • Target System = Raspberry Pi (ARMv6)
  • Build System = Linux (Ubuntu 12.10)

Major steps

  1. Build your tool chain in the build system
    • This is the set of compiler and linker that must be build in the build system, but will know how to generate code for the Target system.
    • In this case we use crosstool-ng to build the tool chain
  2. Create a TryRun ... file in the native system
    • This could be generated (as a skeleton) with the following commands

Building the ToolChain for ARM

The process is described in detail here: http://www.kitware.com/blog/home/post/426 based on the instructions from: http://www.bootc.net/archives/2012/05/26/how-to-build-a-cross-compiler-for-your-raspberry-pi/

Gathering Configuration settings in the target system

Following the advice of the CMake Wiki [3]

Put the following in a file called ToolChain.cmake

 # this one is important
 SET(CMAKE_SYSTEM_NAME Linux)
 #this one not so much
 SET(CMAKE_SYSTEM_VERSION 1)
 # specify the cross compiler
 SET(CMAKE_C_COMPILER
 /home/ibanez/local/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-gcc)
 SET(CMAKE_CXX_COMPILER
 /home/ibanez/local/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-g++)
 # where is the target environment
 SET(CMAKE_FIND_ROOT_PATH
 /home/ibanez/local/x-tools/arm-unknown-linux-gnueabi)
 # search for programs in the build host directories
 SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
 # for libraries and headers in the target directories
 SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
 SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)


and run it with CMake using the command (in an empty directory)

 cmake -DCMAKE_TOOLCHAIN_FILE=./ToolChain.cmake   ~/src/ITK

This will generate (among many other things) a File called

              TryRunResults.cmake

Then, manually populate, the values of each one of the fields.

The values to be put in this file can be taken from the CMakeCache.txt file of a native build in the Raspberry Pi.


Using the Configuration in the Host

Now that you have copied the TryRunResuls.cmake file to the host system, you can use it as an initial cache for configuring the build.

Do the command in the build system.

   cmake -C ~/TryRunResults.cmake -DCMAKE_TOOLCHAIN_FILE=./ToolChain.cmake  ~/src/ITK

once the configuration is completed you can proceed to build ITK by simply typing

   make