Skip to content

Commit 6885bdc

Browse files
authored
Merge pull request scp-fs2open#7442 from Goober5000/7334_followup
fix FRED2 MFC linkage when building qtFRED
2 parents 98aac12 + f4c76dc commit 6885bdc

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

cmake/toolchain-msvc.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ if (MSVC_RELEASE_DEBUGGING)
7171
endif()
7272
endif()
7373

74+
# This should be kept in sync with the corresponding IF() in fred2/CMakeLists.txt
7475
IF(MSVC_USE_RUNTIME_DLL OR FSO_BUILD_QTFRED)
7576
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<NOT:$<CONFIG:Release>>:Debug>DLL")
7677
add_compile_definitions(_AFXDLL)

fred2/CMakeLists.txt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,12 @@ set_source_files_properties(fred.rc PROPERTIES
164164
LANGUAGE RC
165165
)
166166

167-
IF(MSVC_USE_RUNTIME_DLL)
167+
# This should be kept in sync with the corresponding IF() in cmake/toolchain-msvc.cmake
168+
IF(MSVC_USE_RUNTIME_DLL OR FSO_BUILD_QTFRED)
168169
set(CMAKE_MFC_FLAG 2)
169-
ELSE(MSVC_USE_RUNTIME_DLL)
170+
ELSE()
170171
set(CMAKE_MFC_FLAG 1)
171-
ENDIF(MSVC_USE_RUNTIME_DLL)
172+
ENDIF()
172173

173174
IF(MSVC60)
174175
link_directories(${STLPORT_INCLUDE_LIB_DIRS})
@@ -197,8 +198,15 @@ FIND_PACKAGE(OpenGL REQUIRED)
197198
target_link_libraries(FRED2 PUBLIC "${OPENGL_LIBRARY}")
198199

199200
TARGET_LINK_LIBRARIES(FRED2 PUBLIC code) # This will also link all dependencies of code
200-
TARGET_LINK_LIBRARIES(FRED2 PUBLIC "$<$<NOT:$<CONFIG:Release>>:nafxcwd.lib>")
201-
TARGET_LINK_LIBRARIES(FRED2 PUBLIC "$<$<CONFIG:Release>:nafxcw.lib>")
201+
202+
# When CMAKE_MFC_FLAG=2 (DLL MFC) MSBuild already links the DLL MFC stub libs (mfcs*.lib);
203+
# explicitly adding the static MFC libs (nafxcw*) on top causes IsDerivedFrom to be resolved
204+
# from the static MFC copy while CRuntimeClass structs are initialized in the DLL form,
205+
# crashing CDocTemplate's ctor on startup.
206+
IF(NOT (MSVC_USE_RUNTIME_DLL OR FSO_BUILD_QTFRED))
207+
TARGET_LINK_LIBRARIES(FRED2 PUBLIC "$<$<NOT:$<CONFIG:Release>>:nafxcwd.lib>")
208+
TARGET_LINK_LIBRARIES(FRED2 PUBLIC "$<$<CONFIG:Release>:nafxcw.lib>")
209+
ENDIF()
202210

203211
target_link_libraries(FRED2 PUBLIC glad_wgl)
204212

0 commit comments

Comments
 (0)