MSVC: Add cmake option for external manifests

This PR adds a cmake option `WITH_WINDOWS_EXTERNAL_MANIFEST`
which is off by default which addresses the following 2 problems:

The CI env occasionally fails to link the manifest into blender.exe
with mt.exe getting file in use error. The solutions mentioned online
vary wildly between, just rebuild, turn off your AV, use this magic
switch. None of them actually point to a root cause we can address.

When building blender with clang and the visual studio generator
it also somehow doesn't embed the manifest.

If the bots stay problematic this option can be turned on for the CI
environment, and will be automatically turned on when it detects clang
and the visual studio generator being used.

Pull Request: https://projects.blender.org/blender/blender/pulls/111683
This commit is contained in:
Ray molenkamp
2024-04-18 16:57:04 +02:00
parent 42c77b2107
commit 39c901407e
3 changed files with 33 additions and 3 deletions

View File

@@ -1040,6 +1040,9 @@ Include the files needed for debugging python scripts with visual studio 2017+."
option(WITH_WINDOWS_BUNDLE_CRT "Bundle the C runtime for install free distribution." ON)
mark_as_advanced(WITH_WINDOWS_BUNDLE_CRT)
option(WITH_WINDOWS_EXTERNAL_MANIFEST "Use external manifest files" OFF)
mark_as_advanced(WITH_WINDOWS_EXTERNAL_MANIFEST)
option(WITH_WINDOWS_SCCACHE "Use sccache to speed up builds (Ninja builder only)" OFF)
mark_as_advanced(WITH_WINDOWS_SCCACHE)

View File

@@ -12,6 +12,10 @@ endif()
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(MSVC_CLANG ON)
if(NOT WITH_WINDOWS_EXTERNAL_MANIFEST AND CMAKE_GENERATOR MATCHES "Visual Studio")
message(WARNING "WITH_WINDOWS_EXTERNAL_MANIFEST is required for clang and the visual studio generator, turning ON")
set(WITH_WINDOWS_EXTERNAL_MANIFEST ON)
endif()
set(VC_TOOLS_DIR $ENV{VCToolsRedistDir} CACHE STRING "Location of the msvc redistributables")
set(MSVC_REDIST_DIR ${VC_TOOLS_DIR})
if(DEFINED MSVC_REDIST_DIR)
@@ -87,6 +91,10 @@ string(APPEND CMAKE_EXE_LINKER_FLAGS " /SAFESEH:NO /ignore:4099")
string(APPEND CMAKE_SHARED_LINKER_FLAGS " /SAFESEH:NO /ignore:4099")
string(APPEND CMAKE_MODULE_LINKER_FLAGS " /SAFESEH:NO /ignore:4099")
if(WITH_WINDOWS_EXTERNAL_MANIFEST)
string(APPEND CMAKE_EXE_LINKER_FLAGS " /manifest:no")
endif()
list(APPEND PLATFORM_LINKLIBS
ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 Comctl32 version
advapi32 shfolder shell32 ole32 oleaut32 uuid psapi Dbghelp Shlwapi

View File

@@ -167,11 +167,15 @@ if(WIN32 AND NOT UNIX)
-DBLEN_VER_RC_4=0
)
list(APPEND SRC
${CMAKE_SOURCE_DIR}/release/windows/icons/winblender.rc
${CMAKE_BINARY_DIR}/blender.exe.manifest
)
if(NOT WITH_WINDOWS_EXTERNAL_MANIFEST)
list(APPEND SRC
${CMAKE_BINARY_DIR}/blender.exe.manifest
)
endif()
endif()
if(WITH_BUILDINFO)
@@ -342,8 +346,12 @@ else()
add_executable(blender-launcher WIN32
blender_launcher_win32.c
${CMAKE_SOURCE_DIR}/release/windows/icons/winblender.rc
${CMAKE_BINARY_DIR}/blender.exe.manifest
)
if(NOT WITH_WINDOWS_EXTERNAL_MANIFEST)
list(APPEND SRC
${CMAKE_BINARY_DIR}/blender.exe.manifest
)
endif()
target_compile_definitions (blender-launcher PRIVATE -D_UNICODE -DUNICODE)
target_link_libraries(blender-launcher Pathcch.lib)
endif()
@@ -978,6 +986,17 @@ file(REMOVE ${CMAKE_BINARY_DIR}/bin/lib/libglapi.so.0.0.0)\n
)
endif()
elseif(WIN32)
if(WITH_WINDOWS_EXTERNAL_MANIFEST)
install(
FILES ${CMAKE_BINARY_DIR}/blender.exe.manifest
DESTINATION "."
)
install(
FILES ${CMAKE_BINARY_DIR}/blender.exe.manifest
DESTINATION "."
RENAME blender-launcher.exe.manifest
)
endif()
windows_install_shared_manifest(
FILES ${LIBDIR}/epoxy/bin/epoxy-0.dll
ALL