Skip to content

Commit

Permalink
luajit.cmake: Attempt to port LUAJIT_UNWIND_EXTERNAL logic from luaji…
Browse files Browse the repository at this point in the history
…t's src/Makefile
  • Loading branch information
squeek502 authored and zhaozg committed Oct 30, 2021
1 parent 78c7be3 commit 83fc230
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion deps/luajit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 83fc230

Please sign in to comment.