From 0503225928cad4c6590ee06cc8c863ab71bdd000 Mon Sep 17 00:00:00 2001 From: Prateek Machiraju Date: Sun, 20 Sep 2020 12:31:20 -0400 Subject: [PATCH] [build] CMake: Fix Metal linking on macOS (#2725) --- cmake/modules/LinkMacOSGUI.cmake | 5 +++++ cscore/CMakeLists.txt | 6 ++++++ simulation/halsim_gui/CMakeLists.txt | 3 +++ wpigui/CMakeLists.txt | 2 ++ 4 files changed, 16 insertions(+) create mode 100644 cmake/modules/LinkMacOSGUI.cmake diff --git a/cmake/modules/LinkMacOSGUI.cmake b/cmake/modules/LinkMacOSGUI.cmake new file mode 100644 index 0000000000..f76554eee8 --- /dev/null +++ b/cmake/modules/LinkMacOSGUI.cmake @@ -0,0 +1,5 @@ +macro(wpilib_link_macos_gui target) + if (APPLE) + set_target_properties(${target} PROPERTIES LINK_FLAGS "-framework Metal -framework QuartzCore") + endif() +endmacro() diff --git a/cscore/CMakeLists.txt b/cscore/CMakeLists.txt index 92bef994b9..aee280f087 100644 --- a/cscore/CMakeLists.txt +++ b/cscore/CMakeLists.txt @@ -3,6 +3,7 @@ project(cscore) include(SubDirList) include(CompileWarnings) include(AddTest) +include(LinkMacOSGUI) find_package( OpenCV REQUIRED ) @@ -63,6 +64,11 @@ foreach(example ${cscore_examples}) if(cscore_example_src) add_executable(cscore_${example} ${cscore_example_src}) wpilib_target_warnings(cscore_${example}) + + if (${example} STREQUAL "usbviewer") + wpilib_link_macos_gui(cscore_${example}) + endif() + target_link_libraries(cscore_${example} cscore ${add_libs}) set_property(TARGET cscore_${example} PROPERTY FOLDER "examples") endif() diff --git a/simulation/halsim_gui/CMakeLists.txt b/simulation/halsim_gui/CMakeLists.txt index 5d821269b2..424ff5bdc7 100644 --- a/simulation/halsim_gui/CMakeLists.txt +++ b/simulation/halsim_gui/CMakeLists.txt @@ -1,12 +1,15 @@ project(halsim_gui) include(CompileWarnings) +include(LinkMacOSGUI) file(GLOB halsim_gui_src src/main/native/cpp/*.cpp) add_library(halsim_gui MODULE ${halsim_gui_src}) wpilib_target_warnings(halsim_gui) set_target_properties(halsim_gui PROPERTIES DEBUG_POSTFIX "d") + +wpilib_link_macos_gui(halsim_gui) target_link_libraries(halsim_gui PUBLIC hal ntcore wpimath PRIVATE wpigui) target_include_directories(halsim_gui PRIVATE src/main/native/include) diff --git a/wpigui/CMakeLists.txt b/wpigui/CMakeLists.txt index 9b58161c49..7816338a1e 100644 --- a/wpigui/CMakeLists.txt +++ b/wpigui/CMakeLists.txt @@ -1,6 +1,7 @@ project(wpigui) include(CompileWarnings) +include(LinkMacOSGUI) file(GLOB wpigui_src src/main/native/cpp/*.cpp) file(GLOB wpigui_windows_src src/main/native/directx11/*.cpp) @@ -33,6 +34,7 @@ else() endif() add_executable(wpiguidev src/dev/native/cpp/main.cpp) +wpilib_link_macos_gui(wpiguidev) target_link_libraries(wpiguidev wpigui) install(TARGETS wpigui EXPORT wpigui DESTINATION "${main_lib_dest}")