diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0267413..5f4d22f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,6 +3,7 @@ add_library( cps cps/env.cpp cps/loader.cpp + cps/platform.cpp cps/printer.cpp cps/search.cpp cps/utils.cpp diff --git a/src/cps/platform.cpp b/src/cps/platform.cpp new file mode 100644 index 0000000..ec72f15 --- /dev/null +++ b/src/cps/platform.cpp @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: MIT +// Copyright © 2024 Dylan Baker + +#include "cps/platform.hpp" + +namespace cps::platform { + + fs::path libdir() { return "lib"; } + + fs::path datadir() { return "share"; } + +} // namespace cps::platform diff --git a/src/cps/platform.hpp b/src/cps/platform.hpp new file mode 100644 index 0000000..c5036d2 --- /dev/null +++ b/src/cps/platform.hpp @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: MIT +// Copyright © 2024 Dylan Baker + +#include + +namespace cps::platform { + + namespace fs = std::filesystem; + + /// @brief Get the platform specific location that libraries are installed in + /// @return A path segment for libraries to be installed in, relative to a prefix + fs::path libdir(); + + /// @brief Get the platform specific location to install architecture agnostic data to + /// @return A path segment for data to be installed in, relative to a prefix + fs::path datadir(); + +} // namespace cps::platform diff --git a/src/cps/search.cpp b/src/cps/search.cpp index 0b3080f..01a21c5 100644 --- a/src/cps/search.cpp +++ b/src/cps/search.cpp @@ -6,6 +6,7 @@ #include "cps/error.hpp" #include "cps/loader.hpp" +#include "cps/platform.hpp" #include "cps/utils.hpp" #include "cps/version.hpp" @@ -71,19 +72,6 @@ namespace cps::search { return out; } - fs::path libdir() { - // TODO: libdir needs to be configurable based on the personality, - // and different name schemes. - // This is complicated by the fact that different distros have - // different schemes. - return "lib"; - } - - fs::path datadir() { - // TODO: needs to be configurable. see libdir above. - return "share"; - } - const std::vector nix_prefix{"/usr", "/usr/local"}; // TODO: const std::vector mac_prefix{""}; // TODO: const std::vector win_prefix{""}; @@ -100,8 +88,8 @@ namespace cps::search { // TODO: Windows specific paths // TODO: handle name-like search paths - paths.emplace_back(prefix / libdir() / "cps"); - paths.emplace_back(prefix / datadir() / "cps"); + paths.emplace_back(prefix / platform::libdir() / "cps"); + paths.emplace_back(prefix / platform::datadir() / "cps"); return paths; }; diff --git a/src/meson.build b/src/meson.build index c4a6ca6..cf91990 100644 --- a/src/meson.build +++ b/src/meson.build @@ -9,6 +9,7 @@ libcps = static_library( 'cps', 'cps/env.cpp', 'cps/loader.cpp', + 'cps/platform.cpp', 'cps/printer.cpp', 'cps/search.cpp', 'cps/utils.cpp',