From f0fc03508791d1c70862f2f60512de3feac18c27 Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Sun, 26 Jan 2025 15:51:17 -0400 Subject: [PATCH] Defensive checks for vmnet.framework Require targeting macOS 10.10, in case the user builds with an older SDK or sets the target version to an older release. This shouldn't be a problem with modern macOS SDKs, but users using or targeting older macOS should have a better message available rather than a compile message. The check is ugly, but it should work. A similar check is done for block support; this should only be a problem with users using GCC instead of clang, which is default on macOS. Also add a message for vmnet support when printing the build config. --- cmake/dep-link.cmake | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/cmake/dep-link.cmake b/cmake/dep-link.cmake index 512744cb..0dec7bcf 100644 --- a/cmake/dep-link.cmake +++ b/cmake/dep-link.cmake @@ -352,8 +352,33 @@ if (WITH_NETWORK) endif (WITH_SLIRP) if (WITH_VMNET AND APPLE) + # CMAKE_OSX_DEPLOYMENT_TARGET is attractive, but not set by default. + # See what we're using, either by default or what the user has set. + check_c_source_compiles( + " + #include + #if TARGET_OS_OSX && __MAC_OS_X_VERSION_MIN_REQUIRED < 101000 + #error macOS too old + #endif + int main(int argc, char **argv) { return 0; } + " TARGETING_MACOS_10_10) + if (NOT TARGETING_MACOS_10_10) + message(FATAL_ERROR "vmnet.framework requires targeting macOS 10.10 or newer") + endif() + + # vmnet requires blocks for its callback parameter, even in vanilla C. + # This is only supported in clang, not by GCC. It's default in clang, + # but we should be clear about it. Do a feature instead of compiler + # check anyways though, in case GCC does add it eventually. + check_c_compiler_flag(-fblocks HAVE_C_BLOCKS) + if (NOT HAVE_C_BLOCKS) + message(FATAL_ERROR "vmnet.framework requires blocks support in the C compiler") + endif() + target_compile_options(simh_network INTERFACE -fblocks) + target_link_libraries(simh_network INTERFACE "-framework vmnet") target_compile_definitions(simh_network INTERFACE HAVE_VMNET_NETWORK) + list(APPEND NETWORK_PKG_STATUS "macOS vmnet.framework") endif(WITH_VMNET AND APPLE) ## Finally, set the network runtime