rikyoz / bit7z

A C++ static library offering a clean and simple interface to the 7-zip shared libraries.
https://rikyoz.github.io/bit7z
Mozilla Public License 2.0
602 stars 110 forks source link

[Bug]: BIT7Z_DISABLE_USE_STD_FILESYSTEM not working #194

Closed kleuter closed 3 months ago

kleuter commented 4 months ago

bit7z version

4.0.x

Compilation options

BIT7Z_AUTO_FORMAT

7-zip version

v23.01

7-zip shared library used

7z.dll / 7z.so

Compilers

Clang

Compiler versions

No response

Architecture

x86_64

Operating system

macOS

Operating system versions

No response

Bug description

I wanted to compile the lib to used on older macOS, but compilation failed with Error 'path' is unavailable: introduced in macOS 10.15, so basically the lib tried to use std::filesystem, adding BIT7Z_DISABLE_USE_STD_FILESYSTEM didn't give any effect (looks like this define is not used in the lib).

When I changed this (in bitdefines.hpp)

#if defined( __cpp_lib_filesystem )
#   define BIT7Z_USE_STANDARD_FILESYSTEM
#elif BIT7Z_CPP_STANDARD >= 17 && defined( __has_include )
#   if __has_include( <filesystem> )
#       define BIT7Z_USE_STANDARD_FILESYSTEM
#   endif
#endif

to this

#ifndef BIT7Z_DISABLE_USE_STD_FILESYSTEM // by me

#if defined( __cpp_lib_filesystem )
#   define BIT7Z_USE_STANDARD_FILESYSTEM
#elif BIT7Z_CPP_STANDARD >= 17 && defined( __has_include )
#   if __has_include( <filesystem> )
#       define BIT7Z_USE_STANDARD_FILESYSTEM
#   endif
#endif

#endif

It works fine. Would it be correct to include this to the lib?

Steps to reproduce

No response

Expected behavior

No response

Relevant compilation output

No response

Code of Conduct

rikyoz commented 4 months ago

Hi! This is weird! The BIT7Z_DISABLE_USE_STD_FILESYSTEM is not used to define a preprocessor flag, it is used to decide which C++ standard version to use to build the library.

If you enable BIT7Z_DISABLE_USE_STD_FILESYSTEM in CMake, the project should be configured to use C++14, and thus the compiler should not give access to the std::filesystem library. So the #if defined( __cpp_lib_filesystem ) and #if BIT7Z_CPP_STANDARD >= 17 && defined( __has_include ) conditions should be both false, and BIT7Z_USE_STANDARD_FILESYSTEM would never be defined.

I guess I can get CMake to define the BIT7Z_DISABLE_USE_STD_FILESYSTEM preprocessor flag and use the #ifndef BIT7Z_DISABLE_USE_STD_FILESYSTEM as you did.

rikyoz commented 3 months ago

Update: I've pushed the fix to the hotfix/v4.0.6 branch.

Now using the BIT7Z_DISABLE_USE_STD_FILESYSTEM CMake option will define the namesake preprocessor flag, and will prevent bidefines.hpp from defining the BIT7Z_USE_STANDARD_FILESYSTEM.

The next patch version v4.0.6 will contain the fix.

kleuter commented 3 months ago

Thank you, it's important when not using cmake

rikyoz commented 3 months ago

Released on v4.0.6.

Thank you, it's important when not using cmake

You're welcome!