Skip to content

Commit af40c76

Browse files
committed
Better Wine detection and support
* Support more Wine packagings * Allow building 64-bit RemoteVstPlugin using 32-bit Wine tools if possible * Provide suitable library paths for creating AppImages
1 parent 97502a1 commit af40c76

File tree

3 files changed

+98
-31
lines changed

3 files changed

+98
-31
lines changed

cmake/linux/package_linux.sh.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ export LD_LIBRARY_PATH="${APPDIR}usr/lib/lmms/":$LD_LIBRARY_PATH
134134

135135
# Handle wine linking
136136
if [ -d "@WINE_32_LIBRARY_DIR@" ]; then
137-
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LD_LIBRARY_PATH/wine/:@WINE_32_LIBRARY_DIR@:@WINE_32_LIBRARY_DIR@wine/
137+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:@WINE_32_LIBRARY_DIRS@
138138
fi
139139
if [ -d "@WINE_64_LIBRARY_DIR@" ]; then
140-
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LD_LIBRARY_PATH/wine/:@WINE_64_LIBRARY_DIR@:@WINE_64_LIBRARY_DIR@wine/
140+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:@WINE_64_LIBRARY_DIRS@
141141
fi
142142

143143
# Move executables so linuxdeployqt can find them

cmake/modules/FindWine.cmake

+88-29
Original file line numberDiff line numberDiff line change
@@ -7,54 +7,113 @@
77
# WINE_DEFINITIONS - Compiler switches required for using wine
88
#
99

10-
LIST(APPEND CMAKE_PREFIX_PATH /opt/wine-stable /opt/wine-devel /opt/wine-staging /usr/lib/wine/)
10+
MACRO(_findwine_find_flags output expression result)
11+
STRING(REPLACE " " ";" WINEBUILD_FLAGS "${output}")
12+
FOREACH(FLAG ${WINEBUILD_FLAGS})
13+
IF("${FLAG}" MATCHES "${expression}")
14+
SET(${result} "${FLAG}")
15+
ENDIF()
16+
ENDFOREACH()
17+
ENDMACRO()
1118

19+
LIST(APPEND CMAKE_PREFIX_PATH /opt/wine-stable /opt/wine-devel /opt/wine-staging /usr/lib/wine/)
1220

13-
FIND_PATH(WINE_INCLUDE_DIR wine/exception.h PATH_SUFFIXES wine)
1421
FIND_PROGRAM(WINE_CXX
1522
NAMES wineg++ winegcc winegcc64 winegcc32 winegcc-stable
16-
PATHS /usr/lib/wine)
23+
PATHS /usr/lib/wine
24+
)
1725
FIND_PROGRAM(WINE_BUILD NAMES winebuild)
26+
# Detect wine paths and handle linking problems
27+
IF(WINE_CXX)
28+
EXEC_PROGRAM(${WINE_CXX} ARGS "-m32 -v /dev/zero" OUTPUT_VARIABLE WINEBUILD_OUTPUT_32)
29+
EXEC_PROGRAM(${WINE_CXX} ARGS "-m64 -v /dev/zero" OUTPUT_VARIABLE WINEBUILD_OUTPUT_64)
30+
_findwine_find_flags("${WINEBUILD_OUTPUT_32}" "^-isystem/usr/include$" BUGGED_WINEGCC)
31+
_findwine_find_flags("${WINEBUILD_OUTPUT_32}" "^-isystem" WINEGCC_INCLUDE_DIR)
32+
_findwine_find_flags("${WINEBUILD_OUTPUT_32}" "libwinecrt0\\.a.*" WINECRT_32)
33+
_findwine_find_flags("${WINEBUILD_OUTPUT_64}" "libwinecrt0\\.a.*" WINECRT_64)
34+
STRING(REGEX REPLACE "^-isystem" "" WINE_INCLUDE_HINT "${WINEGCC_INCLUDE_DIR}")
35+
STRING(REGEX REPLACE "/wine/windows$" "" WINE_INCLUDE_HINT "${WINE_INCLUDE_HINT}")
36+
STRING(REGEX REPLACE "libwinecrt0\\.a.*" "" WINE_32_LIBRARY_DIR "${WINECRT_32}")
37+
STRING(REGEX REPLACE "libwinecrt0\\.a.*" "" WINE_64_LIBRARY_DIR "${WINECRT_64}")
38+
39+
IF(BUGGED_WINEGCC)
40+
MESSAGE(WARNING "Your winegcc is unusable due to https://bugs.winehq.org/show_bug.cgi?id=46293,\n
41+
Consider either upgrading or downgrading wine.")
42+
RETURN()
43+
ENDIF()
44+
IF(WINE_32_LIBRARY_DIR STREQUAL WINE_64_LIBRARY_DIR)
45+
MESSAGE(STATUS "Old winegcc detected, trying to use workaround linking")
46+
# Fix library search directory according to the target bitness
47+
IF(WINE_32_LIBRARY_DIR MATCHES "/lib/(x86_64|i386)-")
48+
# Debian systems
49+
STRING(REPLACE "/lib/x86_64-" "/lib/i386-" WINE_32_LIBRARY_DIR "${WINE_32_LIBRARY_DIR}")
50+
STRING(REPLACE "/lib/i386-" "/lib/x86_64-" WINE_64_LIBRARY_DIR "${WINE_64_LIBRARY_DIR}")
51+
ELSEIF(WINE_32_LIBRARY_DIR MATCHES "/(lib|lib64)/wine/$")
52+
# WineHQ (/opt/wine-stable, /opt/wine-devel, /opt/wine-staging)
53+
STRING(REGEX REPLACE "/lib64/wine/$" "/lib/wine/" WINE_32_LIBRARY_DIR "${WINE_32_LIBRARY_DIR}")
54+
STRING(REGEX REPLACE "/lib/wine/$" "/lib64/wine/" WINE_64_LIBRARY_DIR "${WINE_64_LIBRARY_DIR}")
55+
ELSEIF(WINE_32_LIBRARY_DIR MATCHES "/lib32/.*/wine/")
56+
# Systems with old multilib layout
57+
STRING(REPLACE "/lib32/" "/lib/" WINE_64_LIBRARY_DIR "${WINE_32_LIBRARY_DIR}")
58+
ELSEIF(WINE_32_LIBRARY_DIR MATCHES "/lib64/.*/wine/")
59+
# We need to test if the corresponding 64bit library directory is lib or lib32
60+
STRING(REPLACE "/lib64/" "/lib32/" WINE_32_LIBRARY_DIR "${WINE_64_LIBRARY_DIR}")
61+
IF(NOT EXISTS "${WINE_32_LIBRARY_DIR}")
62+
STRING(REPLACE "/lib64/" "/lib/" WINE_32_LIBRARY_DIR "${WINE_64_LIBRARY_DIR}")
63+
ENDIF()
64+
ELSEIF(WINE_32_LIBRARY_DIR MATCHES "/lib/.*/wine/")
65+
# Test if this directory is for 32bit or 64bit
66+
STRING(REPLACE "/lib/" "/lib32/" WINE_32_LIBRARY_DIR "${WINE_64_LIBRARY_DIR}")
67+
IF(NOT EXISTS "${WINE_32_LIBRARY_DIR}")
68+
SET(WINE_32_LIBRARY_DIR "${WINE_64_LIBRARY_DIR}")
69+
STRING(REPLACE "/lib/" "/lib64/" WINE_64_LIBRARY_DIR "${WINE_64_LIBRARY_DIR}")
70+
ENDIF()
71+
ELSE()
72+
MESSAGE(WARNING "Can't detect wine installation layout. You may get some build errors.")
73+
ENDIF()
74+
SET(WINE_LIBRARY_FIX "${WINE_32_LIBRARY_DIR} and ${WINE_64_LIBRARY_DIR}")
75+
ENDIF()
76+
ENDIF()
77+
78+
FIND_PATH(WINE_INCLUDE_DIR wine/exception.h
79+
HINTS "${WINE_INCLUDE_HINT}"
80+
)
1881

1982
SET(_ARCHITECTURE ${CMAKE_LIBRARY_ARCHITECTURE})
2083

21-
FIND_LIBRARY(WINE_LIBRARY NAMES wine PATH_SUFFIXES wine i386-linux-gnu/wine)
84+
FIND_LIBRARY(WINE_LIBRARY NAMES wine
85+
PATH_SUFFIXES wine i386-linux-gnu/wine
86+
HINTS "${WINE_32_LIBRARY_DIR}" "${WINE_64_LIBRARY_DIR}"
87+
)
2288

2389
SET(CMAKE_LIBRARY_ARCHITECTURE ${_ARCHITECTURE})
2490

2591
SET(WINE_INCLUDE_DIRS ${WINE_INCLUDE_DIR} )
26-
SET(WINE_LIBRARIES ${WINE_LIBRARY} )
27-
28-
# Handle wine linking problems
29-
EXEC_PROGRAM(${WINE_CXX} ARGS "-v -m32 /dev/zero" OUTPUT_VARIABLE WINEBUILD_OUTPUT)
30-
STRING(REPLACE " " ";" WINEBUILD_FLAGS "${WINEBUILD_OUTPUT}")
31-
32-
FOREACH(FLAG ${WINEBUILD_FLAGS})
33-
IF("${FLAG}" MATCHES "libwinecrt0.a.*")
34-
STRING(REGEX REPLACE "/wine/libwinecrt0.a.*" "" FLAG "${FLAG}")
35-
36-
SET(WINE_64_LIBRARY_DIR "${FLAG}/")
37-
38-
# Debian systems
39-
STRING(REPLACE "/lib/x86_64-" "/lib/i386-" FLAG "${FLAG}")
40-
# Fedora systems
41-
STRING(REPLACE "/lib/lib64" "/lib/i386" FLAG "${FLAG}")
42-
# Gentoo systems
43-
STRING(REPLACE "/lib/wine-" "/lib32/wine-" FLAG "${FLAG}")
44-
# WineHQ (/opt/wine-stable, /opt/wine-devel, /opt/wine-staging)
45-
STRING(REGEX REPLACE "/lib64$" "/lib" FLAG "${FLAG}")
46-
47-
SET(WINE_32_LIBRARY_DIR "${FLAG}/")
48-
ENDIF()
49-
ENDFOREACH()
92+
SET(WINE_LIBRARIES ${WINE_LIBRARY})
5093

5194
include(FindPackageHandleStandardArgs)
5295
find_package_handle_standard_args(Wine DEFAULT_MSG WINE_CXX WINE_LIBRARIES WINE_INCLUDE_DIRS)
5396

5497
mark_as_advanced(WINE_INCLUDE_DIR WINE_LIBRARY WINE_CXX WINE_BUILD)
5598

5699
IF(WINE_32_LIBRARY_DIR)
57-
SET(WINE_32_FLAGS "-L${WINE_32_LIBRARY_DIR}wine/ -L${WINE_32_LIBRARY_DIR}")
100+
IF(WINE_32_LIBRARY_DIR MATCHES "wine*/lib")
101+
SET(WINE_32_FLAGS "-L${WINE_32_LIBRARY_DIR} -L${WINE_32_LIBRARY_DIR}../")
102+
SET(WINE_32_LIBRARY_DIRS "${WINE_32_LIBRARY_DIR}:${WINE_32_LIBRARY_DIR}/..")
103+
ELSE()
104+
SET(WINE_32_FLAGS "-L${WINE_32_LIBRARY_DIR}")
105+
SET(WINE_32_LIBRARY_DIRS "${WINE_32_LIBRARY_DIR}")
106+
ENDIF()
107+
ENDIF()
108+
109+
IF(WINE_64_LIBRARY_DIR)
110+
IF(WINE_64_LIBRARY_DIR MATCHES "wine*/lib")
111+
SET(WINE_64_FLAGS "-L${WINE_64_LIBRARY_DIR} -L${WINE_64_LIBRARY_DIR}../")
112+
SET(WINE_64_LIBRARY_DIRS "${WINE_64_LIBRARY_DIR}:${WINE_64_LIBRARY_DIR}/..")
113+
ELSE()
114+
SET(WINE_64_FLAGS "-L${WINE_64_LIBRARY_DIR}")
115+
SET(WINE_64_LIBRARY_DIRS "${WINE_64_LIBRARY_DIR}")
116+
ENDIF()
58117
ENDIF()
59118

60119
# Create winegcc wrapper

cmake/modules/winegcc_wrapper.in

+8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ while [ $# -gt 0 ]; do
2222
-m32)
2323
win32=true
2424
;;
25+
-m64)
26+
win64=true
27+
;;
2528
*)
2629

2730
;;
@@ -47,6 +50,11 @@ if [ "$win32" = true ] && [ "$no_link" != true ]; then
4750
extra_args="$extra_args @WINE_32_FLAGS@"
4851
fi
4952

53+
# Apply -m64 library fix if necessary
54+
if [ "$win64" = true ] && [ "$no_link" != true ]; then
55+
extra_args="$extra_args @WINE_64_FLAGS@"
56+
fi
57+
5058
# Run winegcc
5159
export WINEBUILD=@WINE_BUILD@
5260
@WINE_CXX@ $extra_args $args

0 commit comments

Comments
 (0)