Skip to content
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

wrap CMP0091 in MSVC check #1580

Merged
merged 9 commits into from
Feb 11, 2021
Merged

Conversation

danewalton
Copy link
Member

fixes #1514

CMakeLists.txt Outdated
Comment on lines 47 to 53
if(MSVC)
# Use the static runtime libraries when building statically for consistency with vcpkg's
# arch-windows-static triplets:
cmake_policy(SET CMP0091 NEW) # https://cmake.org/cmake/help/v3.15/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html
if (NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure why the windows CI legs are now failing with that linker warning on Windows:
https://dev.azure.com/azure-sdk/public/_build/results?buildId=705929&view=logs&j=1822ef0b-3ac4-586f-233b-6fdf166a140f&t=b129bef7-7ee0-56b0-68be-0867e926d36b&l=102

LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library [D:\vss\_work\1\s\build\sdk\tests\iot\provisioning\az_iot_provisioning_test.vcxproj]
LINK : error LNK1218: warning treated as error; no output file generated [D:\vss\_work\1\s\build\sdk\tests\iot\provisioning\az_iot_provisioning_test.vcxproj]
##[error]Cmd.exe exited with code '1'.

Presumable if (MSVC) condition is returning false, but I don't know why. I wonder if you need to do something like this instead: if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC"). Try some tests @danewalton using message(...) to see if we actually enter those code blocks.

@BillyONeal maybe you have some ideas.

Copy link
Member

@antkmsft antkmsft Jan 27, 2021

Choose a reason for hiding this comment

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

I know! MSVC is not defined before the line saying project(az LANGUAGES C). @danewalton, try moving the check after that line, it should work.

@antkmsft
Copy link
Member

antkmsft commented Jan 27, 2021

MSVC is not defined before the project(... C), but the CMP0091 and CMAKE_MSVC_RUNTIME_LIBRARY things that we do has to be done before the project(... C), or they have no effect. The real problem even on ubuntu is that we use a feature from cmake 3.15, while claiming that we need cmake 3.10, so when customer who has exactly cmake 3.10 tries to build it, even for Ubuntu, there are errors. I bet if you try to build for MSVC having cmake 3.10, you get the same error. The proper fix would be to either bump up the cmake version to 3.15, or to introduce an optional build parameter that only has effect during the MSVC builds and indicates which runtime the user wants to link with. I've seen other libraries using that approach, I think we should do it too. We have the same problem that needs to be solved for the C++ repo (Azure/azure-sdk-for-cpp#1223).

@danewalton danewalton requested review from danieljurek and a team as code owners February 10, 2021 23:24
@danewalton
Copy link
Member Author

@ahsonkhan @antkmsft thoughts here? Latest addition seems to be working

@danewalton
Copy link
Member Author

@ahsonkhan @antkmsft thoughts here? Latest addition seems to be working

just checked with Ubuntu 18.04 and looks to be working

image

Comment on lines +9 to +13
add_compile_options(
$<$<CONFIG:>:/MT> #---------|
$<$<CONFIG:Debug>:/MTd> #---|-- Statically link the runtime libraries
$<$<CONFIG:Release>:/MT> #--|
)
Copy link
Member

Choose a reason for hiding this comment

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

@barcharcraz and @BillyONeal - can you please help review and sign-off on this approach.

Copy link
Member Author

Choose a reason for hiding this comment

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

Just for reference I pulled it from here:
https://gitlab.kitware.com/cmake/cmake/-/issues/18390

CMakeLists.txt Outdated
Comment on lines 50 to 57
if(MSVC OR WIN32)
# Use the static runtime libraries when building statically for consistency with vcpkg's
# arch-windows-static triplets:
cmake_policy(SET CMP0091 NEW) # https://cmake.org/cmake/help/v3.15/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html
if (NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
endif()
Copy link
Member

Choose a reason for hiding this comment

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

If we are explicitly adding some compile options in global_compile_options, do we need to set cmake_policy anymore?

Copy link
Member Author

Choose a reason for hiding this comment

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

testing

@danewalton danewalton merged commit da74369 into Azure:master Feb 11, 2021
@danewalton
Copy link
Member Author

Merging for now but let me know if this needs to be changed

@danewalton danewalton deleted the dawalton/msvc branch February 11, 2021 15:38
@@ -44,13 +44,6 @@ if(DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET)
set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "")
endif()

# Use the static runtime libraries when building statically for consistency with vcpkg's
Copy link
Member

Choose a reason for hiding this comment

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

Consider including this fix in a changelog entry.

Copy link
Member

@ahsonkhan ahsonkhan Feb 12, 2021

Choose a reason for hiding this comment

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

Done in #1605

Thanks @danewalton

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SDK no longer builds on Ubuntu 18.04
5 participants