Using CMake + Mingw to Cross-Compile Windows Apps.

Posted in Linux Development on November 23rd, 2009 by OneOfOne

As promised, here’s the second part of the tutorial on how to use cmake to build Qt4/OpenSSL Apps for Windows using mingw on Linux.

Assumptions :

1. You already followed the tutorial on how to setup Qt4/OpenSSL using mingw.
2. You have cmake installed.
3. You have a working wine setup or a way to test the executables.

Part 0 : Setup Wine

You can ignore this if you will test on windows.

  1. Run winecfg, go to Drives, add drive and set the path to your win32 dev (we will use the letter G for this).
  2. Run wine regedit, go to HKEY_LOCAL_MACHINE -> System -> Session Manager -> Enviroment -> edit PATH and append G:\qt-win-opensource-src-4.5.3\;G:\openssl-0.9.8l to the end.

Part 1 : Custom CMake Rules

We need to create a custom cmake rules file, we will name it lin-mingw.cmake for now :

if(WIN32)
	#We haven't built Qt with debug support, so no point setting debug flags.
	set(CMAKE_BUILD_TYPE "Release")
	ADD_DEFINITIONS(${QT_DEFINITIONS})
	SET_PROPERTY(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE QT_NO_DEBUG)

	#set the default pathes, should be changed to match your setup.
	set(WIN32_BASE /home/dev/win32/)
	set(QT_BASE ${WIN32_BASE}/qt-win-opensource-src-4.5.3)
	set(OSSL_BASE ${WIN32_BASE}/openssl-0.9.8l)
	set(APP_ICON_RC ${CMAKE_CURRENT_SOURCE_DIR}/win32_icon.rc)

	set(MINGW_PREFIX "i686-pc-mingw32-")

	# set "sane" default cxxflags for windows, the -mwindows so it wouldn't open a command dos window.
	set(CMAKE_CXX_FLAGS_RELEASE  "${CMAKE_CXX_FLAGS_RELEASE} -march=pentium4 -mtune=pentium4 -mwindows -O2")
	# we need -static-libgcc otherwise we'll link against libgcc_s_sjlj-1.dll.
	SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "-Wl,--no-undefined -static-libgcc -Wl,-O1 -Wl,--as-needed -Wl,--sort-common -s")

.............. etc etc ............

Download the file.
Read more »

Tags: , , , , , , , ,

Mingw + OpenSSL + Qt4 for Windows on Linux

Posted in Linux Development on November 17th, 2009 by OneOfOne

This is slightly outdated, will upload a new version with OpenSSL v1.0.0, also fixed the link to the mingw-openssl.sh script.
For the longest time I used Mingw + cmake on top of wine to cross compile my Qt4 apps for windows, then I was bored one day, tired of how slow it is to recompile qt4 on wine and decided to try to get it to work with a native gcc instead of the overhead with wine.
So here goes.

This was done on Gentoo Linux, please don’t ask me how to do it on other distros.

Assumptions :

1. You know your way around the linux shell and have portage privileges.
2. You’re not scared from compiling things by hand.
3. You already have Qt4 installed and it is the same version as the windows source we gonna build.
4. Your working path will be ~/win32.
5. You have a working wine setup.

Part 1 – Meet the Toolchain :

# Change 32 to 64 if you're trying to build for Win64, of course you'd need a 64bit Linux toolchain as well.
export cross=i686-pc-mingw32
emerge -av crossdev
# I decided to use the latest gcc version, however there's nothing stopping you from using 3.x.
# Start building the tool chain, go make some coffee, watch tv, or play a game until it's done.
crossdev --gcc 4.4.2 ${cross}
# Fix a bug in Qt4's corelib, also make sure to change 4.4.2 to whichever version of gcc you decided to use.
ln -s /usr/${cross}/usr/include/float.h /usr/lib/gcc/${cross}/4.4.2/include/g++-v4

*Important* due to the way the gentoo build works, you have to use -static-libgcc while compiling with mingw’s g++ to elemenate the dependacy on libgcc_s_sjlj-1.dll.

You don’t need root access anymore.
Read more »

Tags: , , , , , , , ,