From 765f47963544f78792581ce215339a854c7654a1 Mon Sep 17 00:00:00 2001 From: Peter Heywood Date: Fri, 13 May 2022 11:49:23 +0100 Subject: [PATCH 1/2] Remove CUDA 10.x and C++14 support --- .github/scripts/install_cuda_ubuntu.sh | 2 +- .github/scripts/install_cuda_windows.ps1 | 29 +++++++----- .github/workflows/Manylinux2014.yml | 4 -- .github/workflows/Ubuntu.yml | 6 +-- .github/workflows/Windows.yml | 2 +- README.md | 5 +-- cmake/cxxstd.cmake | 57 ++++++------------------ cmake/warnings.cmake | 11 +---- src/CMakeLists.txt | 32 ++++++------- 9 files changed, 55 insertions(+), 93 deletions(-) diff --git a/.github/scripts/install_cuda_ubuntu.sh b/.github/scripts/install_cuda_ubuntu.sh index 9bb8cff..6a5dfa0 100755 --- a/.github/scripts/install_cuda_ubuntu.sh +++ b/.github/scripts/install_cuda_ubuntu.sh @@ -7,7 +7,7 @@ # @todo - pass this in from outside the script? # @todo - check the specified subpackages exist via apt pre-install? apt-rdepends cuda-9-0 | grep "^cuda-"? -# Ideally choose from the list of meta-packages to minimise variance between cuda versions (although it does change too). Some of these packages may not be availble pre cuda 10. +# Ideally choose from the list of meta-packages to minimise variance between cuda versions (although it does change too). Some of these packages may not be availble in older CUDA releases CUDA_PACKAGES_IN=( "cuda-compiler" "cuda-cudart-dev" diff --git a/.github/scripts/install_cuda_windows.ps1 b/.github/scripts/install_cuda_windows.ps1 index 0a9922e..fcc7f3f 100755 --- a/.github/scripts/install_cuda_windows.ps1 +++ b/.github/scripts/install_cuda_windows.ps1 @@ -24,14 +24,20 @@ $CUDA_KNOWN_URLS = @{ "11.2.0" = "https://developer.download.nvidia.com/compute/cuda/11.2.0/network_installers/cuda_11.2.0_win10_network.exe"; "11.2.1" = "https://developer.download.nvidia.com/compute/cuda/11.2.1/network_installers/cuda_11.2.1_win10_network.exe"; "11.2.2" = "https://developer.download.nvidia.com/compute/cuda/11.2.2/network_installers/cuda_11.2.2_win10_network.exe"; - "11.3.0" = "https://developer.download.nvidia.com/compute/cuda/11.3.0/network_installers/cuda_11.3.0_win10_network.exe" - "11.3.1" = "https://developer.download.nvidia.com/compute/cuda/11.3.1/network_installers/cuda_11.3.1_win10_network.exe" - "11.4.0" = "https://developer.download.nvidia.com/compute/cuda/11.4.0/network_installers/cuda_11.4.0_win10_network.exe" - "11.4.1" = "https://developer.download.nvidia.com/compute/cuda/11.4.1/network_installers/cuda_11.4.1_win10_network.exe" - "11.4.2" = "https://developer.download.nvidia.com/compute/cuda/11.4.1/network_installers/cuda_11.4.1_win10_network.exe" - "11.5.0" = "https://developer.download.nvidia.com/compute/cuda/11.5.0/network_installers/cuda_11.5.0_win10_network.exe" - "11.5.1" = "https://developer.download.nvidia.com/compute/cuda/11.5.1/network_installers/cuda_11.5.1_windows_network.exe" - "11.6.0" = "https://developer.download.nvidia.com/compute/cuda/11.6.0/network_installers/cuda_11.6.0_windows_network.exe" + "11.3.0" = "https://developer.download.nvidia.com/compute/cuda/11.3.0/network_installers/cuda_11.3.0_win10_network.exe"; + "11.3.1" = "https://developer.download.nvidia.com/compute/cuda/11.3.1/network_installers/cuda_11.3.1_win10_network.exe"; + "11.4.0" = "https://developer.download.nvidia.com/compute/cuda/11.4.0/network_installers/cuda_11.4.0_win10_network.exe"; + "11.4.1" = "https://developer.download.nvidia.com/compute/cuda/11.4.1/network_installers/cuda_11.4.1_win10_network.exe"; + "11.4.2" = "https://developer.download.nvidia.com/compute/cuda/11.4.2/network_installers/cuda_11.4.2_win10_network.exe"; + "11.4.3" = "https://developer.download.nvidia.com/compute/cuda/11.4.3/network_installers/cuda_11.4.3_win10_network.exe"; + "11.4.4" = "https://developer.download.nvidia.com/compute/cuda/11.4.4/network_installers/cuda_11.4.4_win10_network.exe"; + "11.5.0" = "https://developer.download.nvidia.com/compute/cuda/11.5.0/network_installers/cuda_11.5.0_win10_network.exe"; + "11.5.1" = "https://developer.download.nvidia.com/compute/cuda/11.5.1/network_installers/cuda_11.5.1_windows_network.exe"; + "11.5.2" = "https://developer.download.nvidia.com/compute/cuda/11.5.2/network_installers/cuda_11.5.2_windows_network.exe"; + "11.6.0" = "https://developer.download.nvidia.com/compute/cuda/11.6.0/network_installers/cuda_11.6.0_windows_network.exe"; + "11.6.1" = "https://developer.download.nvidia.com/compute/cuda/11.6.1/network_installers/cuda_11.6.1_windows_network.exe"; + "11.6.2" = "https://developer.download.nvidia.com/compute/cuda/11.6.2/network_installers/cuda_11.6.2_windows_network.exe"; + "11.7.0" = "https://developer.download.nvidia.com/compute/cuda/11.7.0/network_installers/cuda_11.7.0_windows_network.exe"; } # @todo - change this to be based on _MSC_VER intead, or invert it to be CUDA keyed instead? @@ -50,6 +56,7 @@ $CUDA_PACKAGES_IN = @( "curand_dev"; "nvrtc_dev"; "cudart"; + "thrust"; ) @@ -100,9 +107,11 @@ Foreach ($package in $CUDA_PACKAGES_IN) { $package="compiler" } elseif($package -eq "compiler" -and [version]$CUDA_VERSION_FULL -ge [version]"9.1") { $package="nvcc" - } + } elseif($package -eq "thrust" -and [version]$CUDA_VERSION_FULL -lt [version]"11.3") { + # Thrust is a package from CUDA 11.3, otherwise it should be skipped. + continue + } $CUDA_PACKAGES += " $($package)_$($CUDA_MAJOR).$($CUDA_MINOR)" - } echo "$($CUDA_PACKAGES)" ## ----------------- diff --git a/.github/workflows/Manylinux2014.yml b/.github/workflows/Manylinux2014.yml index 0e645e9..a84bb9e 100644 --- a/.github/workflows/Manylinux2014.yml +++ b/.github/workflows/Manylinux2014.yml @@ -32,10 +32,6 @@ jobs: cuda_arch: "35" hostcxx: devtoolset-8 os: ubuntu-20.04 - # - cuda: "10.0" - # cuda_arch: "35" - # hostcxx: devtoolset-7 - # os: ubuntu-18.04 config: - name: "Release" config: "Release" diff --git a/.github/workflows/Ubuntu.yml b/.github/workflows/Ubuntu.yml index abf78e7..008498b 100644 --- a/.github/workflows/Ubuntu.yml +++ b/.github/workflows/Ubuntu.yml @@ -24,14 +24,10 @@ jobs: # optional exclude: can be partial, include: must be specific matrix: cudacxx: - - cuda: "11.6" + - cuda: "11.7" cuda_arch: "35" hostcxx: gcc-8 os: ubuntu-20.04 - # - cuda: "10.0" - # cuda_arch: "35" - # hostcxx: gcc-7 - # os: ubuntu-18.04 config: - name: "Release" config: "Release" diff --git a/.github/workflows/Windows.yml b/.github/workflows/Windows.yml index b2164c0..932d234 100644 --- a/.github/workflows/Windows.yml +++ b/.github/workflows/Windows.yml @@ -24,7 +24,7 @@ jobs: # optional exclude: can be partial, include: must be specific matrix: cudacxx: - - cuda: "11.6.0" + - cuda: "11.7.0" cuda_arch: "35" hostcxx: "Visual Studio 16 2019" os: windows-2019 diff --git a/README.md b/README.md index 8ae9fd2..169eb67 100644 --- a/README.md +++ b/README.md @@ -7,13 +7,10 @@ It is unlikely to be useful independently. ## Requirements + [CMake](https://cmake.org/download/) `>= 3.18` - + CMake `>= 3.15` currently works, but support will be dropped in a future release. + [CUDA](https://developer.nvidia.com/cuda-downloads) `>= 11.0` and a Compute Capability `>= 3.5` NVIDIA GPU. - + CUDA `>= 10.0` currently works, but support will be dropped in a future release. + C++17 capable C++ compiler (host), compatible with the installed CUDA version + [Microsoft Visual Studio 2019](https://visualstudio.microsoft.com/) (Windows) - + [make](https://www.gnu.org/software/make/) and either [GCC](https://gcc.gnu.org/) `>= 7` or [Clang](https://clang.llvm.org/) `>= 5` (Linux) - + Older C++ compilers which support C++14 may currently work, but support will be dropped in a future release. + + [make](https://www.gnu.org/software/make/) and [GCC](https://gcc.gnu.org/) `>= 8.1` + [git](https://git-scm.com/) + [SDL](https://www.libsdl.org/) + [GLM](http://glm.g-truc.net/) *(consistent C++/GLSL vector maths functionality)* diff --git a/cmake/cxxstd.cmake b/cmake/cxxstd.cmake index 19ca287..b9d5af2 100644 --- a/cmake/cxxstd.cmake +++ b/cmake/cxxstd.cmake @@ -1,60 +1,31 @@ -# Select the CXX standard to use. +# Select the CXX standard to use, FLAME GPU 2 is c++17 only if(NOT FLAMEGPU_CXX_STD) - # FLAME GPU is c++14, however due to MSVC 16.10 regressions we build as 17 if possible, else 14. - # 14 Support is still required (CUDA 10.x, swig?). - # Start by assuming both should be availble. # No need to check CMake version, as our minimum (3.18) supports CUDA c++17 - set(CXX17_SUPPORTED ON) - # Check the CU - # CUDA 11.0 adds CXX 17 - # CUDA 9.0 adds CXX 14 - if(CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 11.0.0) - # 17 is ok. - elseif(CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 9.0.0) - # 14 is ok, 17 is not. - # no need for an extra deprecation warning here, already warning in common about CUDA version. - set(CXX17_SUPPORTED OFF) - else() + # Check the CUDA version, CUDA 11.0 adds CXX 17 support + if(CMAKE_CUDA_COMPILER_VERSION VERSION_LESS 11.0.0) # Fatal Error. - message(FATAL_ERROR "CUDA ${CMAKE_CUDA_COMPILER_VERSION} does not support -std=c++14") + message(FATAL_ERROR "CUDA ${CMAKE_CUDA_COMPILER_VERSION} does not support -std=c++17") endif() - # VS 2019 16.10.0 breaks CXX 14 + cuda. - 1930? 19.29.30037? - # VS 2017 version 15.3 added /std:c++17 - 1911 - # MSVC VS2015 Update 3 added /std:c++14 >= 1900 && < 1910? + # Check MSVC version, VS 2017 version 15.3 added /std:c++17 - 1911 + # Inside source code, __STDC_VERSION__ can be used on msvc, which will have a value such as 201710L for c++17 if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.29) - # 17 required. - if(NOT CXX17_SUPPORTED) - message(FATAL_ERROR "MSVC >= 19.29 requires CUDA >= 11.0") - endif() - elseif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.11) - # 17 available? - elseif(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.10) - # Emit a deprecation warning for VS20XX that is not c++17 supporting. I think this is VS2017 which will be broken anyway with CUDA - message(DEPRECATION "Use of MSVC ${CMAKE_CXX_COMPILER_VERSION} is deprecated. A C++17 compiler (>= 19.11) will be required in a future release.") - set(CXX17_SUPPORTED OFF) - else() - message(FATAL_ERROR "MSVC ${CMAKE_CXX_COMPILER_VERSION} does not support -std=c++14") + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.11) + message(FATAL_ERROR "MSVC ${CMAKE_CXX_COMPILER_VERSION} does not support -std=c++17 (>= 19.11 required)") endif() endif() - # gcc supported C++17 since 5, so any version supported by cuda 10+ (no need to check, a configure time error will already occur.) - # Inside source code, __STDC_VERSION__ can be used on msvc, which will have a value such as 201710L for c++17 + # GCC 8 required for + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.1) + message(FATAL_ERROR "GCC >= 8.1 required for -std=c++17 ") + endif() # Set a cmake variable so this is only calcualted once, and can be applied afterwards. - if(CXX17_SUPPORTED) - set(FLAMEGPU_CXX_STD 17) - else() - set(FLAMEGPU_CXX_STD 14) - endif() - # if(NOT CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) - # # Forward to the parent scope so it persists between calls. - # set(FLAMEGPU_CXX_STD ${FLAMEGPU_CXX_STD} PARENT_SCOPE) - # endif() + set(FLAMEGPU_CXX_STD 17) # Emit a developer warning if using CUDA 11.0 and GCC 9 in c++17 mode re std::vector>::push_back + # @todo - promote this to a try compile, and issue the (author) warning if the erorr is encountered? if( CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL "11.0" AND CMAKE_CUDA_COMPILER_VERSION VERSION_LESS "11.1" AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU" diff --git a/cmake/warnings.cmake b/cmake/warnings.cmake index 48ade78..cc90a2d 100644 --- a/cmake/warnings.cmake +++ b/cmake/warnings.cmake @@ -100,11 +100,6 @@ if(NOT COMMAND SuppressSomeCompilerWarnings) # C4127: conditional expression is constant. Longer term true static assertions would be better. target_compile_options(${SSCW_TARGET} PRIVATE "$<$:SHELL:-Xcompiler /wd4127>") target_compile_options(${SSCW_TARGET} PRIVATE "$<$:/wd4127>") - # Suppress some VS2015 specific warnings. - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.10) - target_compile_options(${SSCW_TARGET} PRIVATE "$<$:SHELL:-Xcompiler /wd4091>") - target_compile_options(${SSCW_TARGET} PRIVATE "$<$:/wd4091>") - endif() # Suppress Fatbinc warnings on msvc at link time (CMake >= 3.18) target_link_options(${SSCW_TARGET} PRIVATE "$") # CUDA 11.6 deprecates __device__ cudaDeviceSynchronize, but does not provide an alternative. @@ -177,10 +172,8 @@ if(NOT COMMAND EnableWarningsAsErrors) # Platform/host-compiler indifferent options: # Generic WError settings for nvcc target_compile_options(${EWAS_TARGET} PRIVATE "$<$:SHELL:-Xptxas=\"-Werror\" -Xnvlink=\"-Werror\">") - # If CUDA 10.2+, add all_warnings to the Werror option - if(CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL "10.2") - target_compile_options(${EWAS_TARGET} PRIVATE "$<$:SHELL:-Werror all-warnings>") - endif() + # Add all_warnings to the Werror option (supported by all CUDA 11.x+) + target_compile_options(${EWAS_TARGET} PRIVATE "$<$:SHELL:-Werror all-warnings>") endif() endfunction() endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d50714c..bdbeef5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,7 +13,10 @@ project(flamegpu_visualiser) # handle cpplint. include(${CMAKE_CURRENT_LIST_DIR}/../cmake/cpplint.cmake) -# Check to see if CUDA is available. +# Check to see if CUDA is available, and meets the required minimum version for non-lint builds +if(NOT DEFINED MINIMUM_CUDA_VERSION) + set(MINIMUM_CUDA_VERSION 11.0) +endif() include(CheckLanguage) check_language(CUDA) if(CMAKE_CUDA_COMPILER) @@ -165,8 +168,8 @@ if(LINT_ONLY_BUILD) if (NOT OPENGL_FOUND) message(STATUS "OpenGL is required for building") endif () - if (NOT CMAKE_CUDA_COMPILER) - message(STATUS "CUDA is required for building") + if (NOT CMAKE_CUDA_COMPILER OR CMAKE_CUDA_COMPILER_VERSION VERSION_LESS ${MINIMUM_CUDA_VERSION}) + message(STATUS "CUDA >= ${MINIMUM_CUDA_VERSION} is required for building") endif () # return from the file. return() @@ -176,10 +179,9 @@ endif() if (NOT OPENGL_FOUND) message(FATAL_ERROR "OpenGL is required for building") endif () -if (NOT CMAKE_CUDA_COMPILER) - message(FATAL_ERROR "CUDA is required for building") +if (NOT CMAKE_CUDA_COMPILER OR CMAKE_CUDA_COMPILER_VERSION VERSION_LESS ${MINIMUM_CUDA_VERSION}) + message(FATAL_ERROR "CUDA >= ${MINIMUM_CUDA_VERSION} is required for building") endif () - # Include the warnings cmake file. Disabling all warning by default, and providing a mechanism to opt-in for some targets include(${CMAKE_CURRENT_LIST_DIR}/../cmake/warnings.cmake) @@ -225,15 +227,13 @@ if (WIN32) target_compile_definitions("${PROJECT_NAME}" PRIVATE _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_WARNINGS) endif() -# Ensure VS uses SYSTEM if available. +# Ensure VS uses SYSTEM if available, present in 19.10+ if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.10) - # These flags don't currently have any effect on how CMake passes system-private includes to msvc (VS 2017+) - set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "/external:I") - set(CMAKE_INCLUDE_SYSTEM_FLAG_CUDA "/external:I") - # VS 2017+ - target_compile_options("${PROJECT_NAME}" PRIVATE "$<$:/experimental:external>") - endif() + # These flags don't currently have any effect on how CMake passes system-private includes to msvc (VS 2017+) + set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "/external:I") + set(CMAKE_INCLUDE_SYSTEM_FLAG_CUDA "/external:I") + # VS 2017+ + target_compile_options("${PROJECT_NAME}" PRIVATE "$<$:/experimental:external>") endif() # Set up include dirs @@ -263,8 +263,8 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") endif() # If gcc, need to add flag for std::experimental::filesystem (for c++14 support) -if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - target_link_libraries("${PROJECT_NAME}" "-lstdc++fs") +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0) + target_link_libraries("${PROJECT_NAME}" stdc++fs) endif() # Strip trailiing whitespace from SDL2_Libraries for Ubuntu1604 / libsdl2-dev 2.0.4 From f3bd0787e12fac119119271d1c01115c5902c6a7 Mon Sep 17 00:00:00 2001 From: Peter Heywood Date: Mon, 16 May 2022 11:02:03 +0100 Subject: [PATCH 2/2] Use std::filesystem --- src/CMakeLists.txt | 2 +- src/flamegpu/visualiser/shader/ShaderCore.cpp | 39 +----------- src/flamegpu/visualiser/texture/Texture2D.cpp | 18 +----- src/flamegpu/visualiser/util/Resources.cpp | 61 ++++++------------- 4 files changed, 23 insertions(+), 97 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bdbeef5..a47797f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -262,7 +262,7 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") target_link_libraries("${PROJECT_NAME}" "legacy_stdio_definitions") # This won't be required if we rebuild freetype with newer than vs2013 endif() -# If gcc, need to add flag for std::experimental::filesystem (for c++14 support) +# If gcc < 9, needs to link against stdc++fs if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0) target_link_libraries("${PROJECT_NAME}" stdc++fs) endif() diff --git a/src/flamegpu/visualiser/shader/ShaderCore.cpp b/src/flamegpu/visualiser/shader/ShaderCore.cpp index a4a544b..7b9c1b6 100644 --- a/src/flamegpu/visualiser/shader/ShaderCore.cpp +++ b/src/flamegpu/visualiser/shader/ShaderCore.cpp @@ -594,47 +594,10 @@ int ShaderCore::compileShader(const GLuint t_shaderProgram, GLenum type, std::ve } return rtn; } -// If earlier than VS 2019 -// #if defined(_MSC_VER) && _MSC_VER < 1920 -// #include -// using std::tr2::sys::exists; -// using std::tr2::sys::path; -// #else -// // VS2019 requires this macro, as building pre c++17 cant use std::filesystem -// #define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING -// #include -// using std::experimental::filesystem::v1::exists; -// using std::experimental::filesystem::v1::path; -// #endif + char* ShaderCore::loadShaderSource(const char* file) { - // static std::string shadersRoot; - // if (shadersRoot.empty()) { - // // Locate the root directory of the solution - // // Follow up tree a few layers checking for a shaders directory. - // shadersRoot = "./shaders/"; - // for (unsigned int i = 0; i < 5; ++i) { - // if (exists(path(shadersRoot))) - // break; - // shadersRoot = std::string("./.") + shadersRoot; - // } - // if (!exists(path(shadersRoot))) - // shadersRoot = "./"; - // } // If file path is 0 it is being omitted. kinda gross if (file != nullptr) { - // std::string shaderPath = shadersRoot + file; - // FILE* fptr = fopen(shaderPath.c_str(), "rb"); // Attempt with shader root - // if (!fptr) { - // fptr = fopen(file, "rb"); // Attempt without shader root - // if (!fptr) { - // fprintf(stderr, "Shader source not found: %s\n", file); - // if (exitOnError) { - // getchar(); - // exit(1); - // } - // return nullptr; - // } - // } FILE* fptr = Resources::fopen(file, "rb"); // Attempt with shader root fseek(fptr, 0, SEEK_END); int64_t length = ftell(fptr); diff --git a/src/flamegpu/visualiser/texture/Texture2D.cpp b/src/flamegpu/visualiser/texture/Texture2D.cpp index fa94e88..f424210 100644 --- a/src/flamegpu/visualiser/texture/Texture2D.cpp +++ b/src/flamegpu/visualiser/texture/Texture2D.cpp @@ -1,18 +1,6 @@ #include "flamegpu/visualiser/texture/Texture2D.h" #include - -// If earlier than VS 2019 -#if defined(_MSC_VER) && _MSC_VER < 1920 #include -using std::tr2::sys::exists; -using std::tr2::sys::path; -#else -// VS2019 requires this macro, as building pre c++17 cant use std::filesystem -#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING -#include -using std::experimental::filesystem::v1::exists; -using std::experimental::filesystem::v1::path; -#endif #include #include @@ -86,13 +74,13 @@ std::shared_ptr Texture2D::load(const std::string &texPath, con // Locate the file std::string filePath; // Raw exists - if (exists(path(texPath))) + if (std::filesystem::exists(std::filesystem::path(texPath))) filePath = texPath; // Exists in model dir - else if (!modelFolder.empty() && exists(path((modelFolder + texPath).c_str()))) + else if (!modelFolder.empty() && std::filesystem::exists(std::filesystem::path((modelFolder + texPath).c_str()))) filePath = modelFolder + texPath; // Exists in model dir [path incorrect] - else if (!modelFolder.empty() && exists(path((modelFolder + su::getFilenameFromPath(texPath)).c_str()))) + else if (!modelFolder.empty() && std::filesystem::exists(std::filesystem::path((modelFolder + su::getFilenameFromPath(texPath)).c_str()))) filePath = std::string(modelFolder) + su::getFilenameFromPath(texPath); // Exists in resources else if (Resources::exists(texPath)) diff --git a/src/flamegpu/visualiser/util/Resources.cpp b/src/flamegpu/visualiser/util/Resources.cpp index 5634bcb..cd3b71b 100644 --- a/src/flamegpu/visualiser/util/Resources.cpp +++ b/src/flamegpu/visualiser/util/Resources.cpp @@ -1,21 +1,6 @@ #include "flamegpu/visualiser/util/Resources.h" #include "VisException.h" -// If earlier than VS 2019 -#if defined(_MSC_VER) && _MSC_VER < 1920 #include -using std::tr2::sys::temp_directory_path; -using std::tr2::sys::exists; -using std::tr2::sys::path; -using std::tr2::sys::create_directory; -#else -// VS2019 requires this macro, as building pre c++17 cant use std::filesystem -#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING -#include -using std::experimental::filesystem::v1::temp_directory_path; -using std::experimental::filesystem::v1::exists; -using std::experimental::filesystem::v1::path; -using std::experimental::filesystem::v1::create_directory; -#endif #include #include @@ -25,33 +10,23 @@ namespace flamegpu { namespace visualiser { namespace { - void recursive_create_dir(const path &dir) { - if (::exists(dir)) { - return; - } - path parent_dir = dir.parent_path(); - if (!::exists(parent_dir)) { - recursive_create_dir(parent_dir); - } - create_directory(dir); - } - path getTMP() { - static path result; + std::filesystem::path getTMP() { + static std::filesystem::path result; if (result.empty()) { - path tmp = std::getenv("FLAMEGPU2_TMP_DIR") ? std::getenv("FLAMEGPU2_TMP_DIR") : temp_directory_path(); + std::filesystem::path tmp = std::getenv("FLAMEGPU2_TMP_DIR") ? std::getenv("FLAMEGPU2_TMP_DIR") : std::filesystem::temp_directory_path(); // Create the $tmp/flamegpu/vis folder hierarchy - if (!::exists(tmp) && !create_directory(tmp)) { + if (!std::filesystem::exists(tmp) && !std::filesystem::create_directories(tmp)) { THROW InvalidFilePath("Directory '%s' does not exist and cannot be created by visualisation.", tmp.generic_string().c_str()); } if (!std::getenv("FLAMEGPU2_TMP_DIR")) { tmp /= "flamegpu"; - if (!::exists(tmp)) { - create_directory(tmp); + if (!std::filesystem::exists(tmp)) { + std::filesystem::create_directories(tmp); } } tmp /= "vis"; - if (!::exists(tmp)) { - create_directory(tmp); + if (!std::filesystem::exists(tmp)) { + std::filesystem::create_directories(tmp); } result = tmp; } @@ -73,17 +48,17 @@ FILE *Resources::fopen(const char * filename, const char *mode) { std::string Resources::locateFile(const std::string &_path) { // Convert the path into '_filename.file_ext' - const path t_filename = path(std::to_string(hash_larson64(_path.c_str())).append("_").append(path(_path).filename().generic_string())); + const std::filesystem::path t_filename = std::filesystem::path(std::to_string(hash_larson64(_path.c_str())).append("_").append(std::filesystem::path(_path).filename().generic_string())); // File exists in working directory, use that { - if (::exists(path(_path))) + if (std::filesystem::exists(std::filesystem::path(_path))) return _path; } - path temp_dir_path = path(getTMP()); + std::filesystem::path temp_dir_path = std::filesystem::path(getTMP()); temp_dir_path /= t_filename; // See if file exists in temp dir, use that { - if (::exists(temp_dir_path)) { + if (std::filesystem::exists(temp_dir_path)) { return temp_dir_path.string(); } else { // file doesn't exist in temp dir, so create it there @@ -93,9 +68,9 @@ std::string Resources::locateFile(const std::string &_path) { const auto resource_file = fs.open(_path); // open a file to temp_dir_path // Check the output directory exists - path output_dir = temp_dir_path; + std::filesystem::path output_dir = temp_dir_path; output_dir.remove_filename(); - recursive_create_dir(output_dir); + std::filesystem::create_directories(output_dir); // we will extract the file to here FILE *out_file = ::fopen(temp_dir_path.string().c_str(), "wb"); fwrite(resource_file.begin(), resource_file.size(), 1, out_file); @@ -117,12 +92,12 @@ bool Resources::exists(const std::string &path) { std::string Resources::toTempDir(const std::string &_path) { // Convert the path into '_filename.file_ext' - const path t_filename = path(std::to_string(hash_larson64(_path.c_str())).append("_").append(path(_path).filename().generic_string())); - path output_dir = getTMP(); + const std::filesystem::path t_filename = std::filesystem::path(std::to_string(hash_larson64(_path.c_str())).append("_").append(std::filesystem::path(_path).filename().generic_string())); + std::filesystem::path output_dir = getTMP(); output_dir /= t_filename; - const path output_path = output_dir; + const std::filesystem::path output_path = output_dir; output_dir.remove_filename(); - recursive_create_dir(output_dir); + std::filesystem::create_directories(output_dir); return output_path.string(); }