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)
|
||||
project(ghcfilesystem)
|
||||
|
||||
if(NOT DEFINED CMAKE_CXX_STANDARD)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
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_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
|
||||
add_library(ghc_filesystem INTERFACE)
|
||||
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>")
|
||||
|
||||
get_directory_property(hasParent PARENT_DIRECTORY)
|
||||
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>
|
||||
namespace fs = std::filesystem;
|
||||
#else
|
||||
#include "filesystem.hpp"
|
||||
#include <ghc/filesystem.hpp>
|
||||
namespace fs = ghc::filesystem;
|
||||
#endif
|
||||
```
|
||||
@ -115,7 +115,7 @@ using ofstream = std::ofstream;
|
||||
using fstream = std::fstream;
|
||||
}
|
||||
#else
|
||||
#include "filesystem.hpp"
|
||||
#include <ghc/filesystem.hpp>
|
||||
namespace fs {
|
||||
using namespace ghc::filesystem;
|
||||
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
|
||||
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`
|
||||
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
|
||||
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
|
||||
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)`.
|
||||
@ -355,6 +361,21 @@ to the expected behavior.
|
||||
|
||||
## 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)
|
||||
|
||||
* 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)
|
||||
target_compile_definitions(fs_dir PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <filesystem>
|
||||
namespace fs = std::filesystem;
|
||||
#else
|
||||
#include "../filesystem.hpp"
|
||||
#include <ghc/filesystem.hpp>
|
||||
namespace fs = ghc::filesystem;
|
||||
#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
|
||||
$<$<CXX_COMPILER_ID:Clang>:-Wall -Wextra -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)
|
||||
endif()
|
||||
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_link_libraries(filesystem_test_cov PRIVATE --coverage)
|
||||
target_link_libraries(filesystem_test_cov ghc_filesystem)
|
||||
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))
|
||||
@ -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)
|
||||
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
|
||||
#else
|
||||
#define NOMINMAX
|
||||
#include "../filesystem.hpp"
|
||||
#include <ghc/filesystem.hpp>
|
||||
namespace fs {
|
||||
using namespace ghc::filesystem;
|
||||
using ifstream = ghc::filesystem::ifstream;
|
||||
@ -121,12 +121,16 @@ public:
|
||||
TemporaryDirectory(TempOpt opt = TempOpt::none)
|
||||
{
|
||||
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)));
|
||||
std::string filename = "test_";
|
||||
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;
|
||||
do {
|
||||
filename = "test_";
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
filename += "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[rng()];
|
||||
}
|
||||
_path = fs::canonical(fs::temp_directory_path()) / filename;
|
||||
}
|
||||
while(fs::exists(_path));
|
||||
fs::create_directories(_path);
|
||||
if (opt == TempOpt::change_path) {
|
||||
_orig_dir = fs::current_path();
|
||||
|
@ -32,7 +32,7 @@
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "../filesystem.hpp"
|
||||
#include <ghc/filesystem.hpp>
|
||||
namespace fs = ghc::filesystem;
|
||||
|
||||
// This test and the one in multi2.cpp doesn't actualy test relevant functionality,
|
||||
|
@ -30,7 +30,7 @@
|
||||
//
|
||||
//---------------------------------------------------------------------------------------
|
||||
#include "catch.hpp"
|
||||
#include "../filesystem.hpp"
|
||||
#include <ghc/filesystem.hpp>
|
||||
namespace fs = ghc::filesystem;
|
||||
|
||||
// This test and the one in multi1.cpp doesn't actualy test relevant functionality,
|
||||
|
Loading…
x
Reference in New Issue
Block a user