Make MinGW-w64 cross-compilation work again

It has come to using pkg-config. :O
This commit is contained in:
Přemysl Eric Janouch 2015-01-20 23:21:49 +01:00
parent 733fb54580
commit 5bb6a05e1c
3 changed files with 58 additions and 21 deletions

View File

@ -55,6 +55,8 @@ if (WIN32)
list (APPEND CMAKE_FIND_ROOT_PATH ${WIN32_DEPENDS_PATH})
endif (CMAKE_CROSSCOMPILING)
set (PKG_CONFIG_USE_CMAKE_PREFIX_PATH TRUE)
add_custom_target (win32-depends COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_SOURCE_DIR}/Win32Depends.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
@ -98,11 +100,23 @@ endif (CONVERT_EXECUTABLE AND NOT WIN32)
# Dependencies
find_package (JsonGlib REQUIRED)
find_package (PkgConfig REQUIRED)
pkg_search_module (Lua52 REQUIRED lua5.2 lua-5.2 lua>=5.2)
pkg_check_modules (GTK3 REQUIRED gtk+-3.0)
if (NOT WIN32)
pkg_search_module (Lua52 REQUIRED lua5.2 lua-5.2 lua>=5.2)
else (NOT WIN32)
find_package (Lua REQUIRED)
if (NOT LUA_FOUND OR LUA_VERSION_STRING VERSION_LESS "5.2")
message (FATAL_ERROR "Lua 5.2 not found")
endif (NOT LUA_FOUND OR LUA_VERSION_STRING VERSION_LESS "5.2")
set (Lua52_LIBRARIES ${LUA_LIBRARIES})
set (Lua52_INCLUDE_DIRS ${LUA_INCLUDE_DIR})
endif (NOT WIN32)
# This actually fucks up MinGW cross-compilation if omitted
link_directories (${GTK3_LIBRARY_DIRS})
# Localization
find_package (Gettext REQUIRED)
file (GLOB project_PO_FILES ${CMAKE_CURRENT_SOURCE_DIR}/po/*.po)
@ -360,13 +374,8 @@ if (WIN32)
${WIN32_DEPENDS_PATH}/etc/
DESTINATION etc)
install (DIRECTORY
${WIN32_DEPENDS_PATH}/lib/glib-2.0
${WIN32_DEPENDS_PATH}/lib/gtk-2.0
${WIN32_DEPENDS_PATH}/lib/gdk-pixbuf-2.0
DESTINATION lib)
install (DIRECTORY
${WIN32_DEPENDS_PATH}/share/themes/MS-Windows
DESTINATION share/themes)
# Avoid partial translations
file (GLOB locales ${WIN32_DEPENDS_PATH}/share/locale/*)

View File

@ -83,3 +83,15 @@ Now you can generate a package with CPack. You may choose between:
By default, that is if you specify no generator, both packages are built.
## Cross-compiling for Windows
Just install MinGW-w64 and let automation take care of the rest.
$ cmake -P Win32Depends.cmake
$ mkdir build
$ cd build
$ cmake .. \
-DCMAKE_TOOLCHAIN_FILE=../ToolchainDebianMinGWW64.cmake \
-DCMAKE_BUILD_TYPE=Release
$ cpack -G ZIP

View File

@ -18,29 +18,38 @@ if (files)
endif (files)
# Packages
set (pkg_list "7za" "gtk" "winlibs" "mingw_lua")
set (pkg_list "7za" "gtk" "gtkalt" "winlibs" "mingw_lua")
set (pkg_7za_root "http://sourceforge.net/projects/sevenzip/files")
set (pkg_7za_urls "${pkg_7za_root}/7-Zip/9.20/7za920.zip")
set (pkg_7za_md5 "2fac454a90ae96021f4ffc607d4c00f8")
set (pkg_gtk_root "http://ftp.gnome.org/pub/gnome/binaries/win32")
set (pkg_gtk_urls
"${pkg_gtk_root}/gtk+/2.24/gtk+-bundle_2.24.10-20120208_win32.zip"
"${pkg_gtk_root}/dependencies/gettext-tools-0.17.zip")
set (pkg_gtk_md5
"7ae20007b76e8099b05edc789bb23e54"
"09baff956ebd1c391c7f71e9bd768edd")
set (pkg_gtk_urls "${pkg_gtk_root}/dependencies/gettext-tools-0.17.zip")
set (pkg_gtk_md5 "09baff956ebd1c391c7f71e9bd768edd")
set (pkg_gtkalt_root "http://win32builder.gnome.org")
set (pkg_gtkalt_urls "${pkg_gtkalt_root}/gtk+-bundle_3.8.2-20131001_win32.zip")
set (pkg_gtkalt_md5 "3f9b159207edf44937f209b4a5e6bb63")
# Doesn't work, no gtk+-3.0.pc file present
#set (pkg_gtkalt_urls "${pkg_gtkalt_root}/gtk+-bundle_3.10.4-20131202_win32.zip")
#set (pkg_gtkalt_md5 "520bed70943974efdaeea2a1dbe48f84")
# Too old
#set (pkg_gtkalt_urls "${pkg_gtkalt_root}/gtk+-bundle_3.6.4-20130921_win32.zip")
#set (pkg_gtkalt_md5 "9bcb87d917982a6e52a69141ade8bd56")
set (pkg_winlibs_root "http://sourceforge.net/projects/winlibs/files")
set (pkg_winlibs_urls "${pkg_winlibs_root}/GTK+/libjson-glib-1.0-1-mingw32.7z")
set (pkg_winlibs_md5 "f06e42c5998dae5fb6245fecc96a403e")
set (pkg_mingw_lua_root "http://sourceforge.net/projects/mingw-cross/files/%5BLIB%5D%20Lua")
set (pkg_mingw_lua_name "mingw32-lua-5.1.4-2")
set (pkg_mingw_lua_urls "${pkg_mingw_lua_root}/${pkg_mingw_lua_name}/${pkg_mingw_lua_name}.zip")
set (pkg_mingw_lua_strip ${pkg_mingw_lua_name})
set (pkg_mingw_lua_md5 "7deb1f62a9631871e9b90c0419c2e2bb")
set (pkg_mingw_lua_root "http://sourceforge.net/projects/mingw/files/MinGW/Extension")
set (pkg_mingw_lua_urls
"${pkg_mingw_lua_root}/lua/lua-5.2.0-1/lua-5.2.0-1-mingw32-dll-52.tar.xz"
"${pkg_mingw_lua_root}/lua/lua-5.2.0-1/lua-5.2.0-1-mingw32-dev.tar.xz")
set (pkg_mingw_lua_md5
"150b27cab05b78ba40bbd7225630c00d"
"6abe77c1e1a783075fe73c53b7c235fb")
# Stage 1: fetch missing packages
foreach (pkg_set ${pkg_list})
@ -144,5 +153,12 @@ foreach (pkg_set ${pkg_list})
endforeach (pkg_set)
# Stage 4: final touches
file (WRITE ${working_dir}/etc/gtk-2.0/gtkrc
"gtk-theme-name = \"MS-Windows\"")
# We have to fix the prefix path as it is completely wrong everywhere
file (GLOB files ${working_dir}/lib/pkgconfig/*.pc)
foreach (file ${files})
message (STATUS "Fixing ${file}...")
file (READ ${file} file_content)
string (REGEX REPLACE "prefix=[^\r\n]*(.*)" "prefix=${working_dir}\\1"
file_content_fixed "${file_content}")
file (WRITE ${file} "${file_content_fixed}")
endforeach (file)