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
vs2019-cmake std filesystem 错误 #497
Comments
Using "set" to specify the C++ standard is not portable nor is it a modern cmake best practice. The C++ standard is already being expressed in a compiler independent manner, so whatever is going wrong must be some cmake nuance or a compiler bug. Please upload CMakeError.log and CMakeOutput.log. It's redundant to specify target_compile_features twice with a different set of constraints, and it might be causing problems here. In the top level cmake file you'll see this. add_library(nana) add_library(nana::nana ALIAS nana) target_compile_features(nana PUBLIC cxx_std_17) # need after cxx_std_14 or cxx_std_17 ?? target_compile_features(nana PUBLIC cxx_nullptr PUBLIC cxx_range_for PUBLIC cxx_lambdas PUBLIC cxx_decltype_auto PUBLIC cxx_defaulted_functions PUBLIC cxx_deleted_functions PUBLIC cxx_auto_type PUBLIC cxx_decltype_incomplete_return_types PUBLIC cxx_defaulted_move_initializers PUBLIC cxx_noexcept PUBLIC cxx_rvalue_references ) That second target_compile_features block may be the problem. Try commenting it out and try again, and if that doesn't work, uncomment it and then comment out the "cxx_std_17" line. References:
|
Did you try the msbuild or the vcxproj method to compile nana? https://ci.appveyor.com/project/qPCR4vir/nana ppetraki@vanguard:~/Sandbox/hacking/nana-develop$ ls build/vc2019/ |
Tks. 1.cpp
|
Hi, thank you for testing and reporting! |
Now @ppetraki, this is in a .cmake file for Filesystem selection. This is not to set the global c++ flag, that is set directly with the cmake command you pointed. |
@qPCR4vir CMAKE_REQUIRED_FLAGS is a internal cmake option. You're playing with fire there. If someone wants to be C++17 (or 20) from top to bottom to get all the compiler optimizations then they're going to have to do something like this. https://gitlab.kitware.com/cmake/cmake/issues/17146 , or hack the project. IMHO you must distinguish between required language support and required libraries. If Nana 1.x is working to stay as a C++11 AND UP project, then the target_compile_features line should be std_cxx_11. https://crascit.com/2015/03/28/enabling-cxx11-in-cmake/ Right now it's a PUBLIC requirement, which means it's transitive. Worse, if I try to override it, it kinda ignores me. Working with an older nana branch, when setting std_cxx_11 and deleting all those extra compile options. It removed the --std= entirely from the command line, which means it's floating to the latest version that the compiler supports. I would be reasonable to expect that if I declare that 11 is the min, then the project self-configures to use boost, and if it isn't there, it fails. It overrode my intent. https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/
Again the emphasis is on language support, not additional libraries provided by newer versions of the language. That is a library dependency, of which you have quite a few already. Supporting boost, gnu c++, clang c++, and msvc++ is going to require you to code to the lowest common denominator for "filesystem support". See, https://www.bfilipek.com/2019/05/boost-to-stdfs.html . Not everything from boost made it into std::filesystem. Apparently it isn't even consistent across versions of std::filesystem per the clang bug I just filed against 1.7.3. qPCR4vir#37 Also see, To get out of std::fs config hell. You could set a new floor version like c++20 for Nana when you commit to 2.x. Make it a breaking change even. The project is small and the community around it is nimble enough to tolerate that. We don't all get to move up to the latest version of C++ in our established projects, even if it the standard is backwards compatible. The whole fear of the unknown FUD keeps many projects at the C++ std they were conceived with. Sure we can edit the subproject, but now we get to maintain it too. So to recap, what you really have today "per the cmake code", is a C++17 project, that can go backwards to as far as C++11, iif the developer changes the minimum required version. At which point you must use boost. Or, you can stay on 17 and either user the std or boost, depending on the whether the fslib provided by your compiler suite fully complies with the standard, and if it doesn't, you get to use boost. The CI doesn't even appear to be testing a range of C++ versions so... users are going to be the first ones to find out that when this breaks. One day, someone is going to add lambda arguments that use auto to libNana and it's going to break on C++11 because the CI didn't catch it. That's "language support". You've conflated language support with additional libraries provided by the standard and it's made a huge config matrix to test which frankly, isn't creating a lot of value for your project and is hurting it in real ways. I can't even build it out of the box as a straight C++17 project anymore (1.7.3 RC). We just want to get the bits off the disk and into memory. So how do we move forward from here as the cats already out of the bag?
|
Hi @ppetraki,
sorry? what dependency? .. ah, you probable mean the std c++ lib and the OS (win32, X11 and related basic OS support for paint, threads, mouse, fonts, etc.)
we have never supported boost. We had no interest in that. Boost can very well support by self and don't need our support. We have (ab)used boost to implement the sdt::filesystem some compilers (libraries) don't provide in some platforms (gcc/MinGW). Years ago this was difficult, but doable. But the c++ std evolved and diverged from boost. And the nana own filesystem implementation evolved too but in the std direction. Now we prefer to use nana implementation if no std is available rather than boost.
hmm, good idea... but some people will like to kill you |
The cmake script vector-of-bool wrote succinctly captures the discovery of std filesystem support without having to resort to platform specific define checks for C++17 support. https://github.com/vector-of-bool/CMakeCM/blob/master/modules/FindFilesystem.cmake Adopting this would dramatically cut down on the complexity of "select filesystem" code and reduce overall maintenance. I would draw the line with a platform supported by cmake if "set(CMAKE_CXX_STANDARD 17)" didn't do the right thing on said platform. That would require updating the min cmake version to make that work. As opposed to what you have now, which is brittle. Also, it's not shown in the users posting, but the cxx_std_17 check would have failed at the very beginning of the project configuration if the compiler was judged to be unable to support C++17.
I've never seen a library that rolls it minimum language standard forward in the same major release version. If it's not a priority then please consider dumping the mention of 11/14 support from the front page, it's really confusing.
Correct.
Then I'm confused again, there are ifdefs and cmake logic around boost filesystem in the current codebase. If you don't support it then it shouldn't be there.
:-}
Well, if you continue on this path, you might want to kill yourself. Codeblocks is cross platform, so that matrix is multiplied by 3, and cmake basically supports everything. You easily have 10 build variations across IDEs and platforms today. IMHO once you hit 2.x, "one" build system should be the official version that the CI checks all the build/link type variations and the rest is community supported. You want to be the GUI business, not the build system business right? |
Hi! In my tests I have (Ubuntu/gcc 8.3):
and (MinGW/gcc 9.2)
|
msvc output:
|
Thank! |
There is still a bug where the root cmakefile's c++ std will be overwritten by the filesystem check because you directly manipulate those variables without previously saving it's state. cmake's handles this with, https://cmake.org/cmake/help/v3.0/module/CMakePushCheckState.html. Without this, the project's --std will always be dragged back to c++17 after you check for fs support. This is how v.o.b addressed it, making his cmake script project and state independent. |
Could you elaborate on that?
No, no. Here we don't change "the project's --std " we only change the cmake test variables which do not affect the project. Ok, we can set back like in line set (CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_ORIGINAL}) the
|
It's pretty clear. You just go ahead and write into _REQURIED_FLAGS etc without saving the original state. The push/pop functions provided by CMakePushCheckState protect those vars. It's been around since 3.0.2 so it's probably a good idea to use it. |
we save before change: line 97, 98:
we would need to complicate the logic even more to decide when we want to leak the variables changed and when not, which is what we are doing manually. This variables are global for some reason (to be used by downstream-tests), not just local arguments. CMakePushCheckState make actually it locals. |
vs2019
Windows 7
cmake: 3.16.0
develop分支
错误:
57行加上:
include (CheckIncludeFileCXX)
解决之后:
__cplusplus < 201703L
在msvc下似乎要加:/Zc:__cplusplus /std:c++latest
改成:
set (CMAKE_REQUIRED_FLAGS "/Zc:__cplusplus /std:c++latest ${CMAKE_CXX_FLAGS}")
可以正常编译。
参考链接:
https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
The text was updated successfully, but these errors were encountered: