Sylvain Beucler: Cross-compiling with CMake
I'm working on porting FreeGLUT for Android, and FreeGLUT is switching to CMake.
I'm more familiar with the GNU Autotools myself, and I'm used to cross-compile with a simple:
The principle is:
Now here's a slightly more complex toolchain for MinGW. The main issue with MinGW is that there are at least 4 possible prefixes depending on which version and which distro you're using. So I ask the user to specify it with
I used this technique to cross-compile my projects, or other projects that use CMake. mingw-cross-env uses this technique (abeilt with explicit definition of all compiler tools) to provide pre-built windows libraries without altering the existing CMake scripts. Do you people have tips or a better technique to cross-compile with CMake?
./configure --host=arm-linux-androideabi
Can we do that with CMake? Well, it's not well-documented, but yes :)
Let's see how to do that for Android (smartphones) and MinGW (.exe for windows).
The principle is:
- write a "toolchain" CMake script that defines the cross-compiler,
- mention you're using a "GNU" compiler (a.k.a. GCC) so CMake automatically looks for prefixed cross-compilers tools such as
arm-linux-androideabi-cpporarm-linux-androideabi-ld. - pass the toolchain script to CMake using the predefined
CMAKE_TOOLCHAIN_FILEvariable. - REMOVE all the CMake-generated files when you change anything, CMake does not rebuild its cache when the toolchain script or PATH is modified, this creates misleading errors. Hence, building in a subdirectory is crucial.
SET(CMAKE_SYSTEM_NAME Linux) # Tell CMake we're cross-compiling include(CMakeForceCompiler) # Prefix detection only works with compiler id "GNU" # CMake will look for prefixed g++, cpp, ld, etc. automatically CMAKE_FORCE_C_COMPILER(arm-linux-androideabi-gcc GNU) SET(ANDROID TRUE)Note:
SET(ANDROID TRUE) is not mandatory for CMake, it's just used to detect an Android build in the particular case of FreeGLUT development.
Here's how to invoke it:
PATH=/usr/src/ndk-standalone-9/bin:$PATH cd /usr/src/freeglut-3.0.0/ mkdir cross-android/ && cd cross-android/ cmake \ -D CMAKE_TOOLCHAIN_FILE=../android_toolchain.cmake \ -D CMAKE_INSTALL_PREFIX=/freeglut \ .. make -j4 make install DESTDIR=$(pwd)
Now here's a slightly more complex toolchain for MinGW. The main issue with MinGW is that there are at least 4 possible prefixes depending on which version and which distro you're using. So I ask the user to specify it with
GNU_HOST:
SET(CMAKE_SYSTEM_NAME Windows) include(CMakeForceCompiler) IF("$ GNU_HOST " STREQUAL "") SET(GNU_HOST i586-mingw32msvc) ENDIF() # Prefix detection only works with compiler id "GNU" CMAKE_FORCE_C_COMPILER($ GNU_HOST -gcc GNU) # CMake doesn't automatically look for prefixed 'windres', do it manually: SET(CMAKE_RC_COMPILER $ GNU_HOST -windres)I wanted to print an error when
GNU_HOST is not specified, but the toolchain script is loaded multiple times, and the command-line variables are not always set (CMake is not super-clean in that regard). So I defined a default, that works.
Sample invocation:
apt-get install mingw-w64 mkdir cross-woe/ && cd cross-woe/ cmake \ -D GNU_HOST=x86_64-w64-mingw32 \ -D CMAKE_TOOLCHAIN_FILE=../mingw_cross_toolchain.cmake \ -D CMAKE_INSTALL_PREFIX=/freeglut \ .. make -j4 make install DESTDIR=$(pwd)
I used this technique to cross-compile my projects, or other projects that use CMake. mingw-cross-env uses this technique (abeilt with explicit definition of all compiler tools) to provide pre-built windows libraries without altering the existing CMake scripts. Do you people have tips or a better technique to cross-compile with CMake?
For those of you were were in the various Debian infrastructure
channels, you might have noticed that I was playing around with
wanna-build, dak, sbuild, and buildd and friends.
[Thanks to everyone who answered questions, btw.] Over the past week,
I've been building most of
This follows up on a
This is my monthly summary of my Debian related activities. If you re among the people who
Dpkg and multiarch
The month started with a
Hello, this is just a quick post to announce some good news. Back in 2004 we ve formed a local Debian group in Peru. We were active and spread the word country-wide. There were good times. As time passed and interests changed things slowed down.
Past two weeks we are rebooting it. We ll be working with focus towards mentoring people to contribute upstream and Debian. We ll also host meetings for teaching new users in a more concrete problem solving or the basics . Finally, we will be glad to host Debian Developers, as we have done in the past with people that landed in Peru, and organize either social or technical meetings.
We ve set a
I'm seeking advice on budgeting.
Historically, I've been crap at managing money. Things have improved in recent
years. My main tool is
For some time, we use
I ve just started to use it. Next time I m able to show you how stable is Zenbook under Linux.
Right now it s not helpful:
The 13th Debian Conference is just around the corner.
Soile, my fiancee, has had a successful
Also this year the