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 compilation of tests with /std:c++17 #2292

Closed

Conversation

YannickJadoul
Copy link
Collaborator

Seems it needs to be closed to get it passed correctly?

Closes #2089

So this first commit should fail, given #2089.

@YannickJadoul YannickJadoul force-pushed the appveyor-msvc-c++17 branch 4 times, most recently from fc0c2b8 to 0bdf8b9 Compare July 11, 2020 20:45
@YannickJadoul
Copy link
Collaborator Author

Am I going crazy? The debug runs print PYBIND11_CPP_STANDARD=/std:c++17 from CMake, but the actual compile command contains /std:c++14???

@YannickJadoul YannickJadoul force-pushed the appveyor-msvc-c++17 branch 3 times, most recently from 6e7fbe9 to 4e7518c Compare July 11, 2020 23:02
@YannickJadoul
Copy link
Collaborator Author

Seriously!?

https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html

$<COMPILE_LANGUAGE:languages>
...
Note that with Visual Studio Generators and Xcode there is no way to represent target-wide compile definitions or include directories separately for C and CXX languages. Also, with Visual Studio Generators there is no way to represent target-wide flags separately for C and CXX languages. Under these generators, expressions for both C and C++ sources will be evaluated using CXX if there are any C++ sources and otherwise using C. A workaround is to create separate libraries for each source file language instead:

@henryiii
Copy link
Collaborator

henryiii commented Jul 11, 2020

The correct solution probably would be to use compile_features; when we make this 3.7+ only we should be able to change this properly.

But yes, this is a general issue that always needs a workaround for these IDE's.

@YannickJadoul
Copy link
Collaborator Author

The correct solution probably would be to use compile_features; when we make this 3.7+ only we should be able to change this properly.

Yes, I had thought of that as well. But depends on dropping old CMake support, then.

But yes, this is a general issue that always needs a workaround for these IDE's.

Good point. I'll check if there's more of these around!

(Should I also check for Xcode, btw, or not?)

@henryiii
Copy link
Collaborator

If it doesn't work on Xcode, I'd likely know pretty quickly. ;)

I can't think of any more of these that are likely to be a problem, but I wouldn't have remembered the one above (I had to fix in in CLI11 a long time ago). I know of some that probably don't affect us (like the ... syntax in version support being broken in MSVC's forked copy of CMake 3.11)

@YannickJadoul
Copy link
Collaborator Author

Thanks! I found 2 more occurences of $<COMPILE_LANGUAGE:CXX>: one for the embedding target (same fix), and one here:

target_compile_options(${target_name} PRIVATE $<$<NOT:$<CONFIG:Debug>>:$<$<COMPILE_LANGUAGE:CXX>:/MP>>)

Not sure what the last one does, but it's already MSVC-specific. Any idea what to do? Just ignore, since it's only about parallel builds?

@henryiii
Copy link
Collaborator

Maybe tag it with a TODO? Is there a reason that cmake --build -j<N> doesn't work for parallel builds? Manually sticking specific compile options is usually a bad idea. And, due to the COMPILE_LANGUAGE, this one should be a no-op.

@YannickJadoul
Copy link
Collaborator Author

Maybe tag it with a TODO? Is there a reason that cmake --build -j<N> doesn't work for parallel builds? Manually sticking specific compile options is usually a bad idea. And, due to the COMPILE_LANGUAGE, this one should be a no-op.

No clue. Never really touched the CMake internals before. I'll just apply the same fix anyway. If someone passes by that knows more about CMake, we can still change it? :-)

@YannickJadoul
Copy link
Collaborator Author

Builds are still using /std:c+14!? Am I somehow going crazy? I thought I had found the issue :-(

@bstaletic
Copy link
Collaborator

I know the title says /std:c++17, but could we maybe include this as well: #2159

@YannickJadoul
Copy link
Collaborator Author

I know the title says /std:c++17, but could we maybe include this as well: #2159

Yes, good point. I was planning to see if supporting VS 2019 would still be possible, but this is also something to add!
Once I get things to fail, that is ...

@YannickJadoul YannickJadoul force-pushed the appveyor-msvc-c++17 branch 3 times, most recently from cb9ce09 to 23d6691 Compare July 13, 2020 09:55
.appveyor.yml Outdated Show resolved Hide resolved
@LeslieGerman
Copy link

@YannickJadoul

Thanks! I found 2 more occurences of $<COMPILE_LANGUAGE:CXX>: one for the embedding target (sa
target_compile_options(${target_name} PRIVATE $&lt;$<NOT:$CONFIG:Debug>:$<$<COMPILE_LANGUAGE:CXX>:/MP>>)
Not sure what the last one does ...

/MP: Build with Multiple Processes

According to my experiences in previous years, it may or may not improve compilation time. See also MS own Guideline.

If compilation speed is not a key factor here, you can safely omit this option IMO.

@YannickJadoul
Copy link
Collaborator Author

/MP: Build with Multiple Processes

Yes, that I can look up. My question was just wondering out loud why it's in pybind11's CMake and why not in debug, etc. (Which I might be able to look up through some git blame, yes.)

@bstaletic
Copy link
Collaborator

What's the status of this? Are we just going to mandate /permissive-?

@YannickJadoul
Copy link
Collaborator Author

Yes, but I haven't gotten to cleaning up this PR and adding it to the docs. Feel free to take over, if you want?

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.

Pybind fails to build with MSVC 19.16 in C++17 mode
4 participants