Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: macOS port #24

Draft
wants to merge 1 commit into
base: devel
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,19 @@ if(UNIX)
include(${CMAKE_MODULE_PATH}/Findlibusb.cmake)
find_package(libusb REQUIRED)
find_package(glfw3 REQUIRED)
set(STLINK_LINUX ${CMAKE_CURRENT_SOURCE_DIR}/third_party/stlink/lib/linux/libstlink.a)
set(SPDLOG_LINUX ${CMAKE_CURRENT_SOURCE_DIR}/third_party/spdlog/lib/linux/libspdlog.so.1.11.0)
set(INSTALL_PATH /usr/local/STMViewer)
set(DESKTOP_FILE_PATH /usr/share/applications)
if(APPLE)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
set(STLINK_MACOS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/stlink/lib/macos/libstlink.a)
set(SPDLOG_MACOS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/spdlog/lib/macos/libspdlog.a)
set(INSTALL_PATH /usr/local/STMViewer)
set(DESKTOP_FILE_PATH /usr/share/applications)
else()
set(STLINK_LINUX ${CMAKE_CURRENT_SOURCE_DIR}/third_party/stlink/lib/linux/libstlink.a)
set(SPDLOG_LINUX ${CMAKE_CURRENT_SOURCE_DIR}/third_party/spdlog/lib/linux/eibspdlog.so.1.11.0)
set(INSTALL_PATH /usr/local/STMViewer)
set(DESKTOP_FILE_PATH /usr/share/applications)
endif()
endif()

if(WIN32)
Expand Down Expand Up @@ -150,7 +159,10 @@ target_include_directories(${EXECUTABLE} SYSTEM PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/third_party/nfd/src/include/
${CMAKE_CURRENT_SOURCE_DIR}/third_party/spdlog/inc/)

if(UNIX)
if(APPLE)
include_directories(${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS} ${STLINK_INCLUDE_DIRS} )
target_link_libraries(${EXECUTABLE} ${STLINK_MACOS} ${LIBUSB_LIBRARY} ${SPDLOG_MACOS} ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} pthread dl glfw nfd)
elseif(UNIX)
target_link_libraries(${EXECUTABLE} ${STLINK_LINUX} ${LIBUSB_LIBRARY} ${SPDLOG_LINUX} pthread dl GL glfw nfd)
elseif(WIN32)
target_link_libraries(${EXECUTABLE} ${GLFW3_WINDOWS} ${STLINK_WINDOWS} ${LIBUSB_WINDOWS} ${SPDLOG_WINDOWS} -static ssp opengl32 nfd -static-libstdc++ -static-libgcc)
Expand Down
5 changes: 2 additions & 3 deletions src/ConfigHandler/ConfigHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
class ConfigHandler
{
public:
typedef struct
{
struct GlobalSettings {
uint32_t version = 0;
} GlobalSettings;
} ;

ConfigHandler(const std::string& configFilePath, PlotHandler* plotHandler, TracePlotHandler* tracePlotHandler, std::shared_ptr<spdlog::logger> logger);
~ConfigHandler() = default;
Expand Down
2 changes: 2 additions & 0 deletions src/ElfReader/ElfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ std::string ElfReader::executeCommand(const char* cmd)
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
#elif _WIN32
std::unique_ptr<FILE, decltype(&_pclose)> pipe(_popen(cmd, "r"), _pclose);
#elif defined(__APPLE__)
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
#else
#error "Your system is not supported!"
#endif
Expand Down
6 changes: 6 additions & 0 deletions src/Gui/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ void Gui::mainThread()
if (!glfwInit())
return;

#if defined(__APPLE__)
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#endif
GLFWwindow* window = glfwCreateWindow(1500, 1000, (std::string("STMViewer | ") + projectConfigPath).c_str(), NULL, NULL);
if (window == NULL)
return;
Expand Down
7 changes: 7 additions & 0 deletions src/Gui/GuiAbout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ bool Gui::openWebsite(const char* url)
char command[256];
snprintf(command, sizeof(command), "%s %s", browser, url);
system(command);
#elif defined(__APPLE__)
const char* browser = getenv("BROWSER");
if (browser == NULL)
browser = "xdg-open";
char command[256];
snprintf(command, sizeof(command), "%s %s", browser, url);
system(command);
#else
#error "Your system is not supported!"
#endif
Expand Down
5 changes: 2 additions & 3 deletions src/PlotHandler/TracePlotHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
class TracePlotHandler : public PlotHandlerBase
{
public:
typedef struct
{
struct Settings {
uint32_t coreFrequency = 160000;
uint32_t tracePrescaler = 10;
uint32_t maxPoints = 10000;
uint32_t maxViewportPointsPercent = 10;
int32_t triggerChannel = -1;
double triggerLevel = 0.9;
bool shouldReset = false;
} Settings;
} ;

TracePlotHandler(std::atomic<bool>& done, std::mutex* mtx, std::shared_ptr<spdlog::logger> logger);
~TracePlotHandler();
Expand Down
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ int main(int argc, char** argv)
std::string logDirectory = std::string(std::getenv("HOME")) + "/STMViewer/logs/logfile.txt";
#elif _WIN32
std::string logDirectory = std::string(std::getenv("APPDATA")) + "/STMViewer/logs/logfile.txt";
#elif defined(__APPLE__)
std::string logDirectory = std::string(std::getenv("HOME")) + "/STMViewer/logs/logfile.txt";
#else
#error "Your system is not supported!"
#endif
Expand Down
Binary file added third_party/spdlog/lib/macos/libspdlog.a
Binary file not shown.
2 changes: 1 addition & 1 deletion third_party/stlink/inc/spdlogWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int spdlogLog(int level, const char* str, ...)
va_start(args, str);

char buf[1000]{};
vsprintf(buf, str, args);
vsnprintf(buf, 1000, str, args);
buf[strlen(buf) - 1] = '\0';

switch (level)
Expand Down
Binary file added third_party/stlink/lib/macos/libstlink.a
Binary file not shown.