luajit.cmake: Attempt to port LUAJIT_UNWIND_EXTERNAL logic from luajit's src/Makefile
@@ -73,7 +73,6 @@ ENDIF()
if ( WIN32 AND NOT CYGWIN )
set ( LJVM_MODE peobj )
elseif ( APPLE )
- set ( CMAKE_EXE_LINKER_FLAGS "-pagezero_size 10000 -image_base 100000000 ${CMAKE_EXE_LINKER_FLAGS}" )
set ( LJVM_MODE machasm )
else ()
set ( LJVM_MODE elfasm )
@@ -213,6 +212,39 @@ IF(TARGET_LJARCH STREQUAL "ppc")
ENDIF()
ENDIF()
+IF(APPLE)
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLUAJIT_UNWIND_EXTERNAL")
+ELSEIF(NOT WIN32)
+ IF(NOT LJ_NO_UNWIND_1)
+ # Find out whether the target toolchain always generates unwind tables.
+ MESSAGE(STATUS "Checking if the toolchain always generates unwind tables")
+ SET(TOOLCHAIN_GENERATES_UNWIND_TABLES 0)
+ SET(TMPUNWIND_DIR "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp")
+ file(WRITE "${TMPUNWIND_DIR}/tmpunwind.c" "extern void b(void);int a(void){b();return 0;}")
+ # This seems flimsy; it would be better to use something like CMake's try_compile but
+ # there doesn't seem to be a way to avoid linking when using try_compile so this particular
+ # code can't use it (at least without modifying the test code)
+ execute_process(COMMAND "${CMAKE_C_COMPILER}" -c -x c "${TMPUNWIND_DIR}/tmpunwind.c" -o "${TMPUNWIND_DIR}/tmpunwind.o"
+ RESULT_VARIABLE UNWIND_TEST_ERRORED)
+ IF(NOT UNWIND_TEST_ERRORED)
+ file(READ "${TMPUNWIND_DIR}/tmpunwind.o" TMPUNWIND_O)
+ string(FIND "${TMPUNWIND_O}" "eh_frame" EH_FRAME_FOUND)
+ string(FIND "${TMPUNWIND_O}" "__unwind_info" UNWIND_INFO_FOUND)
+ IF(EH_FRAME_FOUND OR UNWIND_INFO_FOUND)
+ SET(TOOLCHAIN_GENERATES_UNWIND_TABLES 1)
+ ENDIF()
+ ENDIF()
+
+ IF(TOOLCHAIN_GENERATES_UNWIND_TABLES)
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLUAJIT_UNWIND_EXTERNAL")
+ MESSAGE(STATUS "Toolchain does generate unwind tables")
+ ELSE()
+ MESSAGE(STATUS "Toolchain does not generate unwind tables")
+ ENDIF()
+ ENDIF()
+ENDIF()
+
+
add_executable(minilua ${LUAJIT_DIR}/src/host/minilua.c)
SET_TARGET_PROPERTIES(minilua PROPERTIES COMPILE_DEFINITIONS "${TARGET_ARCH}")
CHECK_LIBRARY_EXISTS(m sin "" MINILUA_USE_LIBM)
