build: luajit: macos: implement more stable MACOSX_DEPLOYMENT_TARGET
detecting mechanism
1. Refer the MACOSX_DEPLOYMENT_TARGET environment variable first.
2. If it is not available, MACOSX_DEPLOYMENT_TARGET should be
caluculated from sw_vers command results.
This patch should be followed up
@@ -13,11 +13,19 @@ set(LUAJIT_DEST ${CMAKE_CURRENT_BINARY_DIR})
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(CFLAGS "${CFLAGS} -isysroot ${CMAKE_OSX_SYSROOT} -fno-stack-check")
- if (CMAKE_HOST_SYSTEM_VERSION VERSION_GREATER_EQUAL 20
- AND CMAKE_HOST_SYSTEM_VERSION VERSION_LESS 22)
- set(DEPLOYMENT_TARGET "MACOSX_DEPLOYMENT_TARGET=11.0")
+
+ if(DEFINED ENV{MACOSX_DEPLOYMENT_TARGET})
+ # Refer MACOSX_DEPLOYMENT_TARGET if available.
+ set(DEPLOYMENT_TARGET "MACOSX_DEPLOYMENT_TARGET=$ENV{MACOSX_DEPLOYMENT_TARGET}")
else()
- set(DEPLOYMENT_TARGET "MACOSX_DEPLOYMENT_TARGET=10.15")
+ # Calculate MACOSX_DEPLOYMENT_TARGET from sw_vers command result.
+ execute_process(COMMAND sw_vers -productVersion OUTPUT_VARIABLE MACOSX_DEPLOYMENT_TARGET)
+ string(REGEX REPLACE "\n$" "" MACOSX_DEPLOYMENT_TARGET ${MACOSX_DEPLOYMENT_TARGET})
+ string(REPLACE "." ";" DEPLOYMENT_VERSION_LIST ${MACOSX_DEPLOYMENT_TARGET})
+ list(GET DEPLOYMENT_VERSION_LIST 0 MACOSX_DEPLOYMENT_TARGET_MAJOR)
+ list(GET DEPLOYMENT_VERSION_LIST 1 MACOSX_DEPLOYMENT_TARGET_MINOR)
+ list(GET DEPLOYMENT_VERSION_LIST 2 MACOSX_DEPLOYMENT_TARGET_PATCH)
+ set(DEPLOYMENT_TARGET "MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET_MAJOR}.${MACOSX_DEPLOYMENT_TARGET_MINOR}")
endif()
else()
set(DEPLOYMENT_TARGET "")
