From 95510a07d436854d1e32eef116f3da96aa6be155 Mon Sep 17 00:00:00 2001 From: Levi Burner Date: Thu, 2 Jun 2022 22:14:08 -0400 Subject: [PATCH] Simulate: fix MacOS build (still crashes due to GLFW misusage) --- simulate/CMakeLists.txt | 12 ++++++------ simulate/simulate.cc | 25 ++++++++++++------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/simulate/CMakeLists.txt b/simulate/CMakeLists.txt index 6442bb9b..f46ba3f6 100644 --- a/simulate/CMakeLists.txt +++ b/simulate/CMakeLists.txt @@ -84,9 +84,14 @@ target_sources(mjsimulate PUBLIC simulate.h array_safety.h simulate.cc) target_include_directories(mjsimulate PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_compile_definitions(mjsimulate PUBLIC MJSIMULATE_DLL_EXPORTS) target_compile_options(mjsimulate PUBLIC ${MUJOCO_SIMULATE_COMPILE_OPTIONS}) -target_link_libraries(mjsimulate PUBLIC glfw uitools mujoco::mujoco) # TODO is that right +target_link_libraries(mjsimulate PUBLIC glfw uitools mujoco::mujoco) target_link_options(mjsimulate PRIVATE ${MUJOCO_SIMULATE_LINK_OPTIONS}) +if(APPLE) + target_sources(mjsimulate PRIVATE macos_save.mm) + target_link_libraries(mjsimulate PUBLIC "-framework Cocoa") +endif() + # Build samples that require GLFW. if(APPLE) @@ -125,11 +130,6 @@ else() target_link_options(simulate PRIVATE ${MUJOCO_SIMULATE_LINK_OPTIONS}) endif() -if(APPLE) - target_sources(simulate PRIVATE macos_save.mm) - target_link_libraries(simulate "-framework Cocoa") -endif() - if(APPLE AND MUJOCO_BUILD_MACOS_FRAMEWORKS) set_target_properties( simulate diff --git a/simulate/simulate.cc b/simulate/simulate.cc index 55815651..78eb1225 100644 --- a/simulate/simulate.cc +++ b/simulate/simulate.cc @@ -24,6 +24,18 @@ #include #include "array_safety.h" +// When launched via an App Bundle on macOS, the working directory is the path to the App Bundle's +// resource directory. This causes files to be saved into the bundle, which is not the desired +// behavior. Instead, we open a save dialog box to ask the user where to put the file. +// Since the dialog box logic needs to be written in Objective-C, we separate it into a different +// source file. +#ifdef __APPLE__ +std::string getSavePath(const char* filename); +#else +static std::string getSavePath(const char* filename) { + return filename; +} +#endif namespace { namespace mj = ::mujoco; @@ -1026,19 +1038,6 @@ void uiLayout(mjuiState* state) { rect[3].height = rect[0].height; } -// When launched via an App Bundle on macOS, the working directory is the path to the App Bundle's -// resource directory. This causes files to be saved into the bundle, which is not the desired -// behavior. Instead, we open a save dialog box to ask the user where to put the file. -// Since the dialog box logic needs to be written in Objective-C, we separate it into a different -// source file. -#ifdef __APPLE__ -std::string getSavePath(const char* filename); -#else -static std::string getSavePath(const char* filename) { - return filename; -} -#endif - // handle UI event void uiEvent(mjuiState* state) { mj::Simulate* simulate = (mj::Simulate*)(state->userdata);