@@ -167,12 +167,19 @@ endif()
167167
168168######## END ALIASES
169169
170+ # Unset the FORCE on cache variables if in try_compile()
171+ set (FORCE_CACHE FORCE)
172+ get_property (_CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE )
173+ if (_CMAKE_IN_TRY_COMPILE)
174+ unset (FORCE_CACHE)
175+ endif ()
176+
170177# Default to building for iPhoneOS if not specified otherwise, and we cannot
171178# determine the platform from the CMAKE_OSX_ARCHITECTURES variable. The use
172179# of CMAKE_OSX_ARCHITECTURES is such that try_compile() projects can correctly
173180# determine the value of PLATFORM from the root project, as
174181# CMAKE_OSX_ARCHITECTURES is propagated to them by CMake.
175- if (NOT DEFINED PLATFORM)
182+ if (NOT DEFINED PLATFORM)
176183 if (CMAKE_OSX_ARCHITECTURES)
177184 if (CMAKE_OSX_ARCHITECTURES MATCHES ".*arm.*" AND CMAKE_OSX_SYSROOT MATCHES ".*iphoneos.*" )
178185 set (PLATFORM "OS" )
@@ -314,7 +321,7 @@ if (NOT DEFINED CMAKE_OSX_SYSROOT_INT AND NOT DEFINED CMAKE_OSX_SYSROOT)
314321 message (FATAL_ERROR "Invalid CMAKE_OSX_SYSROOT: ${CMAKE_OSX_SYSROOT} "
315322 "does not exist." )
316323elseif (DEFINED CMAKE_OSX_SYSROOT)
317- message (STATUS "Using manually set SDK: ${CMAKE_OSX_SYSROOT} for platform: ${PLATFORM_INT} " )
324+ message (STATUS "Using SDK: ${CMAKE_OSX_SYSROOT} for platform: ${PLATFORM_INT} when checking compatibility " )
318325elseif (DEFINED CMAKE_OSX_SYSROOT_INT)
319326 message (STATUS "Using SDK: ${CMAKE_OSX_SYSROOT_INT} for platform: ${PLATFORM_INT} " )
320327 set (CMAKE_OSX_SYSROOT "${CMAKE_OSX_SYSROOT_INT} " CACHE INTERNAL "" )
@@ -350,21 +357,21 @@ elseif(NOT DEFINED ENABLE_BITCODE)
350357 message (STATUS "Disabling bitcode support by default on simulators. ENABLE_BITCODE not provided for override!" )
351358 set (ENABLE_BITCODE FALSE )
352359endif ()
353- set (ENABLE_BITCODE_INT ${ENABLE_BITCODE} CACHE BOOL "Whether or not to enable bitcode" FORCE )
360+ set (ENABLE_BITCODE_INT ${ENABLE_BITCODE} CACHE BOOL "Whether or not to enable bitcode" ${FORCE_CACHE} )
354361# Use ARC or not
355362if (NOT DEFINED ENABLE_ARC)
356363 # Unless specified, enable ARC support by default
357364 set (ENABLE_ARC TRUE )
358365 message (STATUS "Enabling ARC support by default. ENABLE_ARC not provided!" )
359366endif ()
360- set (ENABLE_ARC_INT ${ENABLE_ARC} CACHE BOOL "Whether or not to enable ARC" FORCE )
367+ set (ENABLE_ARC_INT ${ENABLE_ARC} CACHE BOOL "Whether or not to enable ARC" ${FORCE_CACHE} )
361368# Use hidden visibility or not
362369if (NOT DEFINED ENABLE_VISIBILITY)
363370 # Unless specified, disable symbols visibility by default
364371 set (ENABLE_VISIBILITY FALSE )
365372 message (STATUS "Hiding symbols visibility by default. ENABLE_VISIBILITY not provided!" )
366373endif ()
367- set (ENABLE_VISIBILITY_INT ${ENABLE_VISIBILITY} CACHE BOOL "Whether or not to hide symbols (-fvisibility=hidden)" FORCE )
374+ set (ENABLE_VISIBILITY_INT ${ENABLE_VISIBILITY} CACHE BOOL "Whether or not to hide symbols (-fvisibility=hidden)" ${FORCE_CACHE} )
368375# Get the SDK version information.
369376execute_process (COMMAND xcodebuild -sdk ${CMAKE_OSX_SYSROOT} -version SDKVersion
370377 OUTPUT_VARIABLE SDK_VERSION
@@ -376,8 +383,8 @@ execute_process(COMMAND xcodebuild -sdk ${CMAKE_OSX_SYSROOT} -version SDKVersion
376383# CMAKE_OSX_SYSROOT. There does not appear to be a direct way to obtain
377384# this information from xcrun or xcodebuild.
378385if (NOT DEFINED CMAKE_DEVELOPER_ROOT AND NOT USED_CMAKE_GENERATOR MATCHES "Xcode" )
379- get_filename_component (IOS_PLATFORM_SDK_DIR ${CMAKE_OSX_SYSROOT} PATH )
380- get_filename_component (CMAKE_DEVELOPER_ROOT ${IOS_PLATFORM_SDK_DIR } PATH )
386+ get_filename_component (PLATFORM_SDK_DIR ${CMAKE_OSX_SYSROOT} PATH )
387+ get_filename_component (CMAKE_DEVELOPER_ROOT ${PLATFORM_SDK_DIR } PATH )
381388
382389 if (NOT DEFINED CMAKE_DEVELOPER_ROOT)
383390 message (FATAL_ERROR "Invalid CMAKE_DEVELOPER_ROOT: "
@@ -420,11 +427,11 @@ execute_process(COMMAND uname -r
420427# CMake 3.14+ support building for iOS, watchOS and tvOS out of the box.
421428if (MODERN_CMAKE)
422429 if (SDK_NAME MATCHES "iphone" )
423- set (CMAKE_SYSTEM_NAME iOS CACHE INTERNAL "" FORCE )
430+ set (CMAKE_SYSTEM_NAME iOS CACHE INTERNAL "" ${FORCE_CACHE} )
424431 elseif (SDK_NAME MATCHES "appletv" )
425- set (CMAKE_SYSTEM_NAME tvOS CACHE INTERNAL "" FORCE )
432+ set (CMAKE_SYSTEM_NAME tvOS CACHE INTERNAL "" ${FORCE_CACHE} )
426433 elseif (SDK_NAME MATCHES "watch" )
427- set (CMAKE_SYSTEM_NAME watchOS CACHE INTERNAL "" FORCE )
434+ set (CMAKE_SYSTEM_NAME watchOS CACHE INTERNAL "" ${FORCE_CACHE} )
428435 endif ()
429436
430437 # Provide flags for a combined FAT library build on newer CMake versions
@@ -435,7 +442,7 @@ if(MODERN_CMAKE)
435442 endif ()
436443else ()
437444 # Legacy code path prior to CMake 3.14
438- set (CMAKE_SYSTEM_NAME Darwin CACHE INTERNAL "" FORCE )
445+ set (CMAKE_SYSTEM_NAME Darwin CACHE INTERNAL "" ${FORCE_CACHE} )
439446endif ()
440447# Standard settings.
441448set (CMAKE_SYSTEM_VERSION ${SDK_VERSION} CACHE INTERNAL "" )
@@ -507,16 +514,14 @@ else()
507514endif ()
508515message (STATUS "Version flags set to: ${SDK_NAME_VERSION_FLAGS} " )
509516set (CMAKE_OSX_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET} CACHE STRING
510- "Set CMake deployment target" FORCE )
517+ "Set CMake deployment target" ${FORCE_CACHE} )
511518
512519if (ENABLE_BITCODE_INT)
513520 set (BITCODE "-fembed-bitcode" )
514- set (HEADER_PAD "" )
515521 set (CMAKE_XCODE_ATTRIBUTE_BITCODE_GENERATION_MODE bitcode CACHE INTERNAL "" )
516522 message (STATUS "Enabling bitcode support." )
517523else ()
518524 set (BITCODE "" )
519- set (HEADER_PAD "-headerpad_max_install_names" )
520525 set (CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE NO CACHE INTERNAL "" )
521526 message (STATUS "Disabling bitcode support." )
522527endif ()
@@ -575,11 +580,12 @@ endif()
575580
576581set (CMAKE_PLATFORM_HAS_INSTALLNAME 1)
577582set (CMAKE_SHARED_LINKER_FLAGS "-rpath @executable_path/Frameworks -rpath @loader_path/Frameworks" )
578- set (CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib ${HEADER_PAD} " )
579- set (CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle ${HEADER_PAD} " )
583+ set (CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -Wl,-headerpad_max_install_names " )
584+ set (CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -Wl,-headerpad_max_install_names " )
580585set (CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader," )
581586set (CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader," )
582- set (CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a" )
587+ set (CMAKE_FIND_LIBRARY_SUFFIXES ".tbd" ".dylib" ".so" ".a" )
588+ set (CMAKE_SHARED_LIBRARY_SONAME_C_FLAG "-install_name" )
583589
584590# Hack: if a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old
585591# build tree (where install_name_tool was hardcoded) and where
@@ -589,27 +595,29 @@ set(CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a")
589595# before, Alex.
590596if (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
591597 find_program (CMAKE_INSTALL_NAME_TOOL install_name_tool)
592- endif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
598+ endif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
593599
594600# Set the find root to the iOS developer roots and to user defined paths.
595- set (CMAKE_FIND_ROOT_PATH ${CMAKE_DEVELOPER_ROOT} ${CMAKE_OSX_SYSROOT }
596- ${CMAKE_PREFIX_PATH} CACHE STRING "SKD find search path root" FORCE )
601+ set (CMAKE_FIND_ROOT_PATH ${CMAKE_DEVELOPER_ROOT} ${CMAKE_OSX_SYSROOT_INT }
602+ ${CMAKE_PREFIX_PATH} CACHE STRING "Root path that will be prepended to all search paths" )
597603# Default to searching for frameworks first.
598604set (CMAKE_FIND_FRAMEWORK FIRST)
599605# Set up the default search directories for frameworks.
600- set (CMAKE_SYSTEM_FRAMEWORK_PATH
601- ${CMAKE_OSX_SYSROOT} /System /Library/Frameworks
602- ${CMAKE_OSX_SYSROOT} /System /Library/PrivateFrameworks
603- ${CMAKE_OSX_SYSROOT} /Developer/Library/Frameworks)
606+ set (CMAKE_FRAMEWORK_PATH
607+ ${CMAKE_DEVELOPER_ROOT} /Library/Frameworks
608+ ${CMAKE_DEVELOPER_ROOT} /Library/PrivateFrameworks
609+ ${CMAKE_OSX_SYSROOT_INT} /System /Library/Frameworks
610+ ${CMAKE_FRAMEWORK_PATH} CACHE STRING "Frameworks search paths" )
611+
604612# Only search the specified iOS SDK, not the remainder of the host filesystem.
605- if ( NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM )
606- set ( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
613+ if (NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM)
614+ set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH CACHE STRING "" ${FORCE_CACHE} )
607615endif ()
608- if ( NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY )
609- set ( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
616+ if (NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY)
617+ set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH CACHE STRING "" ${FORCE_CACHE} )
610618endif ()
611- if ( NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE )
612- set ( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
619+ if (NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE)
620+ set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH CACHE STRING "" ${FORCE_CACHE} )
613621endif ()
614622
615623#
0 commit comments