RPGHacker / asar

(Now) official repository of the SNES assembler Asar, originally created by Alcaro
Other
199 stars 42 forks source link

.ILK issue on MSVC after asar-standalone target renamed to asar #248

Closed Atari2 closed 2 years ago

Atari2 commented 2 years ago

As it turns out, the PDB was not the only thing the name change broke, it also broke the .ILK file mechanism that MSVC uses for incremental linking. image Since the dll and the exe now use the same .ilk file for incremental linking and the build is parallelized, sometimes (not always, since the access isn't always concurrent) randomly during link it will error out because the two linking processes will be fighting to access the .LNK file. However since CMake doesn't give you a way to change the .LNK name (I'm not even sure if it's possible in the first place), I don't know an easy fix. I thought about simply instructing CMake to copy & rename the .exe after compilation.(note that I said copy instead of just rename because this way it doesn't break anything IDE related that relies on the executable having the same name as the CMake target that generated it, such as Visual Studio's Run&Debug feature). Such a change would look like this: (after reverting commit 2e24afbda259e29dc12b1c287b1ab9984c561e3f and commit 9768f19d1b895887ce53dca8a23601d6ed83a097)

# inside if (ASAR_GEN_EXE)
add_custom_command(
  TARGET asar-standalone
  POST_BUILD
  COMMAND ${CMAKE_COMMAND} -E copy_if_different asar-standalone${CMAKE_EXECUTABLE_SUFFIX} asar${CMAKE_EXECUTABLE_SUFFIX}
  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  COMMENT "Copying and renaming asar standalone executable file"
)
RPGHacker commented 2 years ago

Crap! 😞 I guess the ideal solution here would be for us to move each build target to its own output folder. If we do that, we can also remove the .pdb rename from the previous commit again, since it should no longer be needed. We'd once again have to adjust the paths for all CI configs, though, which stinks a bit.

Atari2 commented 2 years ago

Yeah giving each target its own output folder sounds like the best idea tbh. We'd just need something like

    set_target_properties(asar-standalone
        PROPERTIES
        OUTPUT_NAME "asar"
        ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/standalone"
        LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/standalone"
        RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/standalone"
    )

in the ASAR_GEN_EXE if and something like

    set_target_properties(asar
        PROPERTIES
        OUTPUT_NAME "asar"
        ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/library"
        LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/library"
        RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/library"
    )

in the ASAR_GEN_DLL if (the OUTPUT_NAME in the second one is useless but I added it for consistency purposes). Doing this works fine, avoids any name clashing and creates two folders each with the .exe/.dll, their respective .pbds, .exp and .lib files.