Skip to content

Commit

Permalink
getCurrentExecutablePath() on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
MeijisIrlnd committed May 26, 2024
1 parent b022661 commit 0f65933
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Resources/[Pp]resets
*.pkg
**.pkg
installer/macOS/[Pp]ayload/*
.vscode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
Expand Down
11 changes: 8 additions & 3 deletions source/utils/marvin_Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@
#include <marvin/utils/marvin_Utils.h>

#if defined(MARVIN_MACOS)

#include <mach-o/dyld.h>
#elif defined(MARVIN_WINDOWS)
#include <windows.h>
#elif defined(MARVIN_LINUX)

#endif
namespace marvin::utils {
std::optional<std::string> getCurrentExecutablePath() {
constexpr static auto maxLength{ 512 };
#if defined(MARVIN_MACOS)
return {};
char data[maxLength];
std::uint32_t length{ sizeof(data) };
const auto resCode = _NSGetExecutablePath(data, &length);
if(resCode != 0) return {};
std::string res = data;
return res;
#elif defined(MARVIN_WINDOWS)
constexpr static auto maxLength{ 512 };
char data[maxLength];
auto dest = (LPSTR)data;
GetModuleFileName(nullptr, dest, maxLength);
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ set(MARVIN_TEST_SOURCE
${CMAKE_CURRENT_SOURCE_DIR}/math/marvin_LeakyIntegratorTests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/math/marvin_VecOpsTests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/math/marvin_WindowedSincInterpolatorTests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/utils/marvin_UtilsTests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/utils/marvin_SmoothedValueTests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/utils/marvin_RandomTests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/utils/marvin_FIFOTests.cpp
Expand Down
22 changes: 22 additions & 0 deletions tests/utils/marvin_UtilsTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// ========================================================================================================
// _______ _______ ______ ___ ___ _______ _______
// | | | _ | __ \ | |_ _| | |
// | | | < | |_| |_| |
// |__|_|__|___|___|___|__|\_____/|_______|__|____|
//
// This file is part of the Marvin open source library and is licensed under the terms of the MIT License.
//
// ========================================================================================================

#include <marvin/utils/marvin_Utils.h>
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
#include <iostream>
namespace marvin::testing {
TEST_CASE("Test getCurrentExecutablePath()") {
const auto pathRes = utils::getCurrentExecutablePath();
REQUIRE(pathRes);
std::cout << *pathRes << "\n";
}

}

0 comments on commit 0f65933

Please sign in to comment.