Skip to content

Commit 6967d28

Browse files
committed
MacOS: Perform CMake check if allowedContentTypes will be used
1 parent f397884 commit 6967d28

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

src/CMakeLists.txt

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,25 @@ if(nfd_PLATFORM STREQUAL PLATFORM_MACOS)
3434
option(NFD_USE_ALLOWEDCONTENTTYPES_IF_AVAILABLE "Use allowedContentTypes for filter lists on macOS >= 11.0" ON)
3535

3636
find_library(APPKIT_LIBRARY AppKit)
37-
find_library(UNIFORMTYPEIDENTIFIERS_LIBRARY UniformTypeIdentifiers)
37+
if(NFD_USE_ALLOWEDCONTENTTYPES_IF_AVAILABLE)
38+
include(CheckCXXSourceCompiles)
39+
check_cxx_source_compiles(
40+
"
41+
#include <Availability.h>
42+
#if !defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || !defined(__MAC_11_0) || __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_11_0
43+
static_assert(false);
44+
#endif
45+
int main() { return 0; }
46+
"
47+
NFD_USE_ALLOWEDCONTENTTYPES
48+
)
49+
if(NFD_USE_ALLOWEDCONTENTTYPES)
50+
find_library(UNIFORMTYPEIDENTIFIERS_LIBRARY UniformTypeIdentifiers)
51+
if(NOT UNIFORMTYPEIDENTIFIERS_LIBRARY)
52+
message(FATAL_ERROR "UniformTypeIdentifiers framework is not available even though we are targeting macOS >= 11.0")
53+
endif()
54+
endif()
55+
endif()
3856
list(APPEND SOURCE_FILES nfd_cocoa.m)
3957
endif()
4058

@@ -68,12 +86,13 @@ if(nfd_PLATFORM STREQUAL PLATFORM_LINUX)
6886
endif()
6987

7088
if(nfd_PLATFORM STREQUAL PLATFORM_MACOS)
71-
if(NFD_USE_ALLOWEDCONTENTTYPES_IF_AVAILABLE AND UNIFORMTYPEIDENTIFIERS_LIBRARY)
72-
target_link_libraries(${TARGET_NAME} PRIVATE ${APPKIT_LIBRARY} ${UNIFORMTYPEIDENTIFIERS_LIBRARY})
73-
else()
74-
target_link_libraries(${TARGET_NAME} PRIVATE ${APPKIT_LIBRARY})
75-
target_compile_definitions(${TARGET_NAME} PRIVATE NFD_MACOS_ALLOWEDCONTENTTYPES=0)
76-
endif()
89+
if(NFD_USE_ALLOWEDCONTENTTYPES)
90+
target_link_libraries(${TARGET_NAME} PRIVATE ${APPKIT_LIBRARY} ${UNIFORMTYPEIDENTIFIERS_LIBRARY})
91+
target_compile_definitions(${TARGET_NAME} PRIVATE NFD_MACOS_ALLOWEDCONTENTTYPES=1)
92+
else()
93+
target_link_libraries(${TARGET_NAME} PRIVATE ${APPKIT_LIBRARY})
94+
target_compile_definitions(${TARGET_NAME} PRIVATE NFD_MACOS_ALLOWEDCONTENTTYPES=0)
95+
endif()
7796
endif()
7897

7998
if(nfd_COMPILER STREQUAL COMPILER_MSVC)

0 commit comments

Comments
 (0)