Skip to content

Commit ca63076

Browse files
committed
Support cross-compiling the C++ tests for Windows
With built-in handling for MinGW.
1 parent f97a812 commit ca63076

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

ffi/CMakeLists.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,23 @@ elseif(WIN32)
1010
set(SYSTEM_LIBS ntdll ws2_32)
1111
endif()
1212

13-
set(TARGET_PATH "${CMAKE_SOURCE_DIR}/../target")
13+
if(CMAKE_CROSSCOMPILING AND NOT DEFINED RUST_TARGET)
14+
if(WIN32 AND MINGW AND CMAKE_SIZEOF_VOID_P EQUAL 8)
15+
set(RUST_TARGET "x86_64-pc-windows-gnu")
16+
elseif(WIN32 AND MINGW AND CMAKE_SIZEOF_VOID_P EQUAL 4)
17+
set(RUST_TARGET "i686-pc-windows-gnu")
18+
else()
19+
message(FATAL_ERROR "Cross-compiling without RUST_TARGET set, and an appropriate value could not be set automatically!")
20+
endif()
21+
endif()
22+
23+
if(DEFINED RUST_TARGET)
24+
message(STATUS "Building for Rust target ${RUST_TARGET}")
25+
set(TARGET_PATH "${PROJECT_SOURCE_DIR}/../target/${RUST_TARGET}")
26+
else()
27+
set(TARGET_PATH "${PROJECT_SOURCE_DIR}/../target")
28+
endif()
29+
1430
set(LIBLOADORDER_FFI_LIB_NAME "${CMAKE_STATIC_LIBRARY_PREFIX}loadorder_ffi${CMAKE_STATIC_LIBRARY_SUFFIX}")
1531

1632
add_library(libloadorder_ffi INTERFACE)

0 commit comments

Comments
 (0)