Environment setup for cross-compiling on Linux for Windows

Started by eumagga0x2a, November 15, 2016, 12:08:38 PM

Previous topic - Next topic

eumagga0x2a

I must have been sort of selectively blind  :) QT_INCLUDES were NOT set correctly, with

diff --git a/cmake/admCheckQt5.cmake b/cmake/admCheckQt5.cmake
index cd9335b..2e0fbe0 100644
--- a/cmake/admCheckQt5.cmake
+++ b/cmake/admCheckQt5.cmake
@@ -8,7 +8,7 @@ MACRO(checkQt5)
         MESSAGE(STATUS "******************")
         IF(CROSS)
                 MESSAGE(STATUS "Cross compiling override for QT5")
-                SET(CROSS5 /usr/lib/x86_64-linux-gnu/cmake/)
+                SET(CROSS5 ${CROSS}/qt5/lib/cmake)
                 SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CROSS5}/Qt5 ${CROSS5}/Qt5Core ${CROSS5}/Qt5Widgets)
                 SET(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${CROSS5}/Qt5 ${CROSS5}/Qt5Core ${CROSS5}/Qt5Widgets)
                 MESSAGE(STATUS "Search path ${CMAKE_MODULE_PATH}")
@@ -20,8 +20,8 @@ MACRO(checkQt5)
                 SET(QT_QTOPENGL_LIBRARIES Qt5OpenGL)
                 SET(QT_QTOPENGL_INCLUDE_DIR ${QT_HOME}/include/QtOpenGL)

-                SET(QT_HEADERS_DIR   ${QT_HOME}/include/qt5  ${QT_HOME}/include/qt5/QtGui ${QT_HOME}/include/qt5/QtCore ${QT_HOME}/include/qt5/QtWidgets ${QT_HOME}/include/qt5/QtNetwork)
-                SET(QT_INCLUDES    -I${QT_HOME}/include/qt5 -I${QT_HOME}/include/qt5/QtGui -I${QT_HOME}/include/qt5/QtCore -I${QT_HOME}/include/qt5/QtWidgets -I${QT_HOME}/include/qt5/QtNetwork)
+                SET(QT_HEADERS_DIR   ${QT_HOME}/include  ${QT_HOME}/include/QtGui ${QT_HOME}/include/QtCore ${QT_HOME}/include/QtWidgets ${QT_HOME}/include/QtNetwork)
+                SET(QT_INCLUDES    -I${QT_HOME}/include -I${QT_HOME}/include/QtGui -I${QT_HOME}/include/QtCore -I${QT_HOME}/include/QtWidgets -I${QT_HOME}/include/QtNetwork)
                 SET(QT_INCLUDE_DIR   ${QT_HEADERS_DIR})
                 SET(QT_BINARY_DIR    ${QT_HOME}/bin)
                 SET(QT_LIBRARY_DIR   ${QT_HOME}/lib ${QT_HOME}/bin)
@@ -34,7 +34,7 @@ MACRO(checkQt5)
                 SET(QT_LIBRARY_EXTENSION QT5)
                 SET(QT5_FOUND True)
                 SET(ADM_QT_VERSION 5)
-                SET(QT5_ROOT_DIR /usr/lib/x86_64-linux-gnu/qt5/bin)
+                SET(QT5_ROOT_DIR ${QT_HOME}/bin)
                 SET(QT_RCC_EXECUTABLE ${QT5_ROOT_DIR}/rcc)
                 SET(QT_MOC_EXECUTABLE ${QT5_ROOT_DIR}/moc)
                 SET(QT_UIC_EXECUTABLE ${QT5_ROOT_DIR}/uic)


everything is fine (except of qtwinextras MXE package missing because I just selected qtbase and qttools to save time while setting up the cross-compile environment).

mean

The last part is to collect all the needed libs and stuff and put everything in one place
Then run wine on it and watch it crash :)

eumagga0x2a

#17
That's true, collecting all the necessary libs and Qt platform stuff required a couple of reboots, but anyway, my first cross-compiled 32 bit Avidemux runs (loads and plays a video via DXVA2 decoder and driver) fine on Windows 7 :) Some features are missing because I borked some components like the x265 install, which is not available via MXE.

I get almost identical CPU usage (~28%) when decoding and playing a 720p video via VDPAU on Linux and via DXVA2 on Windows 7.

edit: I'll try to collect all the necessary patches and push them to my Avidemux git repo over the next days.

edit: A nice screenshot of the video filter manager with the patch from http://avidemux.org/smif/index.php/topic,12493.msg77852.html#msg77852 as proof: only the right column, where the background color is hardcoded white via stylesheet, doesn't suffer from redraw issues.

eumagga0x2a

I'll probably abandon Debian 8 as base for MXE to build 64 bit Avidemux and install MXE on top of Fedora because x265 v2.1 fails to build with yasm 1.2 from Debian (it succeeds with yasm 1.3).

mean


eumagga0x2a

This doesn't bode well if this implies that 1.3 doesn't work for 32 bit cross-builds...

eumagga0x2a

x265 has cross-compiled OK on Fedora, no issues with yasm there no matter x86_64 or i686. I've built 64 and 32 bit Avidemux using MXE (total size of the MXE directory: 2,2G) on Fedora, both run without a hitch on Windows 7. The redundant huge Debian container is ditched now.

I'll try to cleanup and push the enhanced mxe bootstrap script along with the scripts to collect all the required libs, the patched scripts from the foreignBuilds directory and a brief howto to my git repository in the near future.

eumagga0x2a

By the way, when cross-compiling, I had to build against the system libass if fribidi was present in MXE. I used a patch based on https://pkgs.rpmfusion.org/cgit/free/avidemux.git/tree/avidemux-2.6.10-bundled_libs.patch for this task, with slight modifications to fix include paths when building with bundled liba52, libmad and libass:

diff --git a/avidemux_plugins/ADM_audioDecoders/ADM_ad_ac3/ADM_ad_a52.cpp b/avidemux_plugins/ADM_audioDecoders/ADM_ad_ac3/ADM_ad_a52.cpp
index 6eddc3a..d2fdb49 100644
--- a/avidemux_plugins/ADM_audioDecoders/ADM_ad_ac3/ADM_ad_a52.cpp
+++ b/avidemux_plugins/ADM_audioDecoders/ADM_ad_ac3/ADM_ad_a52.cpp
@@ -18,8 +18,13 @@
#include "ADM_ad_plugin.h"

extern "C" {
-#include "ADM_liba52/a52.h"
-#include "ADM_liba52/mm_accel.h"
+#ifdef USE_EXTERNAL_LIBA52
+    #include "a52dec/a52.h"
+    #include "a52dec/mm_accel.h"
+#else
+    #include "ADM_liba52/a52.h"
+    #include "ADM_liba52/mm_accel.h"
+#endif
};

#define AC3_HANDLE ((a52_state_t *)ac3_handle)
diff --git a/avidemux_plugins/ADM_audioDecoders/ADM_ad_ac3/CMakeLists.txt b/avidemux_plugins/ADM_audioDecoders/ADM_ad_ac3/CMakeLists.txt
index 04fbdc6..f769ded 100644
--- a/avidemux_plugins/ADM_audioDecoders/ADM_ad_ac3/CMakeLists.txt
+++ b/avidemux_plugins/ADM_audioDecoders/ADM_ad_ac3/CMakeLists.txt
@@ -1,11 +1,18 @@
INCLUDE(ad_plugin)

-ADD_SUBDIRECTORY(ADM_liba52)
+IF(NOT USE_EXTERNAL_LIBA52)
+    ADD_SUBDIRECTORY(ADM_liba52)
+ENDIF()

SET(ADM_ad_a52_SRCS ADM_ad_a52.cpp)

ADD_AUDIO_DECODER( ADM_ad_a52  ${ADM_ad_a52_SRCS})
-TARGET_LINK_LIBRARIES(ADM_ad_a52 ADM_liba52)
+
+IF(USE_EXTERNAL_LIBA52)
+    TARGET_LINK_LIBRARIES(ADM_ad_a52 ${LIBA52_LIBRARIES})
+ELSE()
+    TARGET_LINK_LIBRARIES(ADM_ad_a52 ADM_liba52)
+ENDIF()

INIT_AUDIO_PLUGIN(ADM_ad_a52)
INSTALL_AUDIODECODER(ADM_ad_a52)
diff --git a/avidemux_plugins/ADM_audioDecoders/ADM_ad_mad/ADM_ad_mad.cpp b/avidemux_plugins/ADM_audioDecoders/ADM_ad_mad/ADM_ad_mad.cpp
index 171b413..d71fc68 100644
--- a/avidemux_plugins/ADM_audioDecoders/ADM_ad_mad/ADM_ad_mad.cpp
+++ b/avidemux_plugins/ADM_audioDecoders/ADM_ad_mad/ADM_ad_mad.cpp
@@ -16,7 +16,12 @@
  ***************************************************************************/
#include "ADM_default.h"
#include "ADM_ad_plugin.h"
-#include "ADM_libMad/mad.h"
+
+#ifdef USE_EXTERNAL_LIBMAD
+    #include "mad.h"
+#else
+    #include "ADM_libMad/mad.h"
+#endif

#define Stream ((mad_stream *)_stream)
#define Frame ((mad_frame *)_frame)
diff --git a/avidemux_plugins/ADM_audioDecoders/ADM_ad_mad/CMakeLists.txt b/avidemux_plugins/ADM_audioDecoders/ADM_ad_mad/CMakeLists.txt
index e5e317b..22d28e1 100644
--- a/avidemux_plugins/ADM_audioDecoders/ADM_ad_mad/CMakeLists.txt
+++ b/avidemux_plugins/ADM_audioDecoders/ADM_ad_mad/CMakeLists.txt
@@ -14,13 +14,20 @@ ELSEIF (ADM_CPU_ARMEL)
ADD_DEFINITIONS("-DFPM_ARM")
ENDIF (ADM_CPU_X86_32)

-ADD_SUBDIRECTORY(ADM_libMad)
+IF(NOT USE_EXTERNAL_LIBMAD)
+    ADD_SUBDIRECTORY(ADM_libMad)
+ENDIF()

ADD_DEFINITIONS("-DHAVE_ASSERT_H")
SET(ADM_ad_Mad_SRCS ADM_ad_mad.cpp)

ADD_AUDIO_DECODER( ADM_ad_Mad ${ADM_ad_Mad_SRCS})
-TARGET_LINK_LIBRARIES(ADM_ad_Mad ADM_libMad)
+
+IF(USE_EXTERNAL_LIBMAD)
+    TARGET_LINK_LIBRARIES(ADM_ad_Mad ${LIBMAD_LIBRARIES})
+ELSE()
+    TARGET_LINK_LIBRARIES(ADM_ad_Mad ADM_libMad)
+ENDIF()

INIT_AUDIO_PLUGIN(ADM_ad_Mad)
INSTALL_AUDIODECODER(ADM_ad_Mad)
diff --git a/avidemux_plugins/ADM_videoFilters6/ass/ADM_vidASS.cpp b/avidemux_plugins/ADM_videoFilters6/ass/ADM_vidASS.cpp
index baadf0c..1a0c948 100644
--- a/avidemux_plugins/ADM_videoFilters6/ass/ADM_vidASS.cpp
+++ b/avidemux_plugins/ADM_videoFilters6/ass/ADM_vidASS.cpp
@@ -24,7 +24,11 @@
#include "prefs.h"
extern "C"
{
-#include "ADM_libass/ass.h"
+#ifdef USE_EXTERNAL_LIBASS
+    #include "ass/ass.h"
+#else
+    #include "ADM_libass/ass.h"
+#endif
}

/**
diff --git a/avidemux_plugins/ADM_videoFilters6/ass/CMakeLists.txt b/avidemux_plugins/ADM_videoFilters6/ass/CMakeLists.txt
index f793fe0..f101863 100644
--- a/avidemux_plugins/ADM_videoFilters6/ass/CMakeLists.txt
+++ b/avidemux_plugins/ADM_videoFilters6/ass/CMakeLists.txt
@@ -1,24 +1,27 @@
-INCLUDE(admCheckFreeType)
-INCLUDE(admCheckFridibi)
-ADD_CORE_INCLUDE(ADM_coreSubtitles)
-checkFreeType()
-checkFridibi("0.19")
-
-IF (USE_FREETYPE AND USE_FRIDIBI)
- ADD_SUBDIRECTORY(ADM_libass)
-
- INCLUDE(vf_plugin)
- SET(ADM_vf_ssa_SRCS ADM_vidASS.cpp)
-
- ADD_VIDEO_FILTER(ADM_vf_ssa ${ADM_vf_ssa_SRCS})
-
- IF(DO_COMMON)
- TARGET_LINK_LIBRARIES(ADM_vf_ssa ADM_libass ${FREETYPE2_LDFLAGS} ${FRIDIBI_LDFLAGS} ADM_coreSubtitle)
-                # We force the use of fontconfig
-                ADD_DEFINITIONS("-DUSE_FONTCONFIG")
-                TARGET_LINK_LIBRARIES(ADM_vf_ssa ${FONTCONFIG_LDFLAGS})
- ENDIF(DO_COMMON)
-
- INIT_VIDEO_FILTER(ADM_vf_ssa)
- INSTALL_VIDEO_FILTER(ADM_vf_ssa)
-ENDIF (USE_FREETYPE AND USE_FRIDIBI)
+INCLUDE(admCheckFreeType)
+INCLUDE(admCheckFridibi)
+ADD_CORE_INCLUDE(ADM_coreSubtitles)
+checkFreeType()
+checkFridibi("0.19")
+
+IF (USE_FREETYPE AND USE_FRIDIBI)
+    INCLUDE(vf_plugin)
+    SET(ADM_vf_ssa_SRCS ADM_vidASS.cpp)
+
+    ADD_VIDEO_FILTER(ADM_vf_ssa ${ADM_vf_ssa_SRCS})
+
+    IF(DO_COMMON)
+        IF(USE_EXTERNAL_LIBASS)
+            TARGET_LINK_LIBRARIES(ADM_vf_ssa ${LIBASS_LIBRARIES} ${FREETYPE2_LDFLAGS} ${FRIDIBI_LDFLAGS} ADM_coreSubtitle)
+        ELSE(USE_EXTERNAL_LIBASS)
+            ADD_SUBDIRECTORY(ADM_libass)
+            TARGET_LINK_LIBRARIES(ADM_vf_ssa ADM_libass ${FREETYPE2_LDFLAGS} ${FRIDIBI_LDFLAGS} ADM_coreSubtitle)
+        ENDIF(USE_EXTERNAL_LIBASS)
+        # We force the use of fontconfig
+        ADD_DEFINITIONS("-DUSE_FONTCONFIG")
+        TARGET_LINK_LIBRARIES(ADM_vf_ssa ${FONTCONFIG_LDFLAGS})
+    ENDIF(DO_COMMON)
+
+    INIT_VIDEO_FILTER(ADM_vf_ssa)
+    INSTALL_VIDEO_FILTER(ADM_vf_ssa)
+ENDIF (USE_FREETYPE AND USE_FRIDIBI)
diff --git a/avidemux_plugins/CMakeLists.txt b/avidemux_plugins/CMakeLists.txt
index 0333abd..96fc895 100644
--- a/avidemux_plugins/CMakeLists.txt
+++ b/avidemux_plugins/CMakeLists.txt
@@ -64,6 +64,41 @@ include(admCoreIncludes)
LINK_DIRECTORIES("${AVIDEMUX_SEARCH_LIB_DIR}")
INCLUDE_DIRECTORIES("${AVIDEMUX_SEARCH_INCLUDE_DIR}/avidemux/2.6")

+#########################################
+# Unbundle some libraries here
+#########################################
+OPTION(USE_EXTERNAL_LIBASS "Use system installed libass library." OFF)
+OPTION(USE_EXTERNAL_LIBMAD "Use system installed libmad library." OFF)
+OPTION(USE_EXTERNAL_LIBA52 "Use system installed liba52 library." OFF)
+OPTION(USE_EXTERNAL_LIBTWOLAME "Use system installed libtwolame library." OFF)
+
+INCLUDE(FindPkgConfig)
+
+# libass
+IF(USE_EXTERNAL_LIBASS)
+        PKG_CHECK_MODULES(LIBASS REQUIRED libass)
+        INCLUDE_DIRECTORIES(SYSTEM ${LIBASS_INCLUDE_DIRS})
+ENDIF()
+
+# libmad
+IF(USE_EXTERNAL_LIBMAD)
+        FIND_PATH(LIBMAD_INCLUDE_DIR mad.h)
+        FIND_LIBRARY(LIBMAD_LIBRARIES mad)
+        INCLUDE_DIRECTORIES(SYSTEM ${LIBMAD_INCLUDE_DIRS})
+ENDIF()
+
+# liba52
+IF(USE_EXTERNAL_LIBA52)
+        FIND_PATH(LIBA52_INCLUDE_DIR a52dec/a52.h)
+        FIND_LIBRARY(LIBA52_LIBRARIES a52)
+        INCLUDE_DIRECTORIES(SYSTEM ${LIBA52_INCLUDE_DIR})
+ENDIF()
+
+# twolame
+IF(USE_EXTERNAL_TWOLAME)
+        PKG_CHECK_MODULES(LIBTWOLAME REQUIRED twolame)
+        INCLUDE_DIRECTORIES(SYSTEM ${LIBTWOLAME_INCLUDE_DIRS})
+ENDIF()

IF (FRESH_BUILD)
MESSAGE("")


By the way, it would be great if all cmake files were converted to Unix line terminators, the current mix causes headaches depending on text editor (vim is capable of handling mixed line endings within a file, gedit is not). The list of remaining files to convert:

avidemux_core/ADM_coreSubtitles/src/CMakeLists.txt
avidemux/common/ADM_audioCodec/src/CMakeLists.txt
avidemux/common/ADM_render/CMakeLists.txt
avidemux/common/ADM_script2/CMakeLists.txt
avidemux/common/ADM_videoCodec/CMakeLists.txt
avidemux/common/ADM_libraries/CMakeLists.txt
avidemux/common/ADM_libraries/ADM_libsdl/CMakeLists.txt
avidemux/qt4/CMakeLists.txt
avidemux/qt4/ADM_openGL/CMakeLists.txt
avidemux/qt4/ADM_openGL/src/CMakeLists.txt
avidemux/qt4/ADM_update/CMakeLists.txt
avidemux/qt4/ADM_update/src/CMakeLists.txt
avidemux/qt4/i18n/CMakeLists.txt
avidemux/qt4/ADM_jobs/CMakeLists.txt
avidemux/qt4/ADM_jobs/src/CMakeLists.txt
avidemux/qt4/ADM_userInterfaces/ADM_filters/CMakeLists.txt
avidemux/qt4/ADM_userInterfaces/ADM_gui/CMakeLists.txt
avidemux/qt4/ADM_userInterfaces/ADM_ocr/CMakeLists.txt
avidemux/qt4/ADM_UIs/CMakeLists.txt
avidemux/qt4/ADM_UIs/src/CMakeLists.txt
avidemux/cli/CMakeLists.txt
# gtk skipped
avidemux_plugins/ADM_demuxers/VapourSynth/qt4/CMakeLists.txt
avidemux_plugins/ADM_videoFilters6/CMakeLists.txt
avidemux_plugins/ADM_videoFilters6/ass/ADM_libass/CMakeLists.txt
avidemux_plugins/ADM_videoDecoder/CMakeLists.txt
avidemux_plugins/ADM_videoDecoder/vpx/CMakeLists.txt
avidemux_plugins/ADM_videoEncoder/CMakeLists.txt
avidemux_plugins/ADM_videoEncoder/jpeg/CMakeLists.txt
avidemux_plugins/ADM_videoEncoder/libva/CMakeLists.txt
avidemux_plugins/ADM_videoEncoder/png/CMakeLists.txt
avidemux_plugins/ADM_videoEncoder/yv12/CMakeLists.txt
avidemux_plugins/ADM_videoEncoder/huff/CMakeLists.txt
avidemux_plugins/ADM_videoFilters/CMakeLists.txt
avidemux_plugins/ADM_videoFilters/Srt/CMakeLists.txt
avidemux_plugins/ADM_muxers/muxerMplex/CMakeLists.txt
# spiderMonkey skipped
avidemux_plugins/ADM_audioDecoders/ADM_ad_mad/ADM_libMad/CMakeLists.txt
avidemux_plugins/ADM_autoScrips/CMakeLists.txt


eumagga0x2a

The bash script which automates cross-compiling and packaging for Windows has been merged into the git master. A howto explains the pretty straightforward setup of the build environment.

Please note that as of now you must add the --with-system-libass option to bootStrapCrossMingwQt5_mxe.sh, otherwise the cross-compilation will fail in pluginsCommon.