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

Fix build for MSVC 19.42 #377

Merged
merged 2 commits into from
Dec 5, 2024
Merged

Fix build for MSVC 19.42 #377

merged 2 commits into from
Dec 5, 2024

Conversation

AVAtarMod
Copy link
Contributor

@AVAtarMod AVAtarMod commented Dec 5, 2024

I cannot build async_mqtt without this fix. It may not work at old MSVC version, but I could not find information about version of MSVC which adds used options.

@redboltz redboltz self-requested a review December 5, 2024 07:19
Copy link
Owner

@redboltz redboltz left a comment

Choose a reason for hiding this comment

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

@AVAtarMod Thank you for sending the PR.

I set some of compiler options for MSVC on CI.
See

$env:CL="/D_WIN32_WINNT#0x0A00 /DBOOST_THREAD_VERSION#3 /DBOOST_ASIO_NO_DEPRECATED /bigobj /EHsc /Zc:preprocessor"

They should be defined to build separate compilation library too.

/Zc:preprocessor /bigobj have already been added in your PR. Could you add the rest of options?


get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(is_multi_config)
if ($<STREQUAL:$<CXX_COMPILER_ID>,"MSVC">)
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
if ($<STREQUAL:$<CXX_COMPILER_ID>,"MSVC">)
if (MSVC)

async_mqtt uses MSVC at other place. So if you can use it here, please use it.
See https://cmake.org/cmake/help/latest/variable/MSVC.html

Copy link
Contributor Author

@AVAtarMod AVAtarMod Dec 5, 2024

Choose a reason for hiding this comment

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

I remove this multi-config check.

Comment on lines 22 to 28
macro(fix_msvc_build)
message(STATUS "MSVC build fix applied")
target_compile_options(async_mqtt_separate PRIVATE "/Zc:preprocessor" "/bigobj")
endmacro()

get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(is_multi_config)
Copy link
Owner

Choose a reason for hiding this comment

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

It seems that this part is for the different way to get CMAKE_CXX_COMPILER_ID.
I am not 100% sure but MSVC could be used for both, if it is right, this part of code could be removed.
And the contents of the macro could be moved into if (MSVC) part.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, MSVC could be used, but as far as I know, this is legacy method

Copy link
Owner

Choose a reason for hiding this comment

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

Oh really, I will update exsiting if (MSVC) code later.

@AVAtarMod
Copy link
Contributor Author

@AVAtarMod Thank you for sending the PR.

I set some of compiler options for MSVC on CI. See

$env:CL="/D_WIN32_WINNT#0x0A00 /DBOOST_THREAD_VERSION#3 /DBOOST_ASIO_NO_DEPRECATED /bigobj /EHsc /Zc:preprocessor"

They should be defined to build separate compilation library too.

/Zc:preprocessor /bigobj have already been added in your PR. Could you add the rest of options?

Why we need /D_WIN32_WINNT#0x0A00 /DBOOST_THREAD_VERSION#3 /DBOOST_ASIO_NO_DEPRECATED /EHsc ?

@redboltz
Copy link
Owner

redboltz commented Dec 5, 2024

Why we need /D_WIN32_WINNT#0x0A00 /DBOOST_THREAD_VERSION#3 /DBOOST_ASIO_NO_DEPRECATED /EHsc ?

I realized I was mistaken.

I now believe these options should be left to the user's discretion. If users want to enable them, they can pass them as CMake arguments via CMAKE_CXX_FLAGS. You've already chosen the minimal mandatory options.

Please keep the original code unchanged in this regard.

@redboltz redboltz merged commit 455c155 into redboltz:main Dec 5, 2024
11 checks passed
@redboltz
Copy link
Owner

redboltz commented Dec 5, 2024

Merged. Thank you for your contribution.

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

Successfully merging this pull request may close these issues.

2 participants