-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add a std::filesystem::path <-> os.PathLike caster. #2730
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -247,6 +247,41 @@ if(Boost_FOUND) | |
| endif() | ||
| endif() | ||
|
|
||
| # Check if we need to add -lstdc++fs or -lc++fs or nothing | ||
| if(MSVC) | ||
EricCousineau-TRI marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| set(STD_FS_NO_LIB_NEEDED TRUE) | ||
| else() | ||
| file( | ||
| WRITE ${CMAKE_CURRENT_BINARY_DIR}/main.cpp | ||
| "#include <filesystem>\nint main(int argc, char ** argv) {\n std::filesystem::path p(argv[0]);\n return p.string().length();\n}" | ||
| ) | ||
| try_compile( | ||
| STD_FS_NO_LIB_NEEDED ${CMAKE_CURRENT_BINARY_DIR} | ||
| SOURCES ${CMAKE_CURRENT_BINARY_DIR}/main.cpp | ||
| COMPILE_DEFINITIONS -std=c++17) | ||
| try_compile( | ||
| STD_FS_NEEDS_STDCXXFS ${CMAKE_CURRENT_BINARY_DIR} | ||
| SOURCES ${CMAKE_CURRENT_BINARY_DIR}/main.cpp | ||
| COMPILE_DEFINITIONS -std=c++17 | ||
| LINK_LIBRARIES stdc++fs) | ||
| try_compile( | ||
| STD_FS_NEEDS_CXXFS ${CMAKE_CURRENT_BINARY_DIR} | ||
| SOURCES ${CMAKE_CURRENT_BINARY_DIR}/main.cpp | ||
| COMPILE_DEFINITIONS -std=c++17 | ||
| LINK_LIBRARIES c++fs) | ||
| endif() | ||
|
|
||
| if(${STD_FS_NEEDS_STDCXXFS}) | ||
| set(STD_FS_LIB stdc++fs) | ||
| elseif(${STD_FS_NEEDS_CXXFS}) | ||
| set(STD_FS_LIB c++fs) | ||
| elseif(${STD_FS_NO_LIB_NEEDED}) | ||
| set(STD_FS_LIB "") | ||
| else() | ||
| message(WARNING "Unknown compiler - not passing -lstdc++fs") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is likely wrong. The
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so? We could be on a compiler that doesn't support C++17 at all, in which case we'll be just fine, everything filesystem-related will be ifdef'd out anyways?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. My project received complaints from users hitting this branch, but I unconditionally depend on
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this have to be done as part of this PR? TBH I'm not so comfortable with cmake...
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can’t be done in CMake in general, too many ways someone could set the std level, though since it’s our tests we can do it. I can look at this later if it’s needed.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll throw in peanut-gallery 2 cents: Looks good for a starting point! Can address acute defects after merge? |
||
| set(STD_FS_LIB "") | ||
| endif() | ||
|
|
||
EricCousineau-TRI marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Compile with compiler warnings turned on | ||
| function(pybind11_enable_warnings target_name) | ||
| if(MSVC) | ||
|
|
@@ -357,6 +392,8 @@ foreach(target ${test_targets}) | |
| target_compile_definitions(${target} PRIVATE -DPYBIND11_TEST_BOOST) | ||
| endif() | ||
|
|
||
| target_link_libraries(${target} PRIVATE ${STD_FS_LIB}) | ||
|
|
||
| # Always write the output file directly into the 'tests' directory (even on MSVC) | ||
| if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY) | ||
| set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.