mirror of
https://git.mirrors.martin98.com/https://github.com/gulrak/filesystem
synced 2025-06-04 11:13:58 +08:00
Restructured include directories and enhanced CMake support.
This commit is contained in:
parent
96b8384886
commit
72e8d2e950
@ -1,12 +1,23 @@
|
|||||||
cmake_minimum_required(VERSION 3.10)
|
cmake_minimum_required(VERSION 3.10)
|
||||||
project(ghcfilesystem)
|
project(ghcfilesystem)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
if(NOT DEFINED CMAKE_CXX_STANDARD)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
endif()
|
||||||
|
if(CMAKE_CXX_STANDARD LESS 11)
|
||||||
|
message(FATAL_ERROR "CMAKE_CXX_STANDARD is less than 11, ghc::filesystem only works with C++11 and above.")
|
||||||
|
endif()
|
||||||
|
|
||||||
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
|
add_library(ghc_filesystem INTERFACE)
|
||||||
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
|
target_sources(ghc_filesystem INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include/ghc/filesystem.hpp)
|
||||||
|
target_include_directories(ghc_filesystem INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||||
|
target_compile_options(ghc_filesystem INTERFACE "$<$<C_COMPILER_ID:MSVC>:/utf-8>")
|
||||||
|
target_compile_options(ghc_filesystem INTERFACE "$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
|
||||||
|
|
||||||
add_subdirectory(test)
|
get_directory_property(hasParent PARENT_DIRECTORY)
|
||||||
add_subdirectory(examples)
|
if(NOT hasParent)
|
||||||
|
add_subdirectory(test)
|
||||||
|
add_subdirectory(examples)
|
||||||
|
endif()
|
||||||
|
29
README.md
29
README.md
@ -97,7 +97,7 @@ a fallback could be:
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
#else
|
#else
|
||||||
#include "filesystem.hpp"
|
#include <ghc/filesystem.hpp>
|
||||||
namespace fs = ghc::filesystem;
|
namespace fs = ghc::filesystem;
|
||||||
#endif
|
#endif
|
||||||
```
|
```
|
||||||
@ -115,7 +115,7 @@ using ofstream = std::ofstream;
|
|||||||
using fstream = std::fstream;
|
using fstream = std::fstream;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#include "filesystem.hpp"
|
#include <ghc/filesystem.hpp>
|
||||||
namespace fs {
|
namespace fs {
|
||||||
using namespace ghc::filesystem;
|
using namespace ghc::filesystem;
|
||||||
using ifstream = ghc::filesystem::ifstream;
|
using ifstream = ghc::filesystem::ifstream;
|
||||||
@ -128,13 +128,19 @@ using fstream = ghc::filesystem::fstream;
|
|||||||
Now you have e.g. `fs::ofstream out(somePath);` and it is either the wrapper or
|
Now you have e.g. `fs::ofstream out(somePath);` and it is either the wrapper or
|
||||||
the C++17 `std::ofstream`.
|
the C++17 `std::ofstream`.
|
||||||
|
|
||||||
Note, that on MSVC this detection only works starting from version 15.7 on and when setting
|
**Note, that on MSVC this detection only works starting from version 15.7 on and when setting
|
||||||
the `/Zc:__cplusplus` compile switch, as the compiler allways reports `199711L`
|
the `/Zc:__cplusplus` compile switch, as the compiler allways reports `199711L`
|
||||||
without that switch ([see](https://blogs.msdn.microsoft.com/vcblog/2018/04/09/msvc-now-correctly-reports-__cplusplus/)).
|
without that switch ([see](https://blogs.msdn.microsoft.com/vcblog/2018/04/09/msvc-now-correctly-reports-__cplusplus/)).**
|
||||||
|
|
||||||
Be aware too, as a header-only library, it is not hiding the fact, that it
|
Be aware too, as a header-only library, it is not hiding the fact, that it
|
||||||
uses system includes, so they "pollute" your global namespace.
|
uses system includes, so they "pollute" your global namespace.
|
||||||
|
|
||||||
|
Additionally, starting from v1.1.0, it is possible to add `ghc::filesystem`
|
||||||
|
as a git submodule, add the directory to your `CMakeLists.txt` with
|
||||||
|
`add_subdirectory()` and then simply use `target_link_libraries(your-target ghc_filesystem)`
|
||||||
|
to ensure correct include path that allow `#include <ghc/filesystem.hpp>`
|
||||||
|
to work.
|
||||||
|
|
||||||
There is a version macro `GHC_FILESYSTEM_VERSION` defined in case future changes
|
There is a version macro `GHC_FILESYSTEM_VERSION` defined in case future changes
|
||||||
might make it needed to react on the version, but I don't plan to break anything.
|
might make it needed to react on the version, but I don't plan to break anything.
|
||||||
It's the version as decimal number `(major * 10000 + minor * 100 + patch)`.
|
It's the version as decimal number `(major * 10000 + minor * 100 + patch)`.
|
||||||
@ -355,6 +361,21 @@ to the expected behavior.
|
|||||||
|
|
||||||
## Release Notes
|
## Release Notes
|
||||||
|
|
||||||
|
### v1.1.0 (wip)
|
||||||
|
|
||||||
|
* Restructuring of the project directory. The header files are now using
|
||||||
|
`hpp` as extension to be marked as c++ and they where moved to
|
||||||
|
`include/ghc/` to be able to include by `<ghc/filesystem.hpp>` as the
|
||||||
|
former include name might have been to generic and conflict with other
|
||||||
|
files.
|
||||||
|
* Better CMake support: `ghc::filesystem` now can be used as a submodul
|
||||||
|
and added with `add_subdirectory` and will export itself as `ghc_filesystem`
|
||||||
|
target. To use it, only `target_link_libraries(your-target ghc_filesystem)`
|
||||||
|
is needed and the include directories will be set so `#include <ghc/filesystem.hpp>`
|
||||||
|
will be a valid directive.
|
||||||
|
Still you can simply only add the header file to you project and include it
|
||||||
|
from there.
|
||||||
|
|
||||||
### [v1.0.10](https://github.com/gulrak/filesystem/releases/tag/v1.0.10)
|
### [v1.0.10](https://github.com/gulrak/filesystem/releases/tag/v1.0.10)
|
||||||
|
|
||||||
* Bugfix for ([#9](https://github.com/gulrak/filesystem/issues/9)), added
|
* Bugfix for ([#9](https://github.com/gulrak/filesystem/issues/9)), added
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
add_executable(fs_dir dir.cpp ../filesystem.hpp)
|
add_executable(fs_dir dir.cpp)
|
||||||
|
target_link_libraries(fs_dir ghc_filesystem)
|
||||||
if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)
|
if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)
|
||||||
target_compile_definitions(fs_dir PRIVATE _CRT_SECURE_NO_WARNINGS)
|
target_compile_definitions(fs_dir PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||||
endif()
|
endif()
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
#else
|
#else
|
||||||
#include "../filesystem.hpp"
|
#include <ghc/filesystem.hpp>
|
||||||
namespace fs = ghc::filesystem;
|
namespace fs = ghc::filesystem;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
add_executable(filesystem_test filesystem_test.cpp ../filesystem.hpp catch.hpp)
|
add_executable(filesystem_test filesystem_test.cpp catch.hpp)
|
||||||
|
target_link_libraries(filesystem_test ghc_filesystem)
|
||||||
target_compile_options(filesystem_test PRIVATE
|
target_compile_options(filesystem_test PRIVATE
|
||||||
$<$<CXX_COMPILER_ID:Clang>:-Wall -Wextra -Werror>
|
$<$<CXX_COMPILER_ID:Clang>:-Wall -Wextra -Werror>
|
||||||
$<$<CXX_COMPILER_ID:GNU>:-Wall -Werror>
|
$<$<CXX_COMPILER_ID:GNU>:-Wall -Werror>
|
||||||
@ -8,9 +9,10 @@ if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)
|
|||||||
target_compile_definitions(filesystem_test PRIVATE _CRT_SECURE_NO_WARNINGS)
|
target_compile_definitions(filesystem_test PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||||
endif()
|
endif()
|
||||||
if(CMAKE_GENERATOR STREQUAL Xcode)
|
if(CMAKE_GENERATOR STREQUAL Xcode)
|
||||||
add_executable(filesystem_test_cov filesystem_test.cpp ../filesystem.hpp catch.hpp)
|
add_executable(filesystem_test_cov filesystem_test.cpp catch.hpp)
|
||||||
target_compile_options(filesystem_test_cov PRIVATE "$<$<CONFIG:DEBUG>:--coverage>")
|
target_compile_options(filesystem_test_cov PRIVATE "$<$<CONFIG:DEBUG>:--coverage>")
|
||||||
target_link_libraries(filesystem_test_cov PRIVATE --coverage)
|
target_link_libraries(filesystem_test_cov PRIVATE --coverage)
|
||||||
|
target_link_libraries(filesystem_test_cov ghc_filesystem)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND (CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 7.0 OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0))
|
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND (CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 7.0 OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0))
|
||||||
@ -36,4 +38,5 @@ if(CMAKE_CXX_COMPILER_ID MATCHES MSVC AND (CMAKE_CXX_COMPILER_VERSION VERSION_EQ
|
|||||||
target_compile_definitions(std_filesystem_test PRIVATE USE_STD_FS _CRT_SECURE_NO_WARNINGS)
|
target_compile_definitions(std_filesystem_test PRIVATE USE_STD_FS _CRT_SECURE_NO_WARNINGS)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_executable(multifile_test multi1.cpp multi2.cpp ../filesystem.hpp catch.hpp)
|
add_executable(multifile_test multi1.cpp multi2.cpp catch.hpp)
|
||||||
|
target_link_libraries(multifile_test ghc_filesystem)
|
||||||
|
@ -65,7 +65,7 @@ using fstream = std::fstream;
|
|||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
#include "../filesystem.hpp"
|
#include <ghc/filesystem.hpp>
|
||||||
namespace fs {
|
namespace fs {
|
||||||
using namespace ghc::filesystem;
|
using namespace ghc::filesystem;
|
||||||
using ifstream = ghc::filesystem::ifstream;
|
using ifstream = ghc::filesystem::ifstream;
|
||||||
@ -121,12 +121,16 @@ public:
|
|||||||
TemporaryDirectory(TempOpt opt = TempOpt::none)
|
TemporaryDirectory(TempOpt opt = TempOpt::none)
|
||||||
{
|
{
|
||||||
static auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count();
|
static auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count();
|
||||||
static auto rng = std::bind(std::uniform_int_distribution<int>(0, 35), std::mt19937(static_cast<unsigned int>(seed)));
|
static auto rng = std::bind(std::uniform_int_distribution<int>(0, 35), std::mt19937(static_cast<unsigned int>(seed) ^ static_cast<unsigned int>(reinterpret_cast<ptrdiff_t>(&opt))));
|
||||||
std::string filename = "test_";
|
std::string filename;
|
||||||
|
do {
|
||||||
|
filename = "test_";
|
||||||
for (int i = 0; i < 8; ++i) {
|
for (int i = 0; i < 8; ++i) {
|
||||||
filename += "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[rng()];
|
filename += "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[rng()];
|
||||||
}
|
}
|
||||||
_path = fs::canonical(fs::temp_directory_path()) / filename;
|
_path = fs::canonical(fs::temp_directory_path()) / filename;
|
||||||
|
}
|
||||||
|
while(fs::exists(_path));
|
||||||
fs::create_directories(_path);
|
fs::create_directories(_path);
|
||||||
if (opt == TempOpt::change_path) {
|
if (opt == TempOpt::change_path) {
|
||||||
_orig_dir = fs::current_path();
|
_orig_dir = fs::current_path();
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
#define CATCH_CONFIG_MAIN
|
#define CATCH_CONFIG_MAIN
|
||||||
#include "catch.hpp"
|
#include "catch.hpp"
|
||||||
|
|
||||||
#include "../filesystem.hpp"
|
#include <ghc/filesystem.hpp>
|
||||||
namespace fs = ghc::filesystem;
|
namespace fs = ghc::filesystem;
|
||||||
|
|
||||||
// This test and the one in multi2.cpp doesn't actualy test relevant functionality,
|
// This test and the one in multi2.cpp doesn't actualy test relevant functionality,
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
//
|
//
|
||||||
//---------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------
|
||||||
#include "catch.hpp"
|
#include "catch.hpp"
|
||||||
#include "../filesystem.hpp"
|
#include <ghc/filesystem.hpp>
|
||||||
namespace fs = ghc::filesystem;
|
namespace fs = ghc::filesystem;
|
||||||
|
|
||||||
// This test and the one in multi1.cpp doesn't actualy test relevant functionality,
|
// This test and the one in multi1.cpp doesn't actualy test relevant functionality,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user