Skip to content

Allow ML.NET native binaries to work on Windows machines that don't have the VC runtime installed. #1828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ if(WIN32)
add_compile_options($<$<CONFIG:Release>:-DNDEBUG>)
add_compile_options($<$<CONFIG:RelWithDebInfo>:-DNDEBUG>)
add_compile_options($<$<CONFIG:Debug>:/Od>)
add_compile_options($<$<CONFIG:Debug>:/MTd>) # /MT will static link the VC runtime library, so it doesn't need to be installed on the target machine
add_compile_options($<$<CONFIG:Release>:/MT>)
add_compile_options($<$<CONFIG:RelWithDebInfo>:/MT>)
add_compile_options(/guard:cf)
add_compile_options(/d2Zi+) # make optimized builds debugging easier
add_compile_options(/nologo) # Suppress Startup Banner
Expand Down Expand Up @@ -62,6 +65,8 @@ if(WIN32)
list(APPEND RESOURCES ${CMAKE_SOURCE_DIR}/../../Tools/NativeVersion.rc)
else()
add_compile_options(-Wno-unused-local-typedef)
add_compile_options(-fPIC)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally missed these setting because I copied the "common" CMake file from dotnet/core-setup. However, /MT for Windows and these two settings on Unix aren't in the common CMake file in that repo, but are spread to the individual CMake files for each library:

https://github.com/dotnet/core-setup/blob/8fe49b4211abaa649784966a4f6b55a38a237d9e/src/corehost/cli/hostpolicy/CMakeLists.txt#L7-L14
https://github.com/dotnet/core-setup/blob/8fe49b4211abaa649784966a4f6b55a38a237d9e/src/corehost/cli/fxr/CMakeLists.txt#L7-L14

Which is why they were overlooked originally.

add_compile_options(-fvisibility=hidden)
add_definitions(-Werror) # treat warnings as errors
endif()

Expand Down