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

cmake: always use pthread outside of MSVC #1305

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

illwieckz
Copy link
Member

@illwieckz illwieckz commented Sep 16, 2024

Always use pthread outside of MSVC.

After enabling it unconditionally I seen no build issue with Linux (GCC and Clang), macOS (AppleClang), FreeBSD (Clang), MinGW, PNaCl.

Also, CMake reported the flags to be supported in all cases, so we may make the flags mandatory.

It happens that the linker flag was lost in translation in #1997:

So I re-added it. It being missing did not bring any issue into all our builds (either on my end, either in our CI), but this is better like this I guess.

@slipher
Copy link
Member

slipher commented Sep 16, 2024

I don't think we should add the flag except where it is actually needed.

@illwieckz
Copy link
Member Author

How do we know it's actually needed? Isn't just using threads makes it needed?

@slipher
Copy link
Member

slipher commented Sep 16, 2024

Normally you don't have to request linking to pthreads unless you directly use the pthread API, e.g. pthread_create. For example, with MinGW, you do need -pthread if you explicitly use the pthread API. But you don't if you use std::thread: that's expected to be provided by the C++ standard library. Just some Linux toolchains are an aberration where you have to pass -pthread despite not having used its API.

In the non-Windows engine, we do call pthread_sigmask. So it would be logical to add the flag to the MacOS engine build (but not gamelogic), even though it apparently builds without it.

@illwieckz
Copy link
Member Author

So, how do we know if FreeBSD requires that flag?

@slipher
Copy link
Member

slipher commented Sep 16, 2024

Well if you want, you can test whether it builds with -pthread. Or if not, just toss in the flag on FreeBSD too to be safe.

@illwieckz
Copy link
Member Author

illwieckz commented Sep 17, 2024

As said in first post I tested the build with this flag on both Linux, FreeBSD, macOS and MinGW (and even PNaCl). In all cases it builds, and the flag is accepted for both compilation and linking.

@slipher
Copy link
Member

slipher commented Sep 17, 2024

Oops typo, I meant you can test whether it builds WITHOUT -pthread.

FreeBSD is the same situation like Mac, if you base it on whether the pthread API is actually used engine would need it but not gamelogic.

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

Successfully merging this pull request may close these issues.

2 participants