From e2fd976077284e0c9ba9aade87ff6bfde919ec01 Mon Sep 17 00:00:00 2001 From: Steve Leung Date: Tue, 5 Mar 2024 07:34:04 -0700 Subject: [PATCH] cmake: link tools to stdc++fs and experimental filesystem library if necessary (#456) --- test/internal/test_cpp_utils.cpp | 2 +- tools/CMakeLists.txt | 18 ++++++++++++++++++ tools/bin2typed.cpp | 1 - ...bled_sobol32_direction_vector_generator.cpp | 1 - ...bled_sobol64_direction_vector_generator.cpp | 1 - tools/sobol32_direction_vector_generator.cpp | 1 - tools/sobol_utils.hpp | 9 +++++++++ tools/utils.hpp | 9 +++++++++ 8 files changed, 37 insertions(+), 5 deletions(-) diff --git a/test/internal/test_cpp_utils.cpp b/test/internal/test_cpp_utils.cpp index 497c6469..c797d77f 100644 --- a/test/internal/test_cpp_utils.cpp +++ b/test/internal/test_cpp_utils.cpp @@ -57,7 +57,7 @@ TEST(rocrand_cpp_utils_tests, numeric_combinations) ASSERT_EQ(combinations.size(), A.size() * B.size() * C.size()); - const std::set combination_set(combinations.begin(), combinations.end()); + const std::set> combination_set(combinations.begin(), combinations.end()); ASSERT_EQ(combinations.size(), combination_set.size()) << "Not all items are unique"; for(auto [a, b, c] : combinations) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 95082c98..c4a1640d 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -22,11 +22,29 @@ set(CMAKE_CXX_STANDARD 17) +include(CheckCXXSourceCompiles) + +set(HAVE_STD_FILESYSTEM_TEST [[ + #include + + int main() + { + std::filesystem::path p{"/"}; + return 0; + } + ]]) +check_cxx_source_compiles("${HAVE_STD_FILESYSTEM_TEST}" HAVE_STD_FILESYSTEM) + add_custom_target(tools) function(rocrand_add_tool TARGET_NAME) add_executable(${TARGET_NAME} ${ARGN}) add_dependencies(tools ${TARGET_NAME}) + if(NOT HAVE_STD_FILESYSTEM) + # if filesystem library is not available in the standard library, + # link to the separate library instead + target_link_options( ${TARGET_NAME} PRIVATE -lstdc++fs ) + endif() endfunction() rocrand_add_tool(bin2typed bin2typed.cpp) diff --git a/tools/bin2typed.cpp b/tools/bin2typed.cpp index 66b2ab93..59c11d8e 100644 --- a/tools/bin2typed.cpp +++ b/tools/bin2typed.cpp @@ -20,7 +20,6 @@ #include "utils.hpp" -#include #include #include #include diff --git a/tools/scrambled_sobol32_direction_vector_generator.cpp b/tools/scrambled_sobol32_direction_vector_generator.cpp index 3445527e..5833c266 100644 --- a/tools/scrambled_sobol32_direction_vector_generator.cpp +++ b/tools/scrambled_sobol32_direction_vector_generator.cpp @@ -21,7 +21,6 @@ #include "sobol_utils.hpp" #include "utils.hpp" -#include #include #include #include diff --git a/tools/scrambled_sobol64_direction_vector_generator.cpp b/tools/scrambled_sobol64_direction_vector_generator.cpp index 04ae880f..80b99d81 100644 --- a/tools/scrambled_sobol64_direction_vector_generator.cpp +++ b/tools/scrambled_sobol64_direction_vector_generator.cpp @@ -21,7 +21,6 @@ #include "sobol_utils.hpp" #include "utils.hpp" -#include #include #include #include diff --git a/tools/sobol32_direction_vector_generator.cpp b/tools/sobol32_direction_vector_generator.cpp index 43cae3b7..91d6c31d 100644 --- a/tools/sobol32_direction_vector_generator.cpp +++ b/tools/sobol32_direction_vector_generator.cpp @@ -21,7 +21,6 @@ #include "sobol_utils.hpp" #include "utils.hpp" -#include #include #include #include diff --git a/tools/sobol_utils.hpp b/tools/sobol_utils.hpp index faf44ff9..a3a67a08 100644 --- a/tools/sobol_utils.hpp +++ b/tools/sobol_utils.hpp @@ -21,7 +21,16 @@ #ifndef ROCRAND_TOOLS_SOBOL_UTILS_HPP_ #define ROCRAND_TOOLS_SOBOL_UTILS_HPP_ +#if __has_include() #include +#else +#include +namespace std +{ + namespace filesystem = experimental::filesystem; +} +#endif + #include #include diff --git a/tools/utils.hpp b/tools/utils.hpp index 508b7176..d0ac10c0 100644 --- a/tools/utils.hpp +++ b/tools/utils.hpp @@ -21,7 +21,16 @@ #ifndef ROCRAND_TOOLS_UTILS_HPP_ #define ROCRAND_TOOLS_UTILS_HPP_ +#if __has_include() #include +#else +#include +namespace std +{ + namespace filesystem = experimental::filesystem; +} +#endif + #include #include