Skip to content

Commit db106a4

Browse files
committed
Fix BrowserEngine Linux compatibility with cross-platform COM support
Replace midl.exe with widl (Wine IDL compiler) and implement proper cross-platform COM interface compilation following PR TheSuperHackers#672 methodology. Changes: - Replace midl.exe with widl for cross-platform IDL compilation - Add fallback logic: midl.exe → widl detection with proper arguments - Use MinGW cross-compiler (i686-w64-mingw32-gcc) for COM interface compilation - Fix ATL module initialization with third NULL parameter for MinGW compatibility - Enable complete BrowserEngine builds on Linux with Windows API compatibility Technical implementation: - IDL files compiled with widl (-h -H for headers, -c for client stubs) - COM interface files compiled with MinGW cross-compiler for Windows API compatibility - Fallback to regular GCC with MinGW-w64 headers if cross-compiler unavailable - Maintains full compatibility with existing Windows build system Fixes compilation of EABrowserEngine and EABrowserDispatch components on Linux while preserving Windows functionality.
1 parent d61ce1f commit db106a4

File tree

3 files changed

+153
-5
lines changed

3 files changed

+153
-5
lines changed

Core/Libraries/Source/EABrowserDispatch/CMakeLists.txt

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,89 @@
11
add_library(core_browserdispatch INTERFACE)
22

3-
if(WIN32 OR "${CMAKE_SYSTEM}" MATCHES "Windows")
3+
# Use widl (Wine IDL compiler) for cross-platform COM interface generation
4+
if(WIN32)
5+
# On Windows, try to use midl.exe first, fall back to widl
6+
find_program(MIDL_EXECUTABLE midl.exe)
7+
if(MIDL_EXECUTABLE)
8+
add_custom_command(
9+
OUTPUT BrowserDispatch_i.c BrowserDispatch.h
10+
COMMAND ${MIDL_EXECUTABLE} "${CMAKE_CURRENT_LIST_DIR}\\BrowserDispatch.idl" /header BrowserDispatch.h
11+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
12+
DEPENDS "${CMAKE_CURRENT_LIST_DIR}/BrowserDispatch.idl"
13+
VERBATIM
14+
)
15+
else()
16+
# Fall back to widl on Windows if midl.exe not found
17+
find_program(WIDL_EXECUTABLE widl REQUIRED)
18+
add_custom_command(
19+
OUTPUT BrowserDispatch_i.c BrowserDispatch.h
20+
COMMAND ${WIDL_EXECUTABLE} -h -H BrowserDispatch.h "${CMAKE_CURRENT_LIST_DIR}/BrowserDispatch.idl"
21+
COMMAND ${WIDL_EXECUTABLE} -c -o BrowserDispatch_i.c "${CMAKE_CURRENT_LIST_DIR}/BrowserDispatch.idl"
22+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
23+
DEPENDS "${CMAKE_CURRENT_LIST_DIR}/BrowserDispatch.idl"
24+
VERBATIM
25+
)
26+
endif()
27+
else()
28+
# On non-Windows platforms, use widl (Wine IDL compiler)
29+
find_program(WIDL_EXECUTABLE widl REQUIRED)
430
add_custom_command(
531
OUTPUT BrowserDispatch_i.c BrowserDispatch.h
6-
COMMAND midl.exe "${CMAKE_CURRENT_LIST_DIR}\\BrowserDispatch.idl" /header BrowserDispatch.h
32+
COMMAND ${WIDL_EXECUTABLE} -h -H BrowserDispatch.h "${CMAKE_CURRENT_LIST_DIR}/BrowserDispatch.idl"
33+
COMMAND ${WIDL_EXECUTABLE} -c -o BrowserDispatch_i.c "${CMAKE_CURRENT_LIST_DIR}/BrowserDispatch.idl"
734
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
835
DEPENDS "${CMAKE_CURRENT_LIST_DIR}/BrowserDispatch.idl"
936
VERBATIM
1037
)
38+
endif()
39+
40+
# Build the COM interface library using MinGW cross-compiler for Windows API compatibility
41+
find_program(MINGW_GCC i686-w64-mingw32-gcc)
42+
43+
if(MINGW_GCC)
44+
# Use MinGW cross-compiler to compile COM interface files
45+
message(STATUS "Using MinGW cross-compiler for COM interface compilation: ${MINGW_GCC}")
46+
47+
# Create custom command to compile BrowserDispatch_i.c with MinGW
48+
add_custom_command(
49+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/BrowserDispatch_i.o
50+
COMMAND ${MINGW_GCC} -c -I${CMAKE_CURRENT_BINARY_DIR}
51+
${CMAKE_CURRENT_BINARY_DIR}/BrowserDispatch_i.c
52+
-o ${CMAKE_CURRENT_BINARY_DIR}/BrowserDispatch_i.o
53+
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/BrowserDispatch_i.c
54+
COMMENT "Compiling BrowserDispatch_i.c with MinGW cross-compiler"
55+
)
56+
57+
# Create library from the MinGW-compiled object file
58+
add_library(core_browserdispatchwin STATIC ${CMAKE_CURRENT_BINARY_DIR}/BrowserDispatch_i.o)
59+
set_target_properties(core_browserdispatchwin PROPERTIES
60+
OUTPUT_NAME browserdispatchwin
61+
LINKER_LANGUAGE C
62+
)
63+
64+
target_link_libraries(core_browserdispatch INTERFACE core_browserdispatchwin)
65+
66+
else()
67+
# Fallback: try to compile with regular GCC and MinGW-w64 headers
68+
message(WARNING "MinGW cross-compiler not found. Attempting compilation with regular GCC and MinGW-w64 headers.")
69+
1170
add_library(core_browserdispatchwin STATIC BrowserDispatch_i.c)
1271
set_target_properties(core_browserdispatchwin PROPERTIES OUTPUT_NAME browserdispatchwin)
72+
73+
# Add MinGW-w64 headers for Windows API compatibility
74+
find_path(MINGW_W64_INCLUDE_DIR windows.h
75+
HINTS
76+
/usr/i686-w64-mingw32/include
77+
/usr/x86_64-w64-mingw32/include
78+
/usr/include/mingw
79+
DOC "MinGW-w64 include directory for Windows API compatibility"
80+
)
81+
82+
if(MINGW_W64_INCLUDE_DIR)
83+
target_include_directories(core_browserdispatchwin PRIVATE ${MINGW_W64_INCLUDE_DIR})
84+
message(STATUS "Using MinGW-w64 headers: ${MINGW_W64_INCLUDE_DIR}")
85+
endif()
86+
1387
target_link_libraries(core_browserdispatch INTERFACE core_browserdispatchwin)
1488
endif()
1589

Core/Libraries/Source/EABrowserEngine/CMakeLists.txt

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,89 @@
11
add_library(core_browserengine INTERFACE)
22

3-
if(WIN32 OR "${CMAKE_SYSTEM}" MATCHES "Windows")
3+
# Use widl (Wine IDL compiler) for cross-platform COM interface generation
4+
if(WIN32)
5+
# On Windows, try to use midl.exe first, fall back to widl
6+
find_program(MIDL_EXECUTABLE midl.exe)
7+
if(MIDL_EXECUTABLE)
8+
add_custom_command(
9+
OUTPUT BrowserEngine_i.c BrowserEngine.h
10+
COMMAND ${MIDL_EXECUTABLE} "${CMAKE_CURRENT_LIST_DIR}\\BrowserEngine.idl" /header BrowserEngine.h
11+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
12+
DEPENDS "${CMAKE_CURRENT_LIST_DIR}/BrowserEngine.idl"
13+
VERBATIM
14+
)
15+
else()
16+
# Fall back to widl on Windows if midl.exe not found
17+
find_program(WIDL_EXECUTABLE widl REQUIRED)
18+
add_custom_command(
19+
OUTPUT BrowserEngine_i.c BrowserEngine.h
20+
COMMAND ${WIDL_EXECUTABLE} -h -H BrowserEngine.h "${CMAKE_CURRENT_LIST_DIR}/BrowserEngine.idl"
21+
COMMAND ${WIDL_EXECUTABLE} -c -o BrowserEngine_i.c "${CMAKE_CURRENT_LIST_DIR}/BrowserEngine.idl"
22+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
23+
DEPENDS "${CMAKE_CURRENT_LIST_DIR}/BrowserEngine.idl"
24+
VERBATIM
25+
)
26+
endif()
27+
else()
28+
# On non-Windows platforms, use widl (Wine IDL compiler)
29+
find_program(WIDL_EXECUTABLE widl REQUIRED)
430
add_custom_command(
531
OUTPUT BrowserEngine_i.c BrowserEngine.h
6-
COMMAND midl.exe "${CMAKE_CURRENT_LIST_DIR}\\BrowserEngine.idl" /header BrowserEngine.h
32+
COMMAND ${WIDL_EXECUTABLE} -h -H BrowserEngine.h "${CMAKE_CURRENT_LIST_DIR}/BrowserEngine.idl"
33+
COMMAND ${WIDL_EXECUTABLE} -c -o BrowserEngine_i.c "${CMAKE_CURRENT_LIST_DIR}/BrowserEngine.idl"
734
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
835
DEPENDS "${CMAKE_CURRENT_LIST_DIR}/BrowserEngine.idl"
936
VERBATIM
1037
)
38+
endif()
39+
40+
# Build the COM interface library using MinGW cross-compiler for Windows API compatibility
41+
find_program(MINGW_GCC i686-w64-mingw32-gcc)
42+
43+
if(MINGW_GCC)
44+
# Use MinGW cross-compiler to compile COM interface files
45+
message(STATUS "Using MinGW cross-compiler for COM interface compilation: ${MINGW_GCC}")
46+
47+
# Create custom command to compile BrowserEngine_i.c with MinGW
48+
add_custom_command(
49+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/BrowserEngine_i.o
50+
COMMAND ${MINGW_GCC} -c -I${CMAKE_CURRENT_BINARY_DIR}
51+
${CMAKE_CURRENT_BINARY_DIR}/BrowserEngine_i.c
52+
-o ${CMAKE_CURRENT_BINARY_DIR}/BrowserEngine_i.o
53+
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/BrowserEngine_i.c
54+
COMMENT "Compiling BrowserEngine_i.c with MinGW cross-compiler"
55+
)
56+
57+
# Create library from the MinGW-compiled object file
58+
add_library(core_browserenginewin STATIC ${CMAKE_CURRENT_BINARY_DIR}/BrowserEngine_i.o)
59+
set_target_properties(core_browserenginewin PROPERTIES
60+
OUTPUT_NAME browserenginewin
61+
LINKER_LANGUAGE C
62+
)
63+
64+
target_link_libraries(core_browserengine INTERFACE core_browserenginewin)
65+
66+
else()
67+
# Fallback: try to compile with regular GCC and MinGW-w64 headers
68+
message(WARNING "MinGW cross-compiler not found. Attempting compilation with regular GCC and MinGW-w64 headers.")
69+
1170
add_library(core_browserenginewin STATIC BrowserEngine_i.c)
1271
set_target_properties(core_browserenginewin PROPERTIES OUTPUT_NAME browserenginewin)
72+
73+
# Add MinGW-w64 headers for Windows API compatibility
74+
find_path(MINGW_W64_INCLUDE_DIR windows.h
75+
HINTS
76+
/usr/i686-w64-mingw32/include
77+
/usr/x86_64-w64-mingw32/include
78+
/usr/include/mingw
79+
DOC "MinGW-w64 include directory for Windows API compatibility"
80+
)
81+
82+
if(MINGW_W64_INCLUDE_DIR)
83+
target_include_directories(core_browserenginewin PRIVATE ${MINGW_W64_INCLUDE_DIR})
84+
message(STATUS "Using MinGW-w64 headers: ${MINGW_W64_INCLUDE_DIR}")
85+
endif()
86+
1387
target_link_libraries(core_browserengine INTERFACE core_browserenginewin)
1488
endif()
1589

Core/Tools/wolSetup/wolInit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ IChat *g_pChat = NULL;
192192
void checkInstalledWolapiVersion( void )
193193
{
194194
// Initialize this instance
195-
_Module.Init(NULL, g_hInst);
195+
_Module.Init(NULL, g_hInst, NULL);
196196

197197
// Create the WOLAPI instance
198198
CoCreateInstance(CLSID_Chat, NULL, CLSCTX_INPROC_SERVER, \

0 commit comments

Comments
 (0)