BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
filesystem.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // qt-mvvm: Model-view-view-model framework for large GUI applications
4 //
5 //! @file mvvm/model/mvvm/core/filesystem.h
6 //! @brief Defines class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_MVVM_MODEL_MVVM_CORE_FILESYSTEM_H
16 #define BORNAGAIN_MVVM_MODEL_MVVM_CORE_FILESYSTEM_H
17 
18 //! @file mvvm/model/mvvm/core/filesystem.h of <filesystem> library for older compilers (<gcc8.0)
19 //! See
20 //! https://stackoverflow.com/questions/53365538/how-to-determine-whether-to-use-filesystem-or-experimental-filesystem
21 
22 // We haven't checked which filesystem to include yet
23 #ifndef INCLUDE_STD_FILESYSTEM_EXPERIMENTAL
24 
25 // Check for feature test macro for <filesystem>
26 #if defined(__cpp_lib_filesystem)
27 #define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0
28 
29 // Check for feature test macro for <experimental/filesystem>
30 #elif defined(__cpp_lib_experimental_filesystem)
31 #define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1
32 
33 // We can't check if headers exist...
34 // Let's assume experimental to be safe
35 #elif !defined(__has_include)
36 #define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1
37 
38 // Check if the header "<filesystem>" exists
39 #elif __has_include(<filesystem>)
40 
41 // If we're compiling on Visual Studio and are not compiling with C++17, we need to use experimental
42 #ifdef _MSC_VER
43 
44 // Check and include header that defines "_HAS_CXX17"
45 #if __has_include(<yvals_core.h>)
46 #include <yvals_core.h>
47 
48 // Check for enabled C++17 support
49 #if defined(_HAS_CXX17) && _HAS_CXX17
50 // We're using C++17, so let's use the normal version
51 #define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0
52 #endif
53 #endif
54 
55 // If the marco isn't defined yet, that means any of the other VS specific checks failed, so we need
56 // to use experimental
57 #ifndef INCLUDE_STD_FILESYSTEM_EXPERIMENTAL
58 #define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1
59 #endif
60 
61 // Not on Visual Studio. Let's use the normal version
62 #else // #ifdef _MSC_VER
63 #define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 0
64 #endif
65 
66 // Check if the header "<filesystem>" exists
67 #elif __has_include(<experimental/filesystem>)
68 #define INCLUDE_STD_FILESYSTEM_EXPERIMENTAL 1
69 
70 // Fail if neither header is available with a nice error message
71 #else
72 #error Could not find system header "<filesystem>" or "<experimental/filesystem>"
73 #endif
74 
75 // We priously determined that we need the exprimental version
76 #if INCLUDE_STD_FILESYSTEM_EXPERIMENTAL
77 // Include it
78 #include <experimental/filesystem>
79 
80 // We need the alias from std::experimental::filesystem to std::filesystem
81 namespace std {
82 namespace filesystem = experimental::filesystem;
83 }
84 
85 // We have a decent compiler and can use the normal version
86 #else
87 // Include it
88 #include <filesystem>
89 #endif
90 
91 #endif // #ifndef INCLUDE_STD_FILESYSTEM_EXPERIMENTAL
92 
93 #endif // BORNAGAIN_MVVM_MODEL_MVVM_CORE_FILESYSTEM_H
Definition: filesystem.h:81