Skip to content

Commit

Permalink
cmake: link tools to stdc++fs and experimental filesystem library if …
Browse files Browse the repository at this point in the history
…necessary (#456)
  • Loading branch information
evetsso authored Mar 5, 2024
1 parent c6f7b0e commit e2fd976
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion test/internal/test_cpp_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::array<int,3>> combination_set(combinations.begin(), combinations.end());
ASSERT_EQ(combinations.size(), combination_set.size()) << "Not all items are unique";

for(auto [a, b, c] : combinations)
Expand Down
18 changes: 18 additions & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,29 @@

set(CMAKE_CXX_STANDARD 17)

include(CheckCXXSourceCompiles)

set(HAVE_STD_FILESYSTEM_TEST [[
#include <filesystem>

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)
Expand Down
1 change: 0 additions & 1 deletion tools/bin2typed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include "utils.hpp"

#include <filesystem>
#include <fstream>
#include <iomanip>
#include <ios>
Expand Down
1 change: 0 additions & 1 deletion tools/scrambled_sobol32_direction_vector_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "sobol_utils.hpp"
#include "utils.hpp"

#include <filesystem>
#include <fstream>
#include <ios>
#include <iostream>
Expand Down
1 change: 0 additions & 1 deletion tools/scrambled_sobol64_direction_vector_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "sobol_utils.hpp"
#include "utils.hpp"

#include <filesystem>
#include <fstream>
#include <ios>
#include <iostream>
Expand Down
1 change: 0 additions & 1 deletion tools/sobol32_direction_vector_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "sobol_utils.hpp"
#include "utils.hpp"

#include <filesystem>
#include <fstream>
#include <iostream>
#include <string_view>
Expand Down
9 changes: 9 additions & 0 deletions tools/sobol_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@
#ifndef ROCRAND_TOOLS_SOBOL_UTILS_HPP_
#define ROCRAND_TOOLS_SOBOL_UTILS_HPP_

#if __has_include(<filesystem>)
#include <filesystem>
#else
#include <experimental/filesystem>
namespace std
{
namespace filesystem = experimental::filesystem;
}
#endif

#include <fstream>
#include <iostream>

Expand Down
9 changes: 9 additions & 0 deletions tools/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@
#ifndef ROCRAND_TOOLS_UTILS_HPP_
#define ROCRAND_TOOLS_UTILS_HPP_

#if __has_include(<filesystem>)
#include <filesystem>
#else
#include <experimental/filesystem>
namespace std
{
namespace filesystem = experimental::filesystem;
}
#endif

#include <fstream>
#include <string_view>

Expand Down

0 comments on commit e2fd976

Please sign in to comment.