loader: Fix cross-compiling with jwasm
authorChristopher Degawa <ccom@randomderp.com>
Mon, 2 Oct 2023 02:38:28 +0000 (21:38 -0500)
committerCharles Giessen <46324611+charles-lunarg@users.noreply.github.com>
Wed, 4 Oct 2023 17:34:16 +0000 (11:34 -0600)
fixes a few issues when cross-compiling from linux to windows using
mingw-w64. Particularly with the result of jwasm not being used in the
library. Additionally, allows running the generated asm_offset binary
with wine, if the user provided the wrapper in their toolchain with
`-DCMAKE_CROSSCOMPILING_EMULATOR=wine`.

Signed-off-by: Christopher Degawa <ccom@randomderp.com>
loader/CMakeLists.txt

index 7ccfbed875ea648a293db6a423315d3d80427284..d7d6383d4566d5a1d59c8c03304aefebc7a206db 100644 (file)
@@ -115,8 +115,9 @@ set(ASM_FAILURE_MSG "${ASM_FAILURE_MSG}Note that this may be unsafe, as the C co
 set(ASM_FAILURE_MSG "${ASM_FAILURE_MSG} the stack frame for certain calls. If the compiler does not do this, then unknown device")
 set(ASM_FAILURE_MSG "${ASM_FAILURE_MSG} extensions will suffer from a corrupted stack.")
 if(WIN32)
-    if(MINGW)
-        find_program(JWASM_FOUND jwasm)
+    option(USE_MASM "Use MASM" ON)
+    if(USE_MASM AND MINGW)
+        find_program(JWASM_FOUND NAMES jwasm)
         if (JWASM_FOUND)
             set(CMAKE_ASM_MASM_COMPILER ${JWASM_FOUND})
             execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpmachine OUTPUT_VARIABLE COMPILER_VERSION_OUTPUT)
@@ -130,14 +131,10 @@ if(WIN32)
             endif()
         endif()
     endif()
-    if (NOT MSVC)
-        set(USE_MASM OFF)
-    endif ()
-    option(USE_MASM "Use MASM" ON)
     if (USE_MASM)
-      enable_language(ASM_MASM)
-    endif ()
-    if(CMAKE_ASM_MASM_COMPILER_WORKS OR JWASM_FOUND)
+        enable_language(ASM_MASM)
+    endif()
+    if(CMAKE_ASM_MASM_COMPILER_WORKS)
         if(MINGW)
             set(CMAKE_ASM_MASM_FLAGS ${CMAKE_ASM_MASM_FLAGS} ${JWASM_FLAGS})
         elseif(NOT CMAKE_CL_64 AND NOT JWASM_FOUND)
@@ -146,8 +143,8 @@ if(WIN32)
 
         add_executable(asm_offset asm_offset.c)
         target_link_libraries(asm_offset PRIVATE loader_specific_options)
-        # If not cross compiling, run asm_offset to generage gen_defines.asm
-        if (NOT CMAKE_CROSSCOMPILING)
+        # If am emulator is provided (Like Wine), or running on native, run asm_offset to generate gen_defines.asm
+        if (CMAKE_CROSSCOMPILING_EMULATOR OR NOT CMAKE_CROSSCOMPILING)
             add_custom_command(OUTPUT gen_defines.asm DEPENDS asm_offset COMMAND asm_offset MASM)
         else()
             # Forces compiler to write the intermediate asm file, needed so that we can get sizeof/offset of info out of it.
@@ -279,11 +276,7 @@ if(WIN32)
         set(RC_FILE_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/loader.rc)
     endif()
 
-    if (MSVC)
-        set(LOADER_UNKNOWN_CHAIN_LIBRARY $<TARGET_OBJECTS:loader-unknown-chain>)
-    else()
-        set(LOADER_UNKNOWN_CHAIN_LIBRARY "")
-    endif()
+    set(LOADER_UNKNOWN_CHAIN_LIBRARY $<$<TARGET_EXISTS:loader-unknown-chain>:$<TARGET_OBJECTS:loader-unknown-chain>>)
 
     add_library(vulkan
                 SHARED