mirror of
https://git.mirrors.martin98.com/https://github.com/gulrak/filesystem
synced 2025-06-04 11:13:58 +08:00
Work on shared/static library mode
Took 1 hour 56 minutes
This commit is contained in:
parent
a07ddedeae
commit
270d6876dc
@ -21,5 +21,5 @@ BraceWrapping:
|
|||||||
SplitEmptyNamespace: true
|
SplitEmptyNamespace: true
|
||||||
BreakConstructorInitializers: BeforeComma
|
BreakConstructorInitializers: BeforeComma
|
||||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||||
IndentPPDirectives: None
|
IndentPPDirectives: AfterHash
|
||||||
...
|
...
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 3.7.2)
|
cmake_minimum_required(VERSION 3.7.2)
|
||||||
project(ghcfilesystem)
|
project(ghc_filesystem)
|
||||||
|
|
||||||
if (POLICY CMP0077)
|
if (POLICY CMP0077)
|
||||||
cmake_policy(SET CMP0077 NEW)
|
cmake_policy(SET CMP0077 NEW)
|
||||||
@ -17,6 +17,8 @@ else()
|
|||||||
option(GHC_FILESYSTEM_BUILD_TESTING "Enable tests" OFF)
|
option(GHC_FILESYSTEM_BUILD_TESTING "Enable tests" OFF)
|
||||||
option(GHC_FILESYSTEM_WITH_INSTALL "With install target" ON)
|
option(GHC_FILESYSTEM_WITH_INSTALL "With install target" ON)
|
||||||
endif()
|
endif()
|
||||||
|
option(GHC_FILESYSTEM_BUILD_STATIC "Enable building static library" OFF)
|
||||||
|
option(GHC_FILESYSTEM_BUILD_SHARED "Enable building shared library" OFF)
|
||||||
option(GHC_FILESYSTEM_BUILD_STD_TESTING "Enable STD tests" ${GHC_FILESYSTEM_BUILD_TESTING})
|
option(GHC_FILESYSTEM_BUILD_STD_TESTING "Enable STD tests" ${GHC_FILESYSTEM_BUILD_TESTING})
|
||||||
if(NOT DEFINED GHC_FILESYSTEM_TEST_COMPILE_FEATURES)
|
if(NOT DEFINED GHC_FILESYSTEM_TEST_COMPILE_FEATURES)
|
||||||
set(GHC_FILESYSTEM_TEST_COMPILE_FEATURES ${CMAKE_CXX_COMPILE_FEATURES})
|
set(GHC_FILESYSTEM_TEST_COMPILE_FEATURES ${CMAKE_CXX_COMPILE_FEATURES})
|
||||||
@ -41,6 +43,28 @@ target_include_directories(ghc_filesystem INTERFACE
|
|||||||
target_compile_options(ghc_filesystem INTERFACE "$<$<C_COMPILER_ID:MSVC>:/utf-8>")
|
target_compile_options(ghc_filesystem INTERFACE "$<$<C_COMPILER_ID:MSVC>:/utf-8>")
|
||||||
target_compile_options(ghc_filesystem INTERFACE "$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
|
target_compile_options(ghc_filesystem INTERFACE "$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
|
||||||
|
|
||||||
|
if(GHC_FILESYSTEM_BUILD_STATIC)
|
||||||
|
add_library(ghc_filesystem_static STATIC src/filesystem.cpp)
|
||||||
|
target_include_directories(ghc_filesystem_static PUBLIC
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
|
$<INSTALL_INTERFACE:include>)
|
||||||
|
target_compile_definitions(ghc_filesystem_static PRIVATE GHC_FILESYSTEM_IMPLEMENTATION)
|
||||||
|
target_compile_definitions(ghc_filesystem_static INTERFACE GHC_FILESYSTEM_FWD)
|
||||||
|
target_compile_options(ghc_filesystem_static PUBLIC "$<$<C_COMPILER_ID:MSVC>:/utf-8>")
|
||||||
|
target_compile_options(ghc_filesystem_static PUBLIC "$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(GHC_FILESYSTEM_BUILD_SHARED)
|
||||||
|
add_library(ghc_filesystem_shared SHARED src/filesystem.cpp)
|
||||||
|
target_include_directories(ghc_filesystem_shared PUBLIC
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
|
$<INSTALL_INTERFACE:include>)
|
||||||
|
target_compile_definitions(ghc_filesystem_shared PRIVATE GHC_FILESYSTEM_IMPLEMENTATION GHC_FILESYSTEM_SHARED)
|
||||||
|
target_compile_definitions(ghc_filesystem_shared INTERFACE GHC_FILESYSTEM_FWD GHC_FILESYSTEM_SHARED)
|
||||||
|
target_compile_options(ghc_filesystem_shared PUBLIC "$<$<C_COMPILER_ID:MSVC>:/utf-8>")
|
||||||
|
target_compile_options(ghc_filesystem_shared PUBLIC "$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
|
||||||
|
endif()
|
||||||
|
|
||||||
if(GHC_FILESYSTEM_BUILD_TESTING OR GHC_FILESYSTEM_BUILD_EXAMPLES)
|
if(GHC_FILESYSTEM_BUILD_TESTING OR GHC_FILESYSTEM_BUILD_EXAMPLES)
|
||||||
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
|
||||||
|
@ -104,7 +104,7 @@ for more information._
|
|||||||
|
|
||||||
Unit tests are currently run with:
|
Unit tests are currently run with:
|
||||||
|
|
||||||
* macOS 10.12: Xcode 9.2 (clang-900.0.39.2), GCC 9.2, Clang 9.0, macOS 10.13: Xcode 10.1, macOS 10.14: Xcode 11.2, macOS 10.15: Xcode 11.6, Xcode 12.4
|
* macOS 10.12: Xcode 9.2 (clang-900.0.39.2), GCC 9.2, Clang 9.0, macOS 10.13: Xcode 10.1, macOS 10.14: Xcode 11.2, macOS 10.15: Xcode 11.6, Xcode 12.4, macOS 11.6: Xcode 13.0
|
||||||
* Windows: Visual Studio 2017, Visual Studio 2015, Visual Studio 2019, MinGW GCC 6.3 (Win32), GCC 7.2 (Win64), Cygwin GCC 10.2 (no CI yet)
|
* Windows: Visual Studio 2017, Visual Studio 2015, Visual Studio 2019, MinGW GCC 6.3 (Win32), GCC 7.2 (Win64), Cygwin GCC 10.2 (no CI yet)
|
||||||
* Linux (Ubuntu): GCC (5.5, 6.5, 7.4, 8.3, 9.2), Clang (5.0, 6.0, 7.1, 8.0, 9.0)
|
* Linux (Ubuntu): GCC (5.5, 6.5, 7.4, 8.3, 9.2), Clang (5.0, 6.0, 7.1, 8.0, 9.0)
|
||||||
* Linux (Alpine ARM/ARM64): GCC 9.2.0
|
* Linux (Alpine ARM/ARM64): GCC 9.2.0
|
||||||
|
@ -3,4 +3,4 @@
|
|||||||
# import targets
|
# import targets
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/ghc_filesystem-targets.cmake")
|
include("${CMAKE_CURRENT_LIST_DIR}/ghc_filesystem-targets.cmake")
|
||||||
|
|
||||||
check_required_components(ghcfilesystem)
|
check_required_components(ghc_filesystem)
|
@ -96,51 +96,41 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined GHC_OS_WINDOWS
|
||||||
|
#define GHC_FS_DLL_IMPORT __declspec(dllimport)
|
||||||
|
#define GHC_FS_DLL_EXPORT __declspec(dllexport)
|
||||||
|
#define GHC_FS_DLL_LOCAL
|
||||||
|
#else
|
||||||
|
#define GHC_FS_DLL_IMPORT __attribute__ ((visibility ("default")))
|
||||||
|
#define GHC_FS_DLL_EXPORT __attribute__ ((visibility ("default")))
|
||||||
|
#define GHC_FS_DLL_LOCAL __attribute__ ((visibility ("hidden")))
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(GHC_FILESYSTEM_IMPLEMENTATION)
|
#if defined(GHC_FILESYSTEM_IMPLEMENTATION)
|
||||||
# define GHC_EXPAND_IMPL
|
# define GHC_EXPAND_IMPL
|
||||||
# define GHC_INLINE
|
# define GHC_INLINE
|
||||||
#ifdef GHC_OS_WINDOWS
|
# ifdef GHC_FILESYSTEM_SHARED
|
||||||
#ifndef GHC_FS_API
|
# define GHC_FS_API GHC_FS_DLL_EXPORT
|
||||||
#define GHC_FS_API
|
# define GHC_FS_API_CLASS GHC_FS_DLL_EXPORT
|
||||||
#endif
|
|
||||||
#ifndef GHC_FS_API_CLASS
|
|
||||||
#define GHC_FS_API_CLASS
|
|
||||||
#endif
|
|
||||||
# else
|
# else
|
||||||
#ifndef GHC_FS_API
|
# define GHC_FS_API
|
||||||
#define GHC_FS_API __attribute__((visibility("default")))
|
# define GHC_FS_API_CLASS
|
||||||
#endif
|
|
||||||
#ifndef GHC_FS_API_CLASS
|
|
||||||
#define GHC_FS_API_CLASS __attribute__((visibility("default")))
|
|
||||||
#endif
|
|
||||||
# endif
|
# endif
|
||||||
#elif defined(GHC_FILESYSTEM_FWD)
|
#elif defined(GHC_FILESYSTEM_FWD)
|
||||||
# define GHC_INLINE
|
# define GHC_INLINE
|
||||||
#ifdef GHC_OS_WINDOWS
|
# ifdef GHC_FILESYSTEM_SHARED
|
||||||
#ifndef GHC_FS_API
|
# define GHC_FS_API GHC_FS_DLL_IMPORT
|
||||||
|
# define GHC_FS_API_CLASS GHC_FS_DLL_IMPORT
|
||||||
|
# else // static instead
|
||||||
# define GHC_FS_API extern
|
# define GHC_FS_API extern
|
||||||
#endif
|
|
||||||
#ifndef GHC_FS_API_CLASS
|
|
||||||
# define GHC_FS_API_CLASS
|
# define GHC_FS_API_CLASS
|
||||||
# endif
|
# endif
|
||||||
#else
|
#else // header-only
|
||||||
#ifndef GHC_FS_API
|
|
||||||
#define GHC_FS_API extern
|
|
||||||
#endif
|
|
||||||
#ifndef GHC_FS_API_CLASS
|
|
||||||
#define GHC_FS_API_CLASS
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
# define GHC_EXPAND_IMPL
|
# define GHC_EXPAND_IMPL
|
||||||
# define GHC_INLINE inline
|
# define GHC_INLINE inline
|
||||||
#ifndef GHC_FS_API
|
|
||||||
# define GHC_FS_API
|
# define GHC_FS_API
|
||||||
#endif
|
|
||||||
#ifndef GHC_FS_API_CLASS
|
|
||||||
# define GHC_FS_API_CLASS
|
# define GHC_FS_API_CLASS
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GHC_EXPAND_IMPL
|
#ifdef GHC_EXPAND_IMPL
|
||||||
|
|
||||||
@ -301,7 +291,7 @@
|
|||||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
// ghc::filesystem version in decimal (major * 10000 + minor * 100 + patch)
|
// ghc::filesystem version in decimal (major * 10000 + minor * 100 + patch)
|
||||||
#define GHC_FILESYSTEM_VERSION 10510L
|
#define GHC_FILESYSTEM_VERSION 10599L
|
||||||
|
|
||||||
#if !defined(GHC_WITH_EXCEPTIONS) && (defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND))
|
#if !defined(GHC_WITH_EXCEPTIONS) && (defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND))
|
||||||
# define GHC_WITH_EXCEPTIONS
|
# define GHC_WITH_EXCEPTIONS
|
||||||
@ -345,6 +335,13 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(GHC_OS_WINDOWS) && !defined(GHC_WIN_DISABLE_WSTRING_STORAGE_TYPE)
|
||||||
|
template class GHC_FS_API_CLASS path_helper_base<wchar_t>;
|
||||||
|
#else
|
||||||
|
template class GHC_FS_API_CLASS path_helper_base<char>;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if __cplusplus < 201703L
|
#if __cplusplus < 201703L
|
||||||
template <typename char_type>
|
template <typename char_type>
|
||||||
constexpr char_type path_helper_base<char_type>::preferred_separator;
|
constexpr char_type path_helper_base<char_type>::preferred_separator;
|
||||||
|
28
src/filesystem.cpp
Normal file
28
src/filesystem.cpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
//---------------------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// ghc::filesystem - A C++17-like filesystem implementation for C++11/C++14
|
||||||
|
//
|
||||||
|
//---------------------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Copyright (c) 2018, Steffen Schümann <s.schuemann@pobox.com>
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
//
|
||||||
|
//---------------------------------------------------------------------------------------
|
||||||
|
#include <ghc/filesystem.hpp>
|
@ -78,6 +78,18 @@ if(CMAKE_CXX_COMPILER_ID MATCHES MSVC)
|
|||||||
endif()
|
endif()
|
||||||
add_test(fwd_impl_test fwd_impl_test)
|
add_test(fwd_impl_test fwd_impl_test)
|
||||||
|
|
||||||
|
if(GHC_FILESYSTEM_BUILD_STATIC)
|
||||||
|
add_executable(filesystem_test_static filesystem_test.cpp catch.hpp)
|
||||||
|
target_link_libraries(filesystem_test_static ghc_filesystem_static)
|
||||||
|
ParseAndAddCatchTests(filesystem_test_static)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(GHC_FILESYSTEM_BUILD_SHARED)
|
||||||
|
add_executable(filesystem_test_shared filesystem_test.cpp catch.hpp)
|
||||||
|
target_link_libraries(filesystem_test_shared ghc_filesystem_shared)
|
||||||
|
ParseAndAddCatchTests(filesystem_test_shared)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_executable(exception exception.cpp)
|
add_executable(exception exception.cpp)
|
||||||
if(NOT MSVC)
|
if(NOT MSVC)
|
||||||
target_compile_options(exception PRIVATE -fno-exceptions)
|
target_compile_options(exception PRIVATE -fno-exceptions)
|
||||||
|
@ -131,9 +131,7 @@ struct StringMaker<fs::perms>
|
|||||||
template <>
|
template <>
|
||||||
struct StringMaker<fs::file_status>
|
struct StringMaker<fs::file_status>
|
||||||
{
|
{
|
||||||
static std::string convert(fs::file_status const& value) {
|
static std::string convert(fs::file_status const& value) { return std::string("[") + std::to_string(static_cast<unsigned int>(value.type())) + "," + std::to_string(static_cast<unsigned int>(value.permissions())) + "]"; }
|
||||||
return std::string("[") + std::to_string(static_cast<unsigned int>(value.type())) + "," + std::to_string(static_cast<unsigned int>(value.permissions())) + "]";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cpp_lib_char8_t
|
#ifdef __cpp_lib_char8_t
|
||||||
@ -297,7 +295,8 @@ public:
|
|||||||
value_type* allocate(std::size_t n) { return static_cast<value_type*>(::operator new(n * sizeof(value_type))); }
|
value_type* allocate(std::size_t n) { return static_cast<value_type*>(::operator new(n * sizeof(value_type))); }
|
||||||
void deallocate(value_type* p, std::size_t) noexcept { ::operator delete(p); }
|
void deallocate(value_type* p, std::size_t) noexcept { ::operator delete(p); }
|
||||||
template <class U>
|
template <class U>
|
||||||
struct rebind {
|
struct rebind
|
||||||
|
{
|
||||||
typedef TestAllocator<U> other;
|
typedef TestAllocator<U> other;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user