@@ -23,14 +23,23 @@ set(SOURCES
2323 ../bundle_marker.cpp
2424 ./hostfxr_resolver.cpp
2525 ./hostpolicy_resolver.cpp
26+ ../../hostpolicy/static /coreclr_resolver.cpp
2627)
2728
2829set (HEADERS
2930 ../bundle_marker.h
3031 ../../../hostfxr_resolver.h
3132)
3233
33- list (APPEND SOURCES $<TARGET_OBJECTS:libhostfxr_static> $<TARGET_OBJECTS:libhostpolicy_static>)
34+ add_definitions (-D_NO_ASYNCRTIMP)
35+ add_definitions (-D_NO_PPLXIMP)
36+ add_definitions (-DEXPORT_SHARED_API=1)
37+ add_definitions (-DHOSTPOLICY_EMBEDDED)
38+
39+
40+ include (../../fxr/files .cmake)
41+ include (../../hostpolicy/files .cmake)
42+ include (../../hostcommon/files .cmake)
3443
3544if (CLR_CMAKE_TARGET_WIN32)
3645 list (APPEND SOURCES
@@ -46,12 +55,47 @@ include(configure.cmake)
4655add_definitions (-DFEATURE_APPHOST=1)
4756add_definitions (-DFEATURE_STATIC_HOST=1)
4857
49- # Disable manifest generation into the file .exe on Windows
5058if (CLR_CMAKE_TARGET_WIN32)
51- set_property (TARGET ${PROJECT_NAME} PROPERTY
52- LINK_FLAGS "/MANIFEST:NO"
59+ # Disable manifest generation into the file .exe on Windows
60+ add_linker_flag("/MANIFEST:NO" )
61+
62+ get_property (ALL_COMPILE_OPTIONS TARGET ${PROJECT_NAME} PROPERTY COMPILE_OPTIONS)
63+ string (TOUPPER ${RUNTIME_CONFIG} UPPERCASE_RUNTIME_CONFIG)
64+
65+ # make sure that certain compiler and linker settings match the runtime config
66+ # we need to ensure that to be able to link with coreclr in mixed builds (ex: Debug with Release runtime)
67+ if (UPPERCASE_RUNTIME_CONFIG STREQUAL DEBUG OR UPPERCASE_RUNTIME_CONFIG STREQUAL CHECKED)
68+ # add_compile_options(/MTd)
69+ # per-config options will win, so we have to use this syntax to override
70+ set_property (TARGET ${PROJECT_NAME} PROPERTY
71+ COMPILE_OPTIONS "${ALL_COMPILE_OPTIONS} ;$<$<CONFIG:DEBUG>:/MTd>"
72+ )
73+
74+ remove_definitions (-DNDEBUG)
75+ add_definitions (-DDEBUG -D_DEBUG -D_DBG)
76+
77+ # ignore runtime libraries that could have been added so far based on the config
78+ add_linker_flag("/NODEFAULTLIB:ucrt.lib" )
79+ add_linker_flag("/NODEFAULTLIB:libucrt.lib" )
80+ add_linker_flag("/NODEFAULTLIB:libcmt.lib" )
81+
82+ # make sure we use statically linked crt
83+ add_linker_flag("/DEFAULTLIB:libucrtd.lib" )
84+ else ()
85+ # add_compile_options(/MT)
86+ # per-config options will win, so we have to use this syntax to override
87+ set_property (TARGET ${PROJECT_NAME} PROPERTY
88+ COMPILE_OPTIONS "${ALL_COMPILE_OPTIONS} ;$<$<CONFIG:DEBUG>:/MT>"
5389 )
5490
91+ remove_definitions (-DDEBUG -D_DEBUG -D_DBG)
92+ add_definitions (-DNDEBUG)
93+
94+ # Force uCRT to be dynamically linked for Release build
95+ add_linker_flag("/NODEFAULTLIB:libucrt.lib" )
96+ add_linker_flag("/DEFAULTLIB:ucrt.lib" )
97+ endif ()
98+
5599 # Incremental linking results in the linker inserting extra padding and routing function calls via thunks that can break the
56100 # invariants (e.g. size of region between Jit_PatchedCodeLast-Jit_PatchCodeStart needs to fit in a page).
57101 add_linker_flag("/INCREMENTAL:NO" )
@@ -72,8 +116,6 @@ if(CLR_CMAKE_TARGET_WIN32)
72116 set (CORECLR_LIBRARIES
73117 ${CORECLR_STATIC_LIB_LOCATION} /coreclr_static.lib
74118 ${CORECLR_STATIC_LIB_LOCATION} /System .Globalization.Native.lib
75- ${STATIC_MT_CRT_LIB}
76- ${STATIC_MT_VCRT_LIB}
77119 kernel32.lib
78120 advapi32.lib
79121 ole32.lib
@@ -212,7 +254,6 @@ endif(NOT CLR_CMAKE_TARGET_LINUX)
212254set_property (TARGET singlefilehost PROPERTY ENABLE_EXPORTS 1)
213255
214256target_link_libraries (singlefilehost
215- libhostcommon
216257 ${CORECLR_LIBRARIES}
217258
218259 ${START_WHOLE_ARCHIVE}
0 commit comments