From 71a61d9cbfe4a82b08a7e2ae5adeb6b5353939e6 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Mon, 4 Nov 2024 20:26:49 +0100 Subject: [PATCH] Using try_run to get __MAC_OS_X_VERSION_MAX_ALLOWED (#1105) --- CMake/macOSMaxAllowed.c | 8 ++++++++ CMake/setup.cmake | 17 +++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 CMake/macOSMaxAllowed.c diff --git a/CMake/macOSMaxAllowed.c b/CMake/macOSMaxAllowed.c new file mode 100644 index 000000000..625bcb6af --- /dev/null +++ b/CMake/macOSMaxAllowed.c @@ -0,0 +1,8 @@ +#include +#include + +int main(int argc, char **argv) { + unsigned int ver = __MAC_OS_X_VERSION_MAX_ALLOWED; + printf("%d.%d.%d", ver/10000, (ver/100)%100, ver%100); + return 0; +} diff --git a/CMake/setup.cmake b/CMake/setup.cmake index dee004ccf..8c06f2782 100644 --- a/CMake/setup.cmake +++ b/CMake/setup.cmake @@ -117,6 +117,19 @@ if(APPLE) set(HAVE_VSNPRINTF 1) set(HAVE_SCANDIR 1) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated") + # Retrieve the value of the macOS compile-time macro + # __MAC_OS_X_VERSION_MAX_ALLOWED. This is needed to decide which + # frameworks must be linked later. + try_run( + RUN_RESULT COMPILE_RESULT + SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/CMake/macOSMaxAllowed.c + RUN_OUTPUT_VARIABLE MAC_OS_X_VERSION_MAX_ALLOWED + ) + if (NOT COMPILE_RESULT) + set(MAC_OS_X_VERSION_MAX_ALLOWED ${CURRENT_OSX_VERSION}) + endif() + fl_debug_var(CMAKE_OSX_DEPLOYMENT_TARGET) + fl_debug_var(MAC_OS_X_VERSION_MAX_ALLOWED) if(FLTK_BACKEND_X11) if(NOT(${CMAKE_SYSTEM_VERSION} VERSION_LESS 17.0.0)) # a.k.a. macOS version ≥ 10.13 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_LIBCPP_HAS_THREAD_API_PTHREAD") @@ -124,10 +137,10 @@ if(APPLE) else() set(FLTK_COCOA_FRAMEWORKS "-framework Cocoa") if (NOT (CMAKE_OSX_ARCHITECTURES STREQUAL "ppc" OR CMAKE_OSX_ARCHITECTURES STREQUAL "i386")) - if(${CMAKE_SYSTEM_VERSION} VERSION_GREATER_EQUAL 20.0) # a.k.a. macOS version ≥ 11.0 + if(${MAC_OS_X_VERSION_MAX_ALLOWED} VERSION_GREATER_EQUAL 11.0) list(APPEND FLTK_COCOA_FRAMEWORKS "-weak_framework UniformTypeIdentifiers") endif() - if(${CMAKE_SYSTEM_VERSION} VERSION_GREATER_EQUAL 24.0) # a.k.a. macOS version ≥ 15.0 + if(${MAC_OS_X_VERSION_MAX_ALLOWED} VERSION_GREATER_EQUAL 15.0) list(APPEND FLTK_COCOA_FRAMEWORKS "-weak_framework ScreenCaptureKit") endif() endif()