Using CMake + Mingw to Cross-Compile Windows Apps.
Posted in Linux Development on November 23rd, 2009 by OneOfOneAs 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.
- Run winecfg, go to Drives, add drive and set the path to your win32 dev (we will use the letter G for this).
- 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 »