Skip to content

Commit

Permalink
rootdir
Browse files Browse the repository at this point in the history
  • Loading branch information
zdenyhraz committed Jun 20, 2024
1 parent 814f574 commit 248617f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ else()
add_link_options(-fopenmp -pthread)
endif()

add_compile_definitions(PROJECT_DIRECTORY="${CMAKE_SOURCE_DIR}")

# ignore warnings from external sources
file(GLOB_RECURSE SRC_LIBS CONFIGURE_DEPENDS libs/*.h libs/*.hpp libs/*.c libs/*.cpp)
if(MSVC)
Expand Down
16 changes: 7 additions & 9 deletions src/Utils/Filesystem.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#pragma once

inline std::filesystem::path GetProjectDirectoryPath(std::string_view relpath = "", std::string_view identifier = "LICENSE.md")
inline std::filesystem::path GetProjectDirectoryPath()
{
auto path = std::filesystem::current_path();
for (usize trial = 0; trial < 10; ++trial)
{
if (std::filesystem::exists(path / identifier))
return relpath.empty() ? path : path / relpath;
path = path.parent_path();
}
throw std::runtime_error(fmt::format("Could not determine project directory via identifier '{}'", identifier));
return std::filesystem::path(PROJECT_DIRECTORY);
}

inline std::filesystem::path GetProjectDirectoryPath(std::string_view relpath)
{
return std::filesystem::path(PROJECT_DIRECTORY) / relpath;
}

inline usize GetFileCount(const std::filesystem::path& dirpath)
Expand Down

0 comments on commit 248617f

Please sign in to comment.