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
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
IndentPPDirectives: None
|
||||
IndentPPDirectives: AfterHash
|
||||
...
|
||||
|
@ -1,5 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.7.2)
|
||||
project(ghcfilesystem)
|
||||
project(ghc_filesystem)
|
||||
|
||||
if (POLICY CMP0077)
|
||||
cmake_policy(SET CMP0077 NEW)
|
||||
@ -17,6 +17,8 @@ else()
|
||||
option(GHC_FILESYSTEM_BUILD_TESTING "Enable tests" OFF)
|
||||
option(GHC_FILESYSTEM_WITH_INSTALL "With install target" ON)
|
||||
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})
|
||||
if(NOT DEFINED GHC_FILESYSTEM_TEST_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 "$<$<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)
|
||||
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||
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:
|
||||
|
||||
* 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)
|
||||
* 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
|
||||
|
@ -3,4 +3,4 @@
|
||||
# import targets
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/ghc_filesystem-targets.cmake")
|
||||
|
||||
check_required_components(ghcfilesystem)
|
||||
check_required_components(ghc_filesystem)
|
@ -96,51 +96,41 @@
|
||||
# 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)
|
||||
# define GHC_EXPAND_IMPL
|
||||
# define GHC_INLINE
|
||||
#ifdef GHC_OS_WINDOWS
|
||||
#ifndef GHC_FS_API
|
||||
#define GHC_FS_API
|
||||
#endif
|
||||
#ifndef GHC_FS_API_CLASS
|
||||
#define GHC_FS_API_CLASS
|
||||
#endif
|
||||
# ifdef GHC_FILESYSTEM_SHARED
|
||||
# define GHC_FS_API GHC_FS_DLL_EXPORT
|
||||
# define GHC_FS_API_CLASS GHC_FS_DLL_EXPORT
|
||||
# else
|
||||
#ifndef GHC_FS_API
|
||||
#define GHC_FS_API __attribute__((visibility("default")))
|
||||
#endif
|
||||
#ifndef GHC_FS_API_CLASS
|
||||
#define GHC_FS_API_CLASS __attribute__((visibility("default")))
|
||||
#endif
|
||||
# define GHC_FS_API
|
||||
# define GHC_FS_API_CLASS
|
||||
# endif
|
||||
#elif defined(GHC_FILESYSTEM_FWD)
|
||||
# define GHC_INLINE
|
||||
#ifdef GHC_OS_WINDOWS
|
||||
#ifndef GHC_FS_API
|
||||
# ifdef GHC_FILESYSTEM_SHARED
|
||||
# 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
|
||||
#endif
|
||||
#ifndef GHC_FS_API_CLASS
|
||||
# define GHC_FS_API_CLASS
|
||||
# endif
|
||||
#else
|
||||
#ifndef GHC_FS_API
|
||||
#define GHC_FS_API extern
|
||||
#endif
|
||||
#ifndef GHC_FS_API_CLASS
|
||||
#define GHC_FS_API_CLASS
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#else // header-only
|
||||
# define GHC_EXPAND_IMPL
|
||||
# define GHC_INLINE inline
|
||||
#ifndef GHC_FS_API
|
||||
# define GHC_FS_API
|
||||
#endif
|
||||
#ifndef GHC_FS_API_CLASS
|
||||
# define GHC_FS_API_CLASS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef GHC_EXPAND_IMPL
|
||||
|
||||
@ -301,7 +291,7 @@
|
||||
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
// 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))
|
||||
# define GHC_WITH_EXCEPTIONS
|
||||
@ -345,6 +335,13 @@ public:
|
||||
#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
|
||||
template <typename char_type>
|
||||
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()
|
||||
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)
|
||||
if(NOT MSVC)
|
||||
target_compile_options(exception PRIVATE -fno-exceptions)
|
||||
|
@ -131,9 +131,7 @@ struct StringMaker<fs::perms>
|
||||
template <>
|
||||
struct StringMaker<fs::file_status>
|
||||
{
|
||||
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())) + "]";
|
||||
}
|
||||
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())) + "]"; }
|
||||
};
|
||||
|
||||
#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))); }
|
||||
void deallocate(value_type* p, std::size_t) noexcept { ::operator delete(p); }
|
||||
template <class U>
|
||||
struct rebind {
|
||||
struct rebind
|
||||
{
|
||||
typedef TestAllocator<U> other;
|
||||
};
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user