Using try_run to get __MAC_OS_X_VERSION_MAX_ALLOWED (#1105)

This commit is contained in:
Matthias Melcher 2024-11-04 20:26:49 +01:00 committed by GitHub
parent afe87de013
commit 71a61d9cbf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 2 deletions

8
CMake/macOSMaxAllowed.c Normal file
View File

@ -0,0 +1,8 @@
#include <Availability.h>
#include <stdio.h>
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;
}

View File

@ -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()