Fix MSBuild integration for the host build with CMake 3.26 (#88208)
authorJeremy Koritzinsky <jekoritz@microsoft.com>
Thu, 29 Jun 2023 23:05:19 +0000 (16:05 -0700)
committerGitHub <noreply@github.com>
Thu, 29 Jun 2023 23:05:19 +0000 (16:05 -0700)
eng/native/ijw/IJW.cmake
eng/native/ijw/SetIJWProperties.props [new file with mode: 0644]
src/native/corehost/test/ijw/CMakeLists.txt
src/tests/Interop/IJW/CopyConstructorMarshaler/CMakeLists.txt
src/tests/Interop/IJW/IjwNativeDll/CMakeLists.txt
src/tests/Interop/IJW/NativeVarargs/CMakeLists.txt

index 9a38a18..4222b9b 100644 (file)
@@ -31,6 +31,19 @@ if (CLR_CMAKE_HOST_WIN32)
     set_target_properties(${targetName} PROPERTIES COMPILE_OPTIONS "${compileOptions}")
   endfunction()
 
+  function(add_ijw_msbuild_project_properties targetName ijwhost_target)
+    # When we're building with MSBuild, we need to set some project properties
+    # in case CMake has decided to use the SDK support.
+    # We're dogfooding things, so we need to set settings in ways that the product doesn't quite support.
+    # We don't actually need an installed/available target framework version here
+    # since we are disabling implicit framework references. We just need a valid value, and net8.0 is valid.
+    set_target_properties(${targetName} PROPERTIES
+      DOTNET_TARGET_FRAMEWORK net8.0
+      VS_GLOBAL_DisableImplicitFrameworkReferences true
+      VS_GLOBAL_GenerateRuntimeConfigurationFiles false
+      VS_PROJECT_IMPORT "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/SetIJWProperties.props")
+  endfunction()
+
   # 4365 - signed/unsigned mismatch
   # 4679 - Could not import member. This is an issue with IJW and static abstract methods in interfaces.
   add_compile_options(/wd4365 /wd4679)
diff --git a/eng/native/ijw/SetIJWProperties.props b/eng/native/ijw/SetIJWProperties.props
new file mode 100644 (file)
index 0000000..d18ba7f
--- /dev/null
@@ -0,0 +1,6 @@
+<Project>
+  <PropertyGroup>
+    <!-- The C++/CLI targets don't let us set this in the project file where CMake lets us set project properties, so we set it in an imported project file where it will work. -->
+    <UseIJWHost>false</UseIJWHost>
+  </PropertyGroup>
+</Project>
\ No newline at end of file
index e9f43e2..9e90cfd 100644 (file)
@@ -12,5 +12,6 @@ add_library(ijw SHARED ${SOURCES})
 target_link_libraries(ijw PRIVATE ${LINK_LIBRARIES_ADDITIONAL})
 
 remove_ijw_incompatible_target_options(ijw)
+add_ijw_msbuild_project_properties(ijw ijwhost)
 
 install_with_stripped_symbols(ijw TARGETS corehost_test)
index 3f9c1d9..d082f7c 100644 (file)
@@ -7,6 +7,7 @@ set(SOURCES IjwCopyConstructorMarshaler.cpp)
 # add the shared library
 add_library (IjwCopyConstructorMarshaler SHARED ${SOURCES})
 target_link_libraries(IjwCopyConstructorMarshaler PRIVATE ${LINK_LIBRARIES_ADDITIONAL})
+add_ijw_msbuild_project_properties(IjwCopyConstructorMarshaler ijwhost)
 
 # add the install targets
 install (TARGETS IjwCopyConstructorMarshaler DESTINATION bin)
index c588e57..a8eee97 100644 (file)
@@ -7,6 +7,7 @@ set(SOURCES IjwNativeDll.cpp)
 # add the shared library
 add_library (IjwNativeDll SHARED ${SOURCES})
 target_link_libraries(IjwNativeDll PRIVATE ${LINK_LIBRARIES_ADDITIONAL})
+add_ijw_msbuild_project_properties(IjwNativeDll ijwhost)
 
 # add the install targets
 install (TARGETS IjwNativeDll DESTINATION bin)
index 17929bf..a3c7c97 100644 (file)
@@ -7,6 +7,7 @@ set(SOURCES IjwNativeVarargs.cpp)
 # add the shared library
 add_library (IjwNativeVarargs SHARED ${SOURCES})
 target_link_libraries(IjwNativeVarargs PRIVATE ${LINK_LIBRARIES_ADDITIONAL})
+add_ijw_msbuild_project_properties(IjwNativeVarargs ijwhost)
 
 # add the install targets
 install (TARGETS IjwNativeVarargs DESTINATION bin)