CMakeLists.txt 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. #
  2. # Copyright (c) 2008-2015 the Urho3D project.
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a copy
  5. # of this software and associated documentation files (the "Software"), to deal
  6. # in the Software without restriction, including without limitation the rights
  7. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. # copies of the Software, and to permit persons to whom the Software is
  9. # furnished to do so, subject to the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included in
  12. # all copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. # THE SOFTWARE.
  21. #
  22. # Based on src/Makefile from http://luajit.org
  23. # The cross-compiling logic is ported to CMake as faithful as possible although currently Urho3D does not support all target archs supported by LuaJIT
  24. # Makefile: Compiler options
  25. if (NOT MSVC)
  26. # Since the assembler part does NOT maintain a frame pointer, it's pointless
  27. # to slow down the C part by not omitting it. Debugging, tracebacks and
  28. # unwinding are not affected -- the assembler part has frame unwind
  29. # information and GCC emits it where needed (x64) or with -g (see CCDEBUG).
  30. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer")
  31. endif ()
  32. # Makefile: Build mode
  33. # When LuaJIT is enabled for Urho3D, always build as static library to be linked against in main Urho3D executable or library CMake target
  34. # Use -DURHO3D_LUAJIT_AMALG=1 to compile LuaJIT core as one huge C file and allows GCC to generate faster and shorter code
  35. # Use -Dxxxxx=0/1/2 as CMake build option to turn off/on the features and debugging support below
  36. # Makefile: Features
  37. #
  38. # Permanently disable the FFI extension to reduce the size of the LuaJIT
  39. # executable. But please consider that the FFI library is compiled-in,
  40. # but NOT loaded by default. It only allocates any memory, if you actually
  41. # make use of it.
  42. if (LUAJIT_DISABLE_FFI)
  43. add_definitions (-DLUAJIT_DISABLE_FFI)
  44. endif ()
  45. # Features from Lua 5.2 that are unlikely to break existing code are
  46. # enabled by default. Some other features that *might* break some existing
  47. # code (e.g. __pairs or os.execute() return values) can be enabled here.
  48. # Note: this does not provide full compatibility with Lua 5.2 at this time.
  49. if (LUAJIT_ENABLE_LUA52COMPAT)
  50. add_definitions (-DLUAJIT_ENABLE_LUA52COMPAT)
  51. endif ()
  52. # Disable the JIT compiler, i.e. turn LuaJIT into a pure interpreter.
  53. if (LUAJIT_DISABLE_JIT)
  54. add_definitions (-DLUAJIT_DISABLE_JIT)
  55. endif ()
  56. # Some architectures (e.g. PPC) can use either single-number (1) or
  57. # dual-number (2) mode. Uncomment one of these lines to override the
  58. # default mode. Please see LJ_ARCH_NUMMODE in lj_arch.h for details.
  59. if (DEFINED LUAJIT_NUMMODE)
  60. add_definitions (-DLUAJIT_NUMMODE=${LUAJIT_NUMMODE})
  61. endif ()
  62. # Makefile: Debugging support
  63. # Note that most of these are NOT suitable for benchmarking or release mode!
  64. #
  65. # Use the system provided memory allocator (realloc) instead of the
  66. # bundled memory allocator. This is slower, but sometimes helpful for
  67. # debugging. It's helpful for Valgrind's memcheck tool, too. This option
  68. # cannot be enabled on x64, since the built-in allocator is mandatory.
  69. if (LUAJIT_USE_SYSMALLOC)
  70. add_definitions (-DLUAJIT_USE_SYSMALLOC)
  71. endif ()
  72. # This define is required to run LuaJIT under Valgrind. The Valgrind
  73. # header files must be installed. You should enable debug information, too.
  74. # Use --suppressions=lj.supp to avoid some false positives.
  75. if (LUAJIT_USE_VALGRIND)
  76. add_definitions (-DLUAJIT_USE_VALGRIND)
  77. endif ()
  78. # This is the client for the GDB JIT API. GDB 7.0 or higher is required
  79. # to make use of it. See lj_gdbjit.c for details. Enabling this causes
  80. # a non-negligible overhead, even when not running under GDB.
  81. if (LUAJIT_USE_GDBJIT)
  82. add_definitions (-DLUAJIT_USE_GDBJIT)
  83. endif ()
  84. # Turn on assertions for the Lua/C API to debug problems with lua_* calls.
  85. # This is rather slow -- use only while developing C libraries/embeddings.
  86. if (LUA_USE_APICHECK)
  87. add_definitions (-DLUA_USE_APICHECK)
  88. endif ()
  89. # Turn on assertions for the whole LuaJIT VM. This significantly slows down
  90. # everything. Use only if you suspect a problem with LuaJIT itself.
  91. if (LUA_USE_ASSERT)
  92. add_definitions (-DLUA_USE_ASSERT)
  93. endif ()
  94. # Makefile: Flags and options for host and target
  95. if (MSVC)
  96. if (LUAJIT_DISABLE_FFI)
  97. set (MSVC_HASFFI 0)
  98. else ()
  99. set (MSVC_HASFFI 1)
  100. endif ()
  101. set (TARGET_TESTARCH "LJ_HASFFI ${MSVC_HASFFI}\n")
  102. if (LUAJIT_DISABLE_JIT)
  103. set (MSVC_HASJIT 0)
  104. else ()
  105. set (MSVC_HASJIT 1)
  106. endif ()
  107. set (TARGET_TESTARCH "${TARGET_TESTARCH} LJ_HASJIT ${MSVC_HASJIT}\n")
  108. if (URHO3D_64BIT)
  109. set (MSVC_ARCH_BITS 64)
  110. set (MSVC_TARGET_ARCH X64)
  111. else ()
  112. set (MSVC_ARCH_BITS 32)
  113. set (MSVC_TARGET_ARCH X86)
  114. endif ()
  115. set (TARGET_TESTARCH "${TARGET_TESTARCH} LJ_ARCH_BITS ${MSVC_ARCH_BITS}\n")
  116. set (TARGET_TESTARCH "${TARGET_TESTARCH} LJ_TARGET_${MSVC_TARGET_ARCH} 1\n")
  117. if (URHO3D_SSE AND NOT URHO3D_64BIT)
  118. set (TARGET_TESTARCH "${TARGET_TESTARCH} __SSE2__ 1\n")
  119. endif ()
  120. # More assumptions
  121. set (TARGET_TESTARCH "${TARGET_TESTARCH} LJ_ARCH_HASFPU 1\n")
  122. set (TARGET_TESTARCH "${TARGET_TESTARCH} LJ_ABI_SOFTFP 0\n")
  123. else ()
  124. set (TARGET_TCFLAGS ${CMAKE_C_FLAGS})
  125. string (REPLACE " " ";" TARGET_TCFLAGS "${TARGET_TCFLAGS}")
  126. execute_process (COMMAND egrep -V RESULT_VARIABLE EGREP_EXIT_CODE OUTPUT_QUIET ERROR_QUIET)
  127. if (EGREP_EXIT_CODE EQUAL 0)
  128. execute_process (COMMAND ${CMAKE_C_COMPILER} ${TARGET_TCFLAGS} -E ${CMAKE_CURRENT_SOURCE_DIR}/src/lj_arch.h -dM
  129. COMMAND egrep "LJ_|MIPSEL|__SSE2__" OUTPUT_VARIABLE TARGET_TESTARCH ERROR_QUIET)
  130. else ()
  131. execute_process (COMMAND ${CMAKE_C_COMPILER} ${TARGET_TCFLAGS} -E ${CMAKE_CURRENT_SOURCE_DIR}/src/lj_arch.h -dM OUTPUT_VARIABLE TARGET_TESTARCH ERROR_QUIET)
  132. endif ()
  133. endif ()
  134. # Macro for finding a substring in TARGET_TESTARCH variable
  135. macro (find_string find_regex output_var)
  136. if (NOT DEFINED ${output_var})
  137. message (STATUS "Finding value for LuaJIT:${output_var}")
  138. string (REGEX MATCH ${find_regex} matched ${TARGET_TESTARCH})
  139. if (matched)
  140. string (REGEX MATCH "\\(.*\\)" captured ${find_regex})
  141. if (captured)
  142. string (REGEX REPLACE ${find_regex} \\1 matched ${matched})
  143. endif ()
  144. # Special case handling to cater for URHO3D_64BIT build option
  145. if (${output_var} STREQUAL TARGET_LJARCH)
  146. string (TOLOWER ${matched} matched)
  147. if (matched STREQUAL x64 AND NOT URHO3D_64BIT)
  148. set (matched x86)
  149. endif ()
  150. elseif (${output_var} STREQUAL ARCH_BITS)
  151. if (matched EQUAL 64 AND NOT URHO3D_64BIT)
  152. set (matched 32)
  153. endif ()
  154. endif ()
  155. set (${output_var} ${matched} CACHE INTERNAL "LUAJIT INTERNAL - ${output_var}")
  156. message (STATUS "Finding value for LuaJIT:${output_var} - found (${matched})")
  157. else ()
  158. set (${output_var} 0 CACHE INTERNAL "LUAJIT INTERNAL - ${output_var}")
  159. message (STATUS "Finding value for LuaJIT:${output_var} - not found")
  160. endif ()
  161. endif ()
  162. endmacro ()
  163. find_string ("LJ_TARGET_(X64|X86|ARM|PPC|PPCSPE|MIPS) 1" TARGET_LJARCH)
  164. if (NOT TARGET_LJARCH)
  165. message (FATAL_ERROR "Unsupported target architecture")
  166. endif ()
  167. if (TARGET_LJARCH STREQUAL mips)
  168. find_string ("MIPSEL (1)" MIPSEL)
  169. if (MIPSEL)
  170. set (TARGET_ARCH ${TARGET_ARCH} -D__MIPSEL__=1)
  171. endif ()
  172. endif ()
  173. find_string ("LJ_TARGET_PS3 (1)" PS3)
  174. if (PS3)
  175. set (TARGET_SYS PS3)
  176. set (TARGET_ARCH ${TARGET_ARCH} -D__CELLOS_LV2__)
  177. add_definitions (-DLUAJIT_USE_SYSMALLOC)
  178. endif ()
  179. find_string ("LJ_NO_UNWIND (1)" NO_UNWIND)
  180. if (NO_UNWIND)
  181. set (TARGET_ARCH ${TARGET_ARCH} -DLUAJIT_NO_UNWIND)
  182. endif ()
  183. set (TARGET_ARCH ${TARGET_ARCH} -DLUAJIT_TARGET=LUAJIT_ARCH_${TARGET_LJARCH})
  184. # Makefile: System detection
  185. if (CMAKE_HOST_WIN32)
  186. set (HOST_SYS Windows)
  187. else ()
  188. execute_process (COMMAND uname -s OUTPUT_VARIABLE HOST_SYS ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
  189. endif ()
  190. if (IOS)
  191. set (TARGET_SYS iOS)
  192. elseif (ANDROID OR RPI)
  193. set (TARGET_SYS Linux)
  194. elseif (MINGW)
  195. set (TARGET_SYS Windows)
  196. elseif (NOT TARGET_SYS)
  197. set (TARGET_SYS ${HOST_SYS})
  198. endif ()
  199. if (NOT HOST_SYS STREQUAL TARGET_SYS)
  200. if (TARGET_SYS STREQUAL Windows)
  201. set (HOST_XCFLAGS ${HOST_XCFLAGS} -malign-double -DLUAJIT_OS=LUAJIT_OS_WINDOWS)
  202. elseif (TARGET_SYS STREQUAL Linux)
  203. set (HOST_XCFLAGS ${HOST_XCFLAGS} -DLUAJIT_OS=LUAJIT_OS_LINUX)
  204. elseif (TARGET_SYS MATCHES Darwin|iOS)
  205. set (HOST_XCFLAGS ${HOST_XCFLAGS} -DLUAJIT_OS=LUAJIT_OS_OSX)
  206. else ()
  207. set (HOST_XCFLAGS ${HOST_XCFLAGS} -DLUAJIT_OS=LUAJIT_OS_OTHER)
  208. endif ()
  209. endif ()
  210. # Makefile: Files and pathnames
  211. if (NOT BAKED_CMAKE_SOURCE_DIR)
  212. set (BAKED_CMAKE_SOURCE_DIR ${CMAKE_SOURCE_DIR})
  213. endif ()
  214. set (DASM_ARCH ${TARGET_LJARCH})
  215. # Below regex is a workaround for "LJ_ARCH_BITS (.*?)\\n" as CMake does not understand non-greedy quantifier
  216. find_string ("LJ_ARCH_BITS ([^\\n]*)" ARCH_BITS)
  217. if (ARCH_BITS EQUAL 64)
  218. set (DASM_AFLAGS ${DASM_AFLAGS} -D P64)
  219. endif ()
  220. find_string ("LJ_HASJIT (1)" HASJIT)
  221. if (HASJIT)
  222. set (DASM_AFLAGS ${DASM_AFLAGS} -D JIT)
  223. endif ()
  224. find_string ("LJ_HASFFI (1)" HASFFI)
  225. if (HASFFI)
  226. set (DASM_AFLAGS ${DASM_AFLAGS} -D FFI)
  227. endif ()
  228. find_string ("LJ_DUALNUM (1)" DUALNUM)
  229. if (DUALNUM)
  230. set (DASM_AFLAGS ${DASM_AFLAGS} -D DUALNUM)
  231. endif ()
  232. find_string ("LJ_ARCH_HASFPU (1)" ARCH_HASFPU)
  233. if (ARCH_HASFPU)
  234. set (DASM_AFLAGS ${DASM_AFLAGS} -D FPU)
  235. endif ()
  236. set (TARGET_ARCH ${TARGET_ARCH} -DLJ_ARCH_HASFPU=${ARCH_HASFPU})
  237. find_string ("LJ_ABI_SOFTFP (1)" ABI_SOFTFP)
  238. if (NOT ABI_SOFTFP)
  239. set (DASM_AFLAGS ${DASM_AFLAGS} -D HFABI)
  240. endif ()
  241. set (TARGET_ARCH ${TARGET_ARCH} -DLJ_ABI_SOFTFP=${ABI_SOFTFP})
  242. # Below regex is a workaround for "LJ_ARCH_VERSION (.*?)\\n" as CMake does not understand non-greedy quantifier
  243. find_string ("LJ_ARCH_VERSION ([^\\n]*)" ARCH_VERSION)
  244. set (DASM_AFLAGS ${DASM_AFLAGS} -D VER=${ARCH_VERSION})
  245. if (TARGET_SYS STREQUAL Windows)
  246. set (DASM_AFLAGS ${DASM_AFLAGS} -D WIN)
  247. endif ()
  248. if (TARGET_LJARCH STREQUAL x86)
  249. find_string ("__SSE2__ (1)" SSE2)
  250. if (SSE2)
  251. set (DASM_AFLAGS ${DASM_AFLAGS} -D SSE)
  252. endif ()
  253. elseif (TARGET_LJARCH STREQUAL x64)
  254. set (DASM_ARCH x86)
  255. elseif (TARGET_LJARCH STREQUAL arm)
  256. if (TARGET_SYS STREQUAL iOS)
  257. set (DASM_AFLAGS ${DASM_AFLAGS} -D IOS)
  258. endif ()
  259. elseif (TARGET_LJARCH STREQUAL ppc)
  260. find_string ("LJ_ARCH_SQRT (1)" ARCH_SQRT)
  261. if (ARCH_SQRT)
  262. set (DASM_AFLAGS ${DASM_AFLAGS} -D SQRT)
  263. endif ()
  264. find_string ("LJ_ARCH_ROUND (1)" ARCH_ROUND)
  265. if (ARCH_ROUND)
  266. set (DASM_AFLAGS ${DASM_AFLAGS} -D ROUND)
  267. endif ()
  268. find_string ("LJ_ARCH_PPC64 (1)" ARCH_PPC64)
  269. if (ARCH_PPC64)
  270. set (DASM_AFLAGS ${DASM_AFLAGS} -D GPR64)
  271. endif ()
  272. if (TARGET_SYS STREQUAL PS3)
  273. set (DASM_AFLAGS ${DASM_AFLAGS} -D PPE -D TOC)
  274. endif ()
  275. endif ()
  276. set (DASM_FLAGS ${DASM_XFLAGS} ${DASM_AFLAGS})
  277. # Makefile: Build mode handling
  278. # Urho3D only builds static LuaJIT library
  279. # Makefile: Make targets
  280. # The host tool must be built natively
  281. if (CMAKE_CROSSCOMPILING OR IOS)
  282. # Escape the variables
  283. foreach (ESCAPED_VAR HOST_XCFLAGS TARGET_ARCH DASM_FLAGS DASM_ARCH)
  284. string (REPLACE -D +D ${ESCAPED_VAR} "${${ESCAPED_VAR}}")
  285. string (REPLACE ";" , ${ESCAPED_VAR} "${${ESCAPED_VAR}}")
  286. endforeach ()
  287. # When cross-compiling, build the host tool as external project
  288. include (ExternalProject)
  289. ExternalProject_Add (buildvm
  290. SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/host
  291. CMAKE_ARGS -DURHO3D_64BIT=${URHO3D_64BIT} -DDEST_RUNTIME_DIR=${CMAKE_BINARY_DIR}/bin/tool -DBAKED_CMAKE_SOURCE_DIR=${CMAKE_SOURCE_DIR} -DHOST_XCFLAGS=${HOST_XCFLAGS} -DTARGET_ARCH=${TARGET_ARCH} -DDASM_FLAGS=${DASM_FLAGS} -DDASM_ARCH=${DASM_ARCH})
  292. else ()
  293. # Otherwise, build it internally as per normal
  294. add_subdirectory (src/host)
  295. endif ()
  296. # Add definitions specific for target C Compiler
  297. if (NOT MSVC)
  298. # Large file support
  299. add_definitions (-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE)
  300. # Buffer overflows check
  301. add_definitions (-U_FORTIFY_SOURCE)
  302. endif ()
  303. # Define target name for LuaJIT library
  304. set (TARGET_NAME LuaJIT)
  305. # Macro for generating source file
  306. macro (generate_source name mode)
  307. set (GEN_SRC ${CMAKE_CURRENT_BINARY_DIR}/generated/${name})
  308. set (GEN_SRCS ${GEN_SRCS} ${GEN_SRC})
  309. add_custom_command (OUTPUT ${GEN_SRC}
  310. COMMAND ${CMAKE_BINARY_DIR}/bin/tool/buildvm -m ${mode} -o ${GEN_SRC} ${ARGN}
  311. DEPENDS buildvm ${ARGN}
  312. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  313. COMMENT "Generating buildvm output: ${name}")
  314. endmacro ()
  315. # Define generated source files
  316. file (MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated)
  317. if (WIN32)
  318. set (LJVM_MODE peobj)
  319. set (LJVM_BOUT lj_vm.obj)
  320. else ()
  321. set (LJVM_BOUT lj_vm.s)
  322. enable_language (ASM)
  323. set (CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} ${DASH_MBIT}")
  324. if (APPLE)
  325. set (LJVM_MODE machasm)
  326. else ()
  327. set (LJVM_MODE elfasm)
  328. endif ()
  329. endif ()
  330. set (LJLIB_C src/lib_base.c src/lib_math.c src/lib_bit.c src/lib_string.c src/lib_table.c
  331. src/lib_io.c src/lib_os.c src/lib_package.c src/lib_debug.c src/lib_jit.c src/lib_ffi.c)
  332. generate_source (${LJVM_BOUT} ${LJVM_MODE})
  333. foreach (MODE bcdef ffdef libdef recdef)
  334. generate_source (lj_${MODE}.h ${MODE} ${LJLIB_C})
  335. endforeach ()
  336. generate_source (vmdef.lua vmdef ${LJLIB_C})
  337. generate_source (lj_folddef.h folddef src/lj_opt_fold.c)
  338. # Define source files
  339. if (URHO3D_LUAJIT_AMALG)
  340. set (LJCORE_C src/ljamalg.c)
  341. else ()
  342. set (LJCORE_C src/lj_gc.c src/lj_err.c src/lj_char.c src/lj_bc.c src/lj_obj.c
  343. src/lj_str.c src/lj_tab.c src/lj_func.c src/lj_udata.c src/lj_meta.c src/lj_debug.c
  344. src/lj_state.c src/lj_dispatch.c src/lj_vmevent.c src/lj_vmmath.c src/lj_strscan.c
  345. src/lj_api.c src/lj_lex.c src/lj_parse.c src/lj_bcread.c src/lj_bcwrite.c src/lj_load.c
  346. src/lj_ir.c src/lj_opt_mem.c src/lj_opt_fold.c src/lj_opt_narrow.c
  347. src/lj_opt_dce.c src/lj_opt_loop.c src/lj_opt_split.c src/lj_opt_sink.c
  348. src/lj_mcode.c src/lj_snap.c src/lj_record.c src/lj_crecord.c src/lj_ffrecord.c
  349. src/lj_asm.c src/lj_trace.c src/lj_gdbjit.c
  350. src/lj_ctype.c src/lj_cdata.c src/lj_cconv.c src/lj_ccall.c src/lj_ccallback.c
  351. src/lj_carith.c src/lj_clib.c src/lj_cparse.c
  352. src/lj_lib.c src/lj_alloc.c src/lib_aux.c
  353. ${LJLIB_C} src/lib_init.c)
  354. endif ()
  355. set (SOURCE_FILES ${LJCORE_C} ${GEN_SRCS})
  356. # Define dependency libs
  357. set (INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/generated)
  358. # Setup target
  359. setup_library ()
  360. # Install headers for building and using the Urho3D library (no direct dependencies but library user may need them)
  361. install_header_files (DIRECTORY src/ DESTINATION ${DEST_INCLUDE_DIR}/ThirdParty/LuaJIT FILES_MATCHING PATTERN *.h *.hpp) # Note: the trailing slash is significant
  362. # Setup additional Lua standalone target (this target can be transfered and executed on an embedded device, such as Raspberry Pi and Android)
  363. if (NOT IOS AND NOT EMSCRIPTEN) # LuaJIT library on Emscripten is not possible anyway but just in case it could be in the future, exclude it to build standalone target
  364. # Define target name for LuaJIT interpreter cum compiler
  365. set (TARGET_NAME luajit_interpreter) # Note: intended target name is 'luajit' which clashes with 'LuaJIT' library target above for case-insensitive platform
  366. # Define source files
  367. set (SOURCE_FILES src/luajit.c)
  368. # Define dependency libs
  369. set (LIBS LuaJIT)
  370. if (NOT MSVC)
  371. list (APPEND LIBS m)
  372. endif ()
  373. # Setup target
  374. setup_executable (NODEPS)
  375. adjust_target_name () # Adjust to intended target output name
  376. # Define post build steps
  377. set (LUAJIT_DEP_DIR ${CMAKE_BINARY_DIR}/bin/jit)
  378. add_custom_command (TARGET ${TARGET_NAME} POST_BUILD
  379. COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/src/jit ${LUAJIT_DEP_DIR}
  380. COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/generated/vmdef.lua ${LUAJIT_DEP_DIR}
  381. COMMENT "Copying dependency files for luajit standalone executable")
  382. # Install dependency files required by luajit
  383. install (DIRECTORY ${LUAJIT_DEP_DIR} DESTINATION ${DEST_RUNTIME_DIR})
  384. endif ()
  385. # Add directory containing the dependency files into the LuaJIT module search path
  386. set (LUA_RDIR ./) # Relative directory
  387. set (LUA_IDIR ${CMAKE_INSTALL_PREFIX}/${DEST_RUNTIME_DIR}/) # Installation directory
  388. add_definitions (-DLUA_RDIR="${LUA_RDIR}" -DLUA_IDIR="${LUA_IDIR}")