From d5c0e215a46a25de58e6264280c74d428404075f Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Tue, 5 Nov 2024 16:09:39 +0100 Subject: MacOS: Improve detection of SDK version (#1103) CMake/macOSMaxAllowed.c: avoid C compiler warning in test code CMake/setup.cmake, technical changes: - optimization: test SDK 15.0.0 first to avoid unnecessary test if true - use a function instead of a macro - use different names for (cached) result variables - use prefix FLTK_ for cache variables Note: the cache variables are marked 'internal': you may need to grep CMakeCache.txt to view them. --- CMake/macOSMaxAllowed.c | 2 +- CMake/setup.cmake | 36 +++++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 14 deletions(-) (limited to 'CMake') diff --git a/CMake/macOSMaxAllowed.c b/CMake/macOSMaxAllowed.c index 93fff3c3d..665d24389 100644 --- a/CMake/macOSMaxAllowed.c +++ b/CMake/macOSMaxAllowed.c @@ -3,4 +3,4 @@ #if __MAC_OS_X_VERSION_MAX_ALLOWED < SDK_VERSION_CHECK #error __MAC_OS_X_VERSION_MAX_ALLOWED < SDK_VERSION_CHECK #endif -int main(int, char**) { return 0; } +int main(int argc, char** argv) { return 0; } diff --git a/CMake/setup.cmake b/CMake/setup.cmake index fa9534c0a..493152c01 100644 --- a/CMake/setup.cmake +++ b/CMake/setup.cmake @@ -113,14 +113,22 @@ endif() if(APPLE) # Check if the __MAC_OS_X_VERSION_MAX_ALLOWED compile time macro is at least # the version encoded in SDK_VERSION and return TRUE or FALSE in RESULT. - macro(CHECK_OSX_MAX_ALLOWED SDK_VERSION RESULT) - try_compile(LOCAL_RESULT - ${CMAKE_BINARY_DIR}/CMakeTmpDup + # Note 1: try_compile() always creates an *internal* CMake cache variable for + # the result which we set to 'FLTK_CHECK_OSX_MAX_ALLOWED_${SDK_VERSION}'. + # Note 2: 'FLTK_' to avoid polluting the cache if FLTK is built as a subproject. + # Note 3: We don't care about the cache, i.e. we run try_compile() unconditionally + # so users can switch SDK's, particularly if they *upgrade* Xcode. + + function(CHECK_OSX_MAX_ALLOWED SDK_VERSION RESULT) + set(_result FLTK_CHECK_OSX_MAX_ALLOWED_${SDK_VERSION}) + try_compile(${_result} + ${CMAKE_CURRENT_BINARY_DIR}_SDK_${SDK_VERSION} SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/CMake/macOSMaxAllowed.c COMPILE_DEFINITIONS -DSDK_VERSION_CHECK=${SDK_VERSION} ) - set(${RESULT} ${LOCAL_RESULT}) - endmacro() + set(${RESULT} ${${_result}} PARENT_SCOPE) + endfunction() + # APPLE macOS setup set(HAVE_STRCASECMP 1) set(HAVE_DIRENT_H 1) @@ -135,14 +143,16 @@ if(APPLE) else() set(FLTK_COCOA_FRAMEWORKS "-framework Cocoa") if (NOT (CMAKE_OSX_ARCHITECTURES STREQUAL "ppc" OR CMAKE_OSX_ARCHITECTURES STREQUAL "i386")) - CHECK_OSX_MAX_ALLOWED(110000 SDK_AVAILABLE) # at least SDK 11.0.0 ? - if (SDK_AVAILABLE) - list(APPEND FLTK_COCOA_FRAMEWORKS "-weak_framework UniformTypeIdentifiers") - endif() - CHECK_OSX_MAX_ALLOWED(150000 SDK_AVAILABLE) # at least SDK 15.0.0 ? - if (SDK_AVAILABLE) - list(APPEND FLTK_COCOA_FRAMEWORKS "-weak_framework ScreenCaptureKit") - endif() + CHECK_OSX_MAX_ALLOWED(150000 SDK_15_AVAILABLE) # at least SDK 15.0.0 ? + if (SDK_15_AVAILABLE) + list(APPEND FLTK_COCOA_FRAMEWORKS "-weak_framework ScreenCaptureKit") # 15.0 + list(APPEND FLTK_COCOA_FRAMEWORKS "-weak_framework UniformTypeIdentifiers") # 11.0 + else(SDK_15_AVAILABLE) + CHECK_OSX_MAX_ALLOWED(110000 SDK_11_AVAILABLE) # at least SDK 11.0.0 ? + if (SDK_11_AVAILABLE) + list(APPEND FLTK_COCOA_FRAMEWORKS "-weak_framework UniformTypeIdentifiers") + endif(SDK_11_AVAILABLE) + endif(SDK_15_AVAILABLE) endif() endif(FLTK_BACKEND_X11) endif(APPLE) -- cgit v1.2.3