CMakeLists.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. # Copyright (C) 2007-2013 LuaDist.
  2. # Created by Peter Drahoš
  3. # Redistribution and use of this file is allowed according to the terms of the MIT license.
  4. # For details see the COPYRIGHT file distributed with LuaDist.
  5. # Please note that the package source code is licensed under its own license.
  6. # NOTE: This build is currently only supporting x86 targets, for other targets use the original makefile. Please do not submit bugs to the LuaJIT author in case this build fails, instead use http://github.com/LuaDist/luajit
  7. #if (APPLE)
  8. #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
  9. #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
  10. #endif()
  11. project ( luajit C ASM)
  12. set( CMAKE_VERBOSE_MAKEFILE on )
  13. cmake_minimum_required ( VERSION 3.5 )
  14. include ( cmake/dist.cmake )
  15. include ( lua )
  16. ## CONFIGURATION
  17. # Default configuration (we assume POSIX by default)
  18. set ( LUA_PATH "LUA_PATH" CACHE STRING "Environment variable to use as package.path." )
  19. set ( LUA_CPATH "LUA_CPATH" CACHE STRING "Environment variable to use as package.cpath." )
  20. set ( LUA_INIT "LUA_INIT" CACHE STRING "Environment variable for initial script." )
  21. option ( LUA_ANSI "Use only ansi features." OFF )
  22. option ( LUA_USE_RELATIVE_LOADLIB "Use modified loadlib.c with support for relative paths on posix systems." ON)
  23. set ( LUA_IDSIZE "60" CACHE STRING "gives the maximum size for the description of the source." )
  24. set ( LUA_PROMPT "> " CACHE STRING "Is the default prompt used by stand-alone Lua." )
  25. set ( LUA_PROMPT2 ">> " CACHE STRING "Is the default continuation prompt used by stand-alone Lua." )
  26. set ( LUA_MAXINPUT "512" CACHE STRING "Is the maximum length for an input line in the stand-alone interpreter.")
  27. # Version
  28. set ( MAJVER 2 )
  29. set ( MINVER 0 )
  30. set ( RELVER 2 )
  31. set ( ABIVER 5.1 )
  32. set ( NODOTABIVER 51 )
  33. # Extra flags
  34. option ( LUAJIT_DISABLE_FFI "Permanently disable the FFI extension to reduce the size of the LuaJIT executable. But please consider that the FFI library is compiled-in, but NOT loaded by default. It only allocates any memory, if you actually make use of it." OFF )
  35. option ( LUAJIT_ENABLE_LUA52COMPAT "Features from Lua 5.2 that are unlikely to break existing code are enabled by default. Some other features that *might* break some existing code (e.g. __pairs or os.execute() return values) can be enabled here. Note: this does not provide full compatibility with Lua 5.2 at this time." ON )
  36. option ( LUAJIT_DISABLE_JIT "Disable the JIT compiler, i.e. turn LuaJIT into a pure interpreter." OFF )
  37. option ( LUAJIT_USE_SYSMALLOC "Use the system provided memory allocator (realloc) instead of the bundled memory allocator. This is slower, but sometimes helpful for debugging. It's helpful for Valgrind's memcheck tool, too. This option cannot be enabled on x64, since the built-in allocator is mandatory." OFF )
  38. option ( LUAJIT_USE_VALGRIND "This option is required to run LuaJIT under Valgrind. The Valgrind header files must be installed. You should enable debug information, too." OFF )
  39. option ( LUAJIT_USE_GDBJIT "This is the client for the GDB JIT API. GDB 7.0 or higher is required to make use of it. See lj_gdbjit.c for details. Enabling this causes a non-negligible overhead, even when not running under GDB." OFF )
  40. option ( LUA_USE_APICHECK "Turn on assertions for the Lua/C API to debug problems with lua_* calls. This is rather slow, use only while developing C libraries/embeddings." OFF )
  41. option ( LUA_USE_ASSERT "Turn on assertions for the whole LuaJIT VM. This significantly slows down everything. Use only if you suspect a problem with LuaJIT itself." OFF )
  42. option ( LUAJIT_CPU_SSE2 "Disable SSE2." OFF )
  43. option ( LUAJIT_CPU_NOCMOV "Disable NOCMOV." OFF )
  44. # Tunable variables
  45. set ( LUAI_MAXSTACK "65500" CACHE STRING "Max. # of stack slots for a thread (<64K)." )
  46. set ( LUAI_MAXCSTACK "8000" CACHE STRING "Max. # of stack slots for a C func (<10K)." )
  47. set ( LUAI_GCPAUSE "200" CACHE STRING "Pause GC until memory is at 200%." )
  48. set ( LUAI_GCMUL "200" CACHE STRING "Run GC at 200% of allocation speed." )
  49. set ( LUA_MAXCAPTURES "32" CACHE STRING "Max. pattern captures." )
  50. ## SETUP
  51. set ( LUA_DIRSEP "/" )
  52. set ( LUA_MODULE_SUFFIX ${CMAKE_SHARED_MODULE_SUFFIX} )
  53. set ( LUA_LDIR ${INSTALL_LMOD} )
  54. set ( LUA_CDIR ${INSTALL_CMOD} )
  55. if ( LUA_USE_RELATIVE_LOADLIB )
  56. # This will set up relative paths to lib
  57. string ( REGEX REPLACE "[^!/]+" ".." LUA_DIR "!/${INSTALL_BIN}/" )
  58. else ()
  59. # Direct path to installation
  60. set ( LUA_DIR ${CMAKE_INSTALL_PREFIX} CACHE STRING "Destination from which modules will be resolved. See INSTALL_LMOD and INSTALL_CMOD.")
  61. endif ()
  62. set ( LUA_PATH_DEFAULT "./?.lua;${LUA_DIR}${LUA_LDIR}/?.lua;${LUA_DIR}${LUA_LDIR}/?/init.lua;./?/init.lua" )
  63. set ( LUA_CPATH_DEFAULT "./?${LUA_MODULE_SUFFIX};${LUA_DIR}${LUA_CDIR}/?${LUA_MODULE_SUFFIX};${LUA_DIR}${LUA_CDIR}/loadall${LUA_MODULE_SUFFIX}" )
  64. if ( WIN32 AND NOT CYGWIN )
  65. # Windows systems
  66. add_definitions (-DLUAJIT_OS=LUAJIT_OS_WINDOWS)
  67. option ( LUA_BUILD_WLUA "Build wluajit interpreter for no-console applications." ON )
  68. set ( LJVM_MODE peobj )
  69. # Paths (Double escapes needed)
  70. set ( LUA_DIRSEP "\\\\" )
  71. string ( REPLACE "/" ${LUA_DIRSEP} LUA_DIR "${LUA_DIR}" )
  72. string ( REPLACE "/" ${LUA_DIRSEP} LUA_LDIR "${LUA_LDIR}" )
  73. string ( REPLACE "/" ${LUA_DIRSEP} LUA_CDIR "${LUA_CDIR}" )
  74. string ( REPLACE "/" ${LUA_DIRSEP} LUA_PATH_DEFAULT "${LUA_PATH_DEFAULT}" )
  75. string ( REPLACE "/" ${LUA_DIRSEP} LUA_CPATH_DEFAULT "${LUA_CPATH_DEFAULT}" )
  76. elseif ( APPLE )
  77. # Required to prevent runtime crash on 64bit OSX - however this breaks 32bit compile
  78. set ( CMAKE_EXE_LINKER_FLAGS "-pagezero_size 10000 -image_base 100000000 -image_base 7fff04c4a000" )
  79. option ( LUA_USE_POSIX "Use POSIX functionality." ON )
  80. option ( LUA_USE_DLOPEN "Use dynamic linker to load modules." ON )
  81. set ( LJVM_MODE machasm )
  82. else ()
  83. option ( LUA_USE_POSIX "Use POSIX functionality." ON )
  84. option ( LUA_USE_DLOPEN "Use dynamic linker to load modules." ON )
  85. set ( LJVM_MODE elfasm )
  86. endif ()
  87. ## LIBRARY DETECTION
  88. # Optional libraries
  89. find_package ( Readline QUIET)
  90. if ( READLINE_FOUND )
  91. option ( LUA_USE_READLINE "Use readline in the Lua CLI." ON )
  92. endif ()
  93. find_package ( Curses )
  94. if ( CURSES_FOUND )
  95. option ( LUA_USE_CURSES "Use curses in the Lua CLI." ON )
  96. endif ()
  97. # Setup needed variables and libraries
  98. if ( LUA_USE_POSIX )
  99. # On POSIX Lua links to standard math library "m"
  100. list ( APPEND LIBS m )
  101. endif ()
  102. if ( LUA_USE_DLOPEN )
  103. # Link to dynamic linker library "dl"
  104. list ( APPEND LIBS dl )
  105. endif ()
  106. if ( LUA_USE_READLINE )
  107. # Add readline
  108. include_directories ( ${READLINE_INCLUDE_DIR} )
  109. list ( APPEND LIBS ${READLINE_LIBRARY} )
  110. endif ()
  111. if ( LUA_USE_CURSES )
  112. # Add curses
  113. include_directories ( ${CURSES_INCLUDE_DIR} )
  114. list ( APPEND LIBS ${CURSES_LIBRARY} )
  115. endif ()
  116. ## SOURCES
  117. # Generate luaconf.h
  118. configure_file ( src/luaconf.h.in ${CMAKE_CURRENT_BINARY_DIR}/luaconf.h )
  119. set ( LJLIB_C
  120. src/lib_base.c
  121. src/lib_math.c
  122. src/lib_bit.c
  123. src/lib_string.c
  124. src/lib_table.c
  125. src/lib_io.c
  126. src/lib_os.c
  127. src/lib_debug.c
  128. src/lib_jit.c
  129. src/lib_ffi.c
  130. )
  131. if ( LUA_USE_RELATIVE_LOADLIB )
  132. list ( APPEND LJLIB_C src/lib_package_rel.c )
  133. else ()
  134. list ( APPEND LJLIB_C src/lib_package.c )
  135. endif ()
  136. ## GENERATE VM
  137. # Build minilua
  138. add_executable ( minilua src/host/minilua.c )
  139. target_link_libraries ( minilua ${LIBS} )
  140. # Dynasm
  141. set ( DASM ${CMAKE_CURRENT_SOURCE_DIR}/dynasm/dynasm.lua )
  142. set ( DASM_T ${CMAKE_CURRENT_SOURCE_DIR}/src/host/buildvm_arch.h )
  143. # 2DO: Proper detection of flags
  144. set ( DASM_VER "" )
  145. set ( DASM_FLAGS -D FPU -D HFABI )
  146. set ( DASM_ARCH x86 )
  147. # Raspberry PI, ARM
  148. if ( ${CMAKE_SYSTEM_PROCESSOR} MATCHES "armv6l" )
  149. set ( DASM_ARCH arm )
  150. list ( APPEND DASM_FLAGS -D DUALNUM )
  151. set ( DASM_VER 60 )
  152. endif ()
  153. # Windows is ... special
  154. if ( WIN32 )
  155. list ( APPEND DASM_FLAGS -D WIN )
  156. endif ()
  157. # 32bit vs 64bit
  158. #if ( CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT APPLE )
  159. if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
  160. list ( APPEND DASM_FLAGS -D P64 )
  161. endif ()
  162. if ( NOT LUAJIT_DISABLE_JIT )
  163. list ( APPEND DASM_FLAGS -D JIT )
  164. endif ()
  165. if ( NOT LUAJIT_DISABLE_FFI )
  166. list ( APPEND DASM_FLAGS -D FFI )
  167. endif ()
  168. if ( NOT LUAJIT_CPU_SSE2 )
  169. list ( APPEND DASM_FLAGS -D SSE2 )
  170. endif ()
  171. list ( APPEND DASM_FLAGS -D VER=${DASM_VER} )
  172. string ( REPLACE ";" " " DASM_FLAGS_STR "${DASM_FLAGS}")
  173. #message ( STATUS "DASM_FLAGS: ${DASM_FLAGS_STR}")
  174. #message ( STATUS "DASM_ARCH: ${DASM_ARCH}" )
  175. set ( DASM_DASC ${CMAKE_CURRENT_SOURCE_DIR}/src/vm_${DASM_ARCH}.dasc )
  176. # Generate buildvm arch header
  177. add_custom_command(OUTPUT ${DASM_T}
  178. COMMAND minilua ${DASM} ${DASM_FLAGS} -o ${DASM_T} ${DASM_DASC}
  179. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dynasm
  180. DEPENDS minilua
  181. )
  182. # Buildvm
  183. file ( GLOB SRC_BUILDVM src/host/buildvm*.c )
  184. add_executable ( buildvm ${SRC_BUILDVM} ${DASM_T} )
  185. macro(add_buildvm_target _target _mode)
  186. add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_target}
  187. COMMAND buildvm ARGS -m ${_mode} -o ${CMAKE_CURRENT_BINARY_DIR}/${_target} ${ARGN}
  188. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  189. DEPENDS buildvm ${ARGN}
  190. )
  191. endmacro(add_buildvm_target)
  192. if ( WIN32 AND NOT CYGWIN )
  193. add_buildvm_target ( lj_vm.obj peobj )
  194. set (LJ_VM_SRC ${CMAKE_CURRENT_BINARY_DIR}/lj_vm.obj)
  195. else ()
  196. add_buildvm_target ( lj_vm.s ${LJVM_MODE} )
  197. set (LJ_VM_SRC ${CMAKE_CURRENT_BINARY_DIR}/lj_vm.s)
  198. endif ()
  199. add_buildvm_target ( lj_ffdef.h ffdef ${LJLIB_C} )
  200. add_buildvm_target ( lj_bcdef.h bcdef ${LJLIB_C} )
  201. add_buildvm_target ( lj_folddef.h folddef src/lj_opt_fold.c )
  202. add_buildvm_target ( lj_recdef.h recdef ${LJLIB_C} )
  203. add_buildvm_target ( lj_libdef.h libdef ${LJLIB_C} )
  204. add_buildvm_target ( jit/vmdef.lua libvm ${LJLIB_C} )
  205. SET ( DEPS
  206. ${LJ_VM_SRC}
  207. ${CMAKE_CURRENT_BINARY_DIR}/lj_ffdef.h
  208. ${CMAKE_CURRENT_BINARY_DIR}/lj_bcdef.h
  209. ${CMAKE_CURRENT_BINARY_DIR}/lj_libdef.h
  210. ${CMAKE_CURRENT_BINARY_DIR}/lj_recdef.h
  211. ${CMAKE_CURRENT_BINARY_DIR}/lj_folddef.h
  212. )
  213. ## LuaJIT Library
  214. include_directories ( ${CMAKE_CURRENT_BINARY_DIR} dynasm src src/host )
  215. set ( LJCORE_C
  216. src/lj_gc.c
  217. src/lj_err.c
  218. src/lj_char.c
  219. src/lj_bc.c
  220. src/lj_obj.c
  221. src/lj_str.c
  222. src/lj_tab.c
  223. src/lj_func.c
  224. src/lj_udata.c
  225. src/lj_meta.c
  226. src/lj_debug.c
  227. src/lj_state.c
  228. src/lj_dispatch.c
  229. src/lj_vmevent.c
  230. src/lj_vmmath.c
  231. src/lj_strscan.c
  232. src/lj_api.c
  233. src/lj_lex.c
  234. src/lj_parse.c
  235. src/lj_bcread.c
  236. src/lj_bcwrite.c
  237. src/lj_load.c
  238. src/lj_ir.c
  239. src/lj_opt_mem.c
  240. src/lj_opt_fold.c
  241. src/lj_opt_narrow.c
  242. src/lj_opt_dce.c
  243. src/lj_opt_loop.c
  244. src/lj_opt_split.c
  245. src/lj_opt_sink.c
  246. src/lj_mcode.c
  247. src/lj_snap.c
  248. src/lj_record.c
  249. src/lj_crecord.c
  250. src/lj_ffrecord.c
  251. src/lj_asm.c
  252. src/lj_trace.c
  253. src/lj_gdbjit.c
  254. src/lj_ctype.c
  255. src/lj_cdata.c
  256. src/lj_cconv.c
  257. src/lj_ccall.c
  258. src/lj_ccallback.c
  259. src/lj_carith.c
  260. src/lj_clib.c
  261. src/lj_cparse.c
  262. src/lj_lib.c
  263. src/lj_alloc.c
  264. src/lib_aux.c
  265. src/lib_init.c
  266. ${LJLIB_C}
  267. )
  268. add_library ( liblua STATIC ${LJCORE_C} ${DEPS} )
  269. #if (APPLE)
  270. #set_target_properties(liblua PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
  271. #endif()
  272. target_link_libraries ( liblua ${LIBS} )
  273. set_target_properties ( liblua PROPERTIES OUTPUT_NAME lua CLEAN_DIRECT_OUTPUT 1 )
  274. # Installed manually for APPLE for correct bundle paths
  275. #if (WIN32)
  276. # install(TARGETS liblua
  277. # RUNTIME DESTINATION .
  278. # LIBRARY DESTINATION .
  279. #)
  280. #endif()
  281. ## LuaJIT Executable
  282. add_executable ( luajit src/luajit.c src/luajit.rc )
  283. #if (APPLE)
  284. #set_target_properties(luajit PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
  285. #endif()
  286. target_link_libraries ( luajit liblua )
  287. ## INSTALL
  288. #install_library(liblua)