-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Boost::filesystem in PCL #5881
Comments
I would like to work on this, please do share your plan for this activity. Thank You |
@SumitkumarSatpute Great! You could start with Idea 1. I would like to emphasize that not all functions/classes from Boost will be replaceable this way. The replacement should be C++14 compatible, work on all platforms (Windows, Linux, macOS), and not be too complex. I would suggest that you first post your suggested replacement here, and then create a pull request after one of us maintainers gives the okay |
@mvieth https://github.com/gulrak/filesystem would be OK? |
Interesting, thanks for the link. |
@mvieth Using // main.cpp
#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;
int main() {
auto pwd = fs::current_path();
std::cout << pwd.string() << std::endl;
return 0;
} And then g++ main.cpp -o main -std=c++14 -lstdc++fs |
Sorry for late reply. |
Doesn't it required a build change to an existing build process ? |
No |
|
@mvieth Something like this ? |
@mvieth For Idea 2,I found the only two functions #if (BOOST_VERSION >= 107700)
// TODO: alternative implementation
#else
// existing implementation
#endif |
@SumitkumarSatpute The logic to get the filename extension looks good, but what is @cybaol |
@mvieth by i.e
|
@SumitkumarSatpute It's mine. #include <fstream>
#include <string>
bool ends_with(const std::string& str, const std::string& suffix) {
const auto suffix_start = str.size() - suffix.size();
const auto result = str.find(suffix, suffix_start);
return (result == suffix_start) && (result != std::string::npos);
}
bool is_exists(const std::string& file_name) {
std::ifstream file(file_name);
return file.good();
} |
Okay, let's start with the following:
Feel free to open a pull request for any of these three tasks, after commenting here which task you want to work on (one pull request per task, please). |
I am working on task 1, 2 and 3. |
@mvieth For Idea 3, in order to simplify the conditional macro in the code, a namespace alias is used when included( #if (__cplusplus >= 201703L)
#include <filesystem>
namespace fs = std::filesystem;
#else
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
#endif And then replace all |
@cybaol That is a good idea, but are |
I think a good next step would be to adapt https://github.com/PointCloudLibrary/pcl/blob/master/cmake/pcl_find_boost.cmake: If if(TARGET Boost::filesystem)
target_link_libraries("${LIB_NAME}" Boost::filesystem)
endif() The behaviour we want to achieve (first three points already work, the last one does not work yet):
|
Do note that there are several differences between It seems likely to me that just picking between the two options "boost available, build everything using that" and "boost unavailable, try '17 when it works" is the right level of granularity. Trying to guess based on |
Context
Currently, PCL uses the filesystem library from Boost. In the long term, we would like to replace all functions and classes from Boost::filesystem with something else and remove this dependency.
To find out where PCL uses Boost::filesystem, you can e.g. use
grep -ri "boost.*filesystem" *
In C++17, there is a std::filesystem library which could replace the one from Boost, but at the moment, PCL still aims to be compatible with C++14.
In Boost 1.83.0, some functions from Boost::filesystem are deprecated. PCL should not use these deprecated functions any more. (see here, choose any build, select a macOS or Windows job, click
Build Library
, and search forfilesystem
)Idea 1
Check if, instead of using functions and classes from Boost::filesystem, the same goal can be achieved in a different, C++14 compatible way (meaning, without using std::filesystem). This might for example be possible when simply checking the filename extension. In other situations, it may not be possible to find a reliable alternative on all platforms.
Idea 2
For the functions deprecated in Boost 1.83.0, that are used in PCL: check the alternative suggested by Boost. In which older Boost versions is this alternative available? PCL currently requires at least Boost 1.65.0.
Idea 3
If a function or class from Boost can not easily be replaced without using std::filesystem from C++17 (idea 1), then use std::filesystem like this:
This way, PCL stays C++14 compatible and we can automatically switch in the future.
If someone wants to work on this, please make sure that your pull requests are not too large (otherwise split them), and comment here first what you are planning to do.
The text was updated successfully, but these errors were encountered: