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

Add cmake-init generated CMake files #4

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

ClausKlein
Copy link
Owner

@ClausKlein ClausKlein commented Nov 29, 2024

  • Add and use cmake workflow presets file
  • Use CMAKE_VERIFY_INTERFACE_HEADER_SETS
  • Use ccache if available
  • use debug postfix
  • install libray to lib
  • install less verbose
  • test installed cmake config package
  • install the c++20 CXX_MODULE
  • compiles with Apple clang version 16.0.0 (std=c++2b, but no CXX_MODULE support yet!)
  • compiles with clang version 19.1.4 (std=c++2b)
  • MSVC works on CI (std=c++20, but fails to compile the CXX_MODULE)
  • Activate the find installed CXX_MODULE test on CI!
  • g++-14 fails on macOS with both versions?

see too https://anarthal.github.io/cppblog/modules2

and fmt-module

Add and use cmake workflow presets file

Add CMAKE_VERIFY_INTERFACE_HEADER_SETS

Use ccache if available
Install cmake config package to <prefix>/lib
Install files less verbose
Add examples to cmake project
Use debug postfix for install asio library
@ClausKlein ClausKlein force-pushed the feature/update-cmake-asio-version branch from ef14579 to 7fcf4a4 Compare November 29, 2024 18:14
@ClausKlein ClausKlein marked this pull request as ready for review November 29, 2024 18:16
Comment on lines +1 to +6
module;

#include <asio.hpp>
#include <asio/ssl.hpp>

export module asio;
Copy link
Owner Author

@ClausKlein ClausKlein Nov 30, 2024

Choose a reason for hiding this comment

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

NOTE: the asio module

but MSVC does not compile it:

[5/8] Building CXX object CMakeFiles\asio_module.dir\D_\a\asio\asio\asio\stagedir\lib\cmake\asio\module\asio.cppm.obj
asio.cppm
Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. For example:
- add -D_WIN32_WINNT=0x0601 to the compiler command line; or
- add _WIN32_WINNT=0x0601 to your project's Preprocessor Definitions.
Assuming _WIN32_WINNT=0x0601 (i.e. Windows 7 target).
D:\a\asio\asio\asio\stagedir\include\asio/detail/impl/win_mutex.ipp(39): note: sorry: 'inline' function definition for 
'int asio::detail::win_mutex::do_init(void)' could not be written to module due to unrecognized expression
 or statement at 'D:\a\asio\asio\asio\stagedir\include\asio/detail/impl/win_mutex.ipp(55)'.
If possible please provide a repro here: https://developercommunity.visualstudio.com/

Add wrapper for CXX_MODULES

The example module test needs oppenssl
@ClausKlein ClausKlein force-pushed the feature/update-cmake-asio-version branch 2 times, most recently from ca7d2ae to 3dd1161 Compare November 30, 2024 17:47
MSVC supports CXX_MODULES too, give it a try
@ClausKlein ClausKlein force-pushed the feature/update-cmake-asio-version branch from 1dce944 to 3de812a Compare November 30, 2024 19:02
@ClausKlein ClausKlein force-pushed the feature/update-cmake-asio-version branch from 45ea47e to bf27e93 Compare December 1, 2024 18:50
use try {} catch() {}
@ClausKlein ClausKlein force-pushed the feature/update-cmake-asio-version branch from 33e17ec to 47d4cd3 Compare December 1, 2024 20:18
@ClausKlein
Copy link
Owner Author

Windows makes me crazy:

FAILED: CMakeFiles/main.dir/main.cpp.obj 
C:\PROGRA~1\MICROS~2\2022\ENTERP~1\VC\Tools\MSVC\1442~1.344\bin\Hostx64\x64\cl.exe  /nologo /TP -DASIO_DISABLE_BOOST_CONTEXT_FIBER -DASIO_HAS_SNPRINTF -DASIO_NO_DEPRECATED -DUSE_MODULES -external:I"C:\Program Files\OpenSSL\include" -external:W0 /DWIN32 /D_WINDOWS /EHsc /Ob0 /Od /RTC1 -std:c++latest -MDd -Zi /showIncludes @CMakeFiles\main.dir\main.cpp.obj.modmap /FoCMakeFiles\main.dir\main.cpp.obj /FdCMakeFiles\main.dir\ /FS -c D:\a\asio\asio\asio\module\tests\main.cpp
D:\a\asio\asio\asio\module\tests\main.hpp(36): error C2039: 'stream_truncated': is not a member of 'asio::ssl::error'
D:\a\asio\asio\asio\stagedir\lib\cmake\asio\module\asio.cppm(66): note: see declaration of 'asio::ssl::error'
D:\a\asio\asio\asio\module\tests\main.hpp(36): error C2065: 'stream_truncated': undeclared identifier
D:\a\asio\asio\asio\module\tests\main.hpp(44): error C2039: 'promise_type': is not a member of 'std::coroutine_traits<asio::awaitable<void,asio::any_io_executor>,asio::ip::tcp::socket>'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.42.34433\include\coroutine(46): note: see declaration of 'std::coroutine_traits<asio::awaitable<void,asio::any_io_executor>,asio::ip::tcp::socket>'
D:\a\asio\asio\asio\module\tests\main.hpp(58): error C2039: 'promise_type': is not a member of 'std::coroutine_traits<asio::awaitable<void,asio::any_io_executor>>'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.42.34433\include\coroutine(46): note: see declaration of 'std::coroutine_traits<asio::awaitable<void,asio::any_io_executor>>'
D:\a\asio\asio\asio\module\tests\main.hpp(63): error C2440: 'initializing': cannot convert from 'initializer list' to 'asio::basic_socket_acceptor<asio::ip::tcp,asio::any_io_executor>'

Use ssl::error::make_error_code()

Be less pedantic on Windows
@ClausKlein ClausKlein force-pushed the feature/update-cmake-asio-version branch from a06ec59 to 3846d69 Compare December 2, 2024 08:32
@anarthal
Copy link
Collaborator

anarthal commented Dec 2, 2024

I encountered and reported the first error you mention: https://developercommunity.visualstudio.com/t/Using-__try-in-an-inline-function-in-a-h/10186252
It's supposedly fixed but not released.
The other ones are likely a problem with the "export using" approach, which I believe can't be used with MSVC. I think what you're encountering is what I describe here: https://anarthal.github.io/cppblog/modules2#template-spec

@ClausKlein
Copy link
Owner Author

Thank you!

@ClausKlein ClausKlein requested a review from anarthal December 2, 2024 16:12
Copy link
Owner Author

@ClausKlein ClausKlein left a comment

Choose a reason for hiding this comment

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

Is this OK?

@@ -64,10 +64,11 @@ int win_mutex::do_init()
return ::GetLastError();
# endif
}
__except(GetExceptionCode() == STATUS_NO_MEMORY
? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
catch (const std::bad_alloc&)
Copy link
Owner Author

Choose a reason for hiding this comment

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

@anarthal This was my quick solution for ths MSVC inline problem

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like GitHub had an issue yesterday, I got some 500 errors when trying to post my comments.

This doesn't do what you'd expect. SEH __catch clauses do catch C++ exceptions, but C++ catch doesn't catch SEH exceptions AFAIK. There's no std::bad_alloc exception in SEH to begin with.

If I'm not mistaken, the SEH handler there is only relevant for Windows XP/Windows Server 2003 and previous versions (see the InitializeCriticalSection docs). I don't think you can target these systems with a C++20 compiler, so you can likely remove the SEH try/catch in your prototype without loss of functionality.

@@ -111,12 +111,15 @@ int win_static_mutex::do_init()
}
# endif
}
__except(GetExceptionCode() == STATUS_NO_MEMORY
? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
catch (const std::bad_alloc&)
Copy link
Owner Author

Choose a reason for hiding this comment

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

@anarthal This was my quick solution for ths MSVC inline problem

Copy link
Collaborator

Choose a reason for hiding this comment

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

Same applies here.

@ClausKlein
Copy link
Owner Author

ClausKlein commented Dec 2, 2024

The remaining problem seems a const problem to be:

cannot convert argument 1 from 'asio::this_coro::executor_t' to 'const asio::any_io_executor &'

C:\PROGRA~1\MICROS~2\2022\ENTERP~1\VC\Tools\MSVC\1442~1.344\bin\Hostx64\x64\cl.exe  /nologo /TP -DASIO_DISABLE_BOOST_CONTEXT_FIBER -DASIO_HAS_SNPRINTF -DASIO_NO_DEPRECATED -DUSE_MODULES -external:I"C:\Program Files\OpenSSL\include" -external:W0 /DWIN32 /D_WINDOWS /EHsc /Ob0 /Od /RTC1 -std:c++latest -MDd -Zi /showIncludes @CMakeFiles\main.dir\main.cpp.obj.modmap /FoCMakeFiles\main.dir\main.cpp.obj /FdCMakeFiles\main.dir\ /FS -c D:\a\asio\asio\asio\module\tests\main.cpp
D:\a\asio\asio\asio\module\tests\main.hpp(49): error C2039: 'promise_type': is not a member of 'std::coroutine_traits<asio::awaitable<void,asio::any_io_executor>,asio::ip::tcp::socket>'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.42.34433\include\coroutine(46): note: see declaration of 'std::coroutine_traits<asio::awaitable<void,asio::any_io_executor>,asio::ip::tcp::socket>'
D:\a\asio\asio\asio\module\tests\main.hpp(58): error C2039: 'promise_type': is not a member of 'std::coroutine_traits<asio::awaitable<void,asio::any_io_executor>>'
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.42.34433\include\coroutine(46): note: see declaration of 'std::coroutine_traits<asio::awaitable<void,asio::any_io_executor>>'
D:\a\asio\asio\asio\module\tests\main.hpp(63): error C2440: 'initializing': cannot convert from 'initializer list' to 'asio::basic_socket_acceptor<asio::ip::tcp,asio::any_io_executor>'
D:\a\asio\asio\asio\module\tests\main.hpp(63): note: 'asio::basic_socket_acceptor<asio::ip::tcp,asio::any_io_executor>::basic_socket_acceptor': no overloaded function could convert all the argument types
D:\a\asio\asio\asio\stagedir\include\asio\basic_socket_acceptor.hpp(134): note: could be 'asio::basic_socket_acceptor<asio::ip::tcp,asio::any_io_executor>::basic_socket_acceptor(const asio::any_io_executor &)'
D:\a\asio\asio\asio\module\tests\main.hpp(63): note: 'asio::basic_socket_acceptor<asio::ip::tcp,asio::any_io_executor>::basic_socket_acceptor(const asio::any_io_executor &)': cannot convert argument 1 from 'asio::this_coro::executor_t' to 'const asio::any_io_executor &'
D:\a\asio\asio\asio\module\tests\main.hpp(63): note: Reason: cannot convert from 'asio::this_coro::executor_t' to 'const asio::any_io_executor'
D:\a\asio\asio\asio\module\tests\main.hpp(63): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

@ClausKlein
Copy link
Owner Author

I got the CXX_MODULE work for the fmt library:

https://github.com/ClausKlein/fmt-module

@anarthal
Copy link
Collaborator

anarthal commented Dec 4, 2024

The other issue you're seeing is likely due to this warning you're getting:

D:\a\asio\asio\asio\stagedir\lib\cmake\asio\module\asio.cppm(48): warning C5304: a declaration designated by the using-declaration 'asio::this_coro::executor' exported from this module has internal linkage and using such a name outside the module is ill-formed; consider declaring 'const asio::this_coro::executor_t asio::this_coro::executor' 'inline' to use it outside of this module

Which is related to this: constexpr variables must be marked inline, otherwise they have internal linkage and can't be exported.

Actually, Asio declares them as ASIO_INLINE_VARIABLE, which conditionally expands to inline when there's support from the compiler (see config.hpp.

This, however, relies on __cplusplus being correctly defined, which is not the case by default for MSVC. IIRC there's a command line switch (was it /Zc:__cplusplus?) to solve it. Have a try with this.

@anarthal
Copy link
Collaborator

anarthal commented Dec 4, 2024

By the way, what is your final intention with this repository? Are you planning to PR it to Asio, or is it just to experiment?

@ClausKlein
Copy link
Owner Author

ClausKlein commented Dec 4, 2024

By the way, what is your final intention with this repository? Are you planning to PR it to Asio, or is it just to experiment?

Both, but no success to add cmake support to the asio cmake PR

But a a site effect, I created issues or pushed small fixes.

I found a better way and dit it for boost, fmt, asio: a cmake adapter to improve the cmake support.

i.e.

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.

3 participants