11cmake_minimum_required (VERSION 3.15 )
22
33# Metadata
4-
54project (NativeScript CXX OBJCXX )
65
76set (NAME NativeScript)
@@ -17,7 +16,6 @@ set(COMMON_FLAGS "-O3 -Wno-shorten-64-to-32")
1716set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS } ${COMMON_FLAGS} " )
1817
1918# Arguments
20-
2119set (TARGET_PLATFORM "macos" CACHE STRING "Target platform for the Objective-C bridge" )
2220set (TARGET_ENGINE "v8" CACHE STRING "Target JS engine for the NativeScript runtime" )
2321set (METADATA_SIZE 0 CACHE STRING "Size of embedded metadata in bytes" )
@@ -56,6 +54,10 @@ elseif(TARGET_PLATFORM STREQUAL "macos")
5654 set (TARGET_PLATFORM_SPEC "macos-arm64_x86_64" )
5755 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS } -DTARGET_PLATFORM_MACOS" )
5856
57+ # Unlike "ios", "macos" doesn't seem to produce a NativeScript.framework.dSYM
58+ # by default. We can produce it by setting these variables.
59+ set (CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT "dwarf-with-dsym" )
60+ set (CMAKE_XCODE_ATTRIBUTE_DWARF_DSYM_FOLDER_PATH "${CMAKE_CURRENT_BINARY_DIR } /$<CONFIG >" )
5961else ()
6062 message (FATAL_ERROR "Unknown target platform: ${TARGET_PLATFORM} " )
6163 return ()
@@ -87,18 +89,16 @@ endif()
8789if (ENABLE_JS_RUNTIME)
8890 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS } -DENABLE_JS_RUNTIME" )
8991 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS } -DENABLE_JS_RUNTIME" )
90- elseif (TARGET_PLATFORM_MACOS)
91- # If building a generic library for macOS, we'll build a dylib instead of a framework
92- unset (BUILD_FRAMEWORK)
92+ else ()
9393 set (GENERIC_NAPI TRUE )
9494endif ()
9595
9696message (STATUS "TARGET_PLATFORM = ${TARGET_PLATFORM} " )
9797message (STATUS "TARGET_ENGINE = ${TARGET_ENGINE} " )
9898message (STATUS "ENABLE_JS_RUNTIME = ${ENABLE_JS_RUNTIME} " )
99+ message (STATUS "GENERIC_NAPI = ${GENERIC_NAPI} " )
99100
100101# Set up sources
101-
102102include_directories (
103103 ./
104104 ../metadata-generator/include
@@ -201,12 +201,14 @@ if(ENABLE_JS_RUNTIME)
201201 )
202202
203203 set (SOURCE_FILES ${SOURCE_FILES}
204+
204205 # quickjs
205206 napi/quickjs/source/cutils.c
206207 napi/quickjs/source/libregexp.c
207208 napi/quickjs/source/libbf.c
208209 napi/quickjs/source/libunicode.c
209210 napi/quickjs/source/quickjs.c
211+
210212 # napi
211213 napi/quickjs/quickjs-api.c
212214 napi/quickjs/jsr.cpp
@@ -223,7 +225,6 @@ if(ENABLE_JS_RUNTIME)
223225 napi/jsc/jsc-api.cpp
224226 napi/jsc/jsr.cpp
225227 )
226-
227228 endif ()
228229else ()
229230 include_directories (
@@ -239,7 +240,6 @@ if(BUILD_CLI_BINARY)
239240endif ()
240241
241242# Find SDK
242-
243243find_program (XCODEBUILD_EXECUTABLE xcodebuild )
244244
245245if (METADATA_SIZE EQUAL 0)
@@ -265,7 +265,6 @@ set(CMAKE_OSX_SYSROOT "${CMAKE_OSX_SYSROOT_INT}" CACHE INTERNAL "")
265265message (STATUS "SDK = ${CMAKE_OSX_SYSROOT} " )
266266
267267# Build targets
268-
269268if (BUILD_CLI_BINARY)
270269 add_executable (${NAME} ${SOURCE_FILES} )
271270else ()
@@ -301,11 +300,22 @@ endif()
301300
302301if (TARGET_PLATFORM_MACOS)
303302 # add_custom_command(TARGET ${NAME} POST_BUILD
304- # COMMAND /usr/libexec/PlistBuddy -c "Add :LSMinimumSystemVersion string ${CMAKE_OSX_DEPLOYMENT_TARGET}" $<TARGET_FILE_DIR:${NAME}>/Resources/Info.plist
303+ # COMMAND /usr/libexec/PlistBuddy -c "Add :LSMinimumSystemVersion string ${CMAKE_OSX_DEPLOYMENT_TARGET}" $<TARGET_FILE_DIR:${NAME}>/Resources/Info.plist
305304 # )
306305
306+ # Convert the Info.plist from binary format to XML format.
307+ # This seemed to unblock a build error when using in React Native.
308+ add_custom_command (TARGET ${NAME} POST_BUILD
309+ COMMAND plutil -convert xml1 $<TARGET_FILE_DIR :${NAME} >/Resources/Info.plist
310+ )
307311 set (METADATA_FILE "metadata.macos.nsmd" )
308312elseif (TARGET_PLATFORM_IOS)
313+ # Convert the Info.plist from binary format to XML format.
314+ # This seemed to unblock a build error when using in React Native.
315+ add_custom_command (TARGET ${NAME} POST_BUILD
316+ COMMAND plutil -convert xml1 $<TARGET_FILE_DIR :${NAME} >/Info.plist
317+ )
318+
309319 if (TARGET_PLATFORM_SIM)
310320 set (METADATA_FILE "metadata.ios-sim.nsmd" )
311321 else ()
@@ -362,7 +372,7 @@ if(TARGET_ENGINE_JSC)
362372endif ()
363373
364374if (TARGET_ENGINE_V8)
365- if (TARGET_PLATFORM_MACOS)
375+ if (TARGET_PLATFORM_MACOS)
366376 target_link_directories (
367377 ${NAME}
368378 PRIVATE
@@ -414,12 +424,12 @@ if(TARGET_ENGINE_QUICKJS)
414424 )
415425endif ()
416426
417- # if (GENERIC_NAPI)
418- target_link_options (
419- ${NAME}
420- PRIVATE
421- "-Wl"
422- "-undefined"
423- "dynamic_lookup"
424- )
425- # endif()
427+ if (GENERIC_NAPI)
428+ target_link_options (
429+ ${NAME}
430+ PRIVATE
431+ "-Wl"
432+ "-undefined"
433+ "dynamic_lookup"
434+ )
435+ endif ()
0 commit comments