@ -6,20 +6,23 @@ enable_language(C)
enable_language ( ASM )
enable_testing ( )
# G e t a c c e s s t o C M a k e h e l p e r s
set ( CMAKE_MODULE_PATH ${ CMAKE_MODULE_PATH } "${CMAKE_SOURCE_DIR}/cmake" )
# B y d e f a u l t J I T i s O F F
option ( LLVM_JIT "Controls whether LLVM JIT compilation will be enabled, default is OFF" OFF )
option ( STATIC_BUILD "Build static version of Ravi, default is OFF" OFF )
option ( EMBEDDED_DMRC "Controls whether the embedded dmrC feature should be enabled, default is OFF" OFF )
option ( COMPUTED_GOTO "Controls whether the interpreter switch will use computed gotos on gcc/clang, default is OFF" ON )
option ( ASM_VM "Controls whether to use the new VM (not ready yet! so don't turn on)" OFF )
option ( LTESTS "Controls whether ltests are enabled in Debug mode" OFF )
if ( LLVM_JIT )
set ( ASM_VM OFF )
endif ( )
if ( ASM_VM )
# F o r n o w w e s w i t c h t o s t a t i c b u i l d
# T O D O A f i x i s n e e d e d t o e n s u r e t h a t i n s h a r e d l i b r a r y t h e a s m f u n c t i o n s a r e r e s o l v e d
set ( STATIC_BUILD ON )
set ( LTESTS OFF )
endif ( )
if ( STATIC_BUILD )
@ -36,11 +39,10 @@ if (LLVM_JIT)
include_directories ( ${ LLVM_INCLUDE_DIRS } )
add_definitions ( ${ LLVM_DEFINITIONS } )
add_definitions ( -DUSE_LLVM )
endif ( )
if ( EMBEDDED_DMRC )
add_definitions ( -DUSE_DMR_C )
# W e a l s o n e e d t o d e f i n e U S E _ L L V M w h e n c o m p i l i n g c o d e
# b u t r a t h e r t h a n s e t t i n g g l o b a l l y w e s e t t h i s w h e n b u i l d i n g t h e
# l i b r a r y
endif ( )
message ( STATUS "Computed goto ${COMPUTED_GOTO}" )
@ -79,10 +81,7 @@ if (MSVC)
add_definitions ( "/wd4141" )
add_definitions ( "/DLUA_COMPAT_5_2" )
add_definitions ( "/DLUA_COMPAT_5_1" )
endif ( )
if ( ( CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang" ) AND NOT APPLE )
elseif ( ( CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang" ) AND NOT APPLE )
if ( NOT WIN32 )
# a s s u m e L i n u x
set ( OS_FLAGS "-DLUA_USE_LINUX" )
@ -97,9 +96,7 @@ if ((CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") A
set ( CMAKE_CXX_FLAGS_RELEASE "-fno-rtti -O2 -fomit-frame-pointer -Wall -Wno-sign-compare -Winline -std=c++11 -fno-exceptions ${LUA_COMPAT_FLAGS} ${OS_FLAGS}" )
set ( CMAKE_CXX_FLAGS_DEBUG "${SANITIZER_FLAGS} -fno-omit-frame-pointer -fno-rtti -O0 -g3 -Wall -Wno-sign-compare -std=c++11 -fno-exceptions ${LUA_COMPAT_FLAGS} ${OS_FLAGS}" )
set ( CMAKE_CXX_FLAGS_RELWITHDEBINFO "${SANITIZER_FLAGS} -fno-rtti -O1 -g3 -Wall -Wno-sign-compare -std=c++11 -fno-exceptions ${LUA_COMPAT_FLAGS} ${OS_FLAGS}" )
endif ( )
if ( APPLE )
elseif ( APPLE )
set ( LUA_COMPAT_FLAGS "-DLUA_COMPAT_5_2 -DLUA_COMPAT_5_1" )
set ( CMAKE_C_FLAGS "-std=c99 -O3 -Wall -Wextra ${LUA_COMPAT_FLAGS} -DLUA_USE_MACOSX" )
set ( CMAKE_C_FLAGS_DEBUG "-std=c99 -O0 -g3 -Wall -Wextra ${LUA_COMPAT_FLAGS} -DLUA_USE_MACOSX" )
@ -109,10 +106,12 @@ if (APPLE)
set ( CMAKE_CXX_FLAGS_RELEASE "-fno-rtti -O3 -Wall -Wno-sign-compare -std=c++11 -fno-exceptions ${LUA_COMPAT_FLAGS} -DLUA_USE_MACOSX" )
set ( CMAKE_CXX_FLAGS_DEBUG "-fno-rtti -O0 -g3 -Wall -Wno-sign-compare -std=c++11 -fno-exceptions ${LUA_COMPAT_FLAGS} -DLUA_USE_MACOSX" )
set ( CMAKE_CXX_FLAGS_RELWITHDEBINFO "-fno-rtti -O1 -g3 -Wall -Wno-sign-compare -std=c++11 -fno-exceptions ${LUA_COMPAT_FLAGS} -DLUA_USE_MACOSX" )
else ( )
message ( FATAL_ERROR "Unsupported platform" )
endif ( )
include_directories ( "${PROJECT_SOURCE_DIR}/include" )
if ( CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND NOT ASM_VM )
if ( ( CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "DEBUG" ) AND LTESTS AND NOT ASM_VM )
# N o t e t h a t e n a b l i n g l t e s t s . h m e s s e s w i t h g l o b a l _ S t a t e a n d t h u s i n t e r f e r e s w i t h A S M _ V M
message ( STATUS "Enabling Lua extended test harness 'ltests'" )
add_definitions ( -DLUA_USER_H= "ltests.h" )
@ -121,7 +120,6 @@ endif ()
if ( ASM_VM )
# F o r n o w w e s w i t c h t o s t a t i c b u i l d
# T O D O A f i x i s n e e d e d t o e n s u r e t h a t i n s h a r e d l i b r a r y t h e a s m f u n c t i o n s a r e r e s o l v e d
set ( STATIC_BUILD ON )
add_definitions ( -DRAVI_USE_ASMVM )
set ( ASMVM_DEFS ${ PROJECT_SOURCE_DIR } /include/ravi_asmvm_defs.h )
if ( WIN32 AND NOT CYGWIN )
@ -167,8 +165,7 @@ if (LLVM_JIT)
s r c / r a v i _ l l v m a r i t h 1 . c p p s r c / r a v i _ l l v m c a l l . c p p s r c / r a v i _ l l v m t a b l e . c p p
s r c / r a v i _ l l v m a r i t h 2 . c p p s r c / r a v i _ l l v m t f o r c a l l . c p p s r c / r a v i _ l l v m r e s t . c p p
s r c / r a v i _ l l v m l u a a p i . c p p )
endif ( )
if ( NOT LLVM_JIT )
else ( )
set ( NO_JIT_SRCS src/ravi_nojit.c )
endif ( )
# d e f i n e t h e l u a c o r e s o u r c e f i l e s
@ -232,12 +229,10 @@ if (EMBEDDED_DMRC)
d m r _ c / s r c / p a r s e . h
d m r _ c / s r c / p o r t . h
d m r _ c / s r c / p t r l i s t . h
d m r _ c / s r c / p t r m a p . h
d m r _ c / s r c / s c o p e . h
d m r _ c / s r c / s y m b o l . h
d m r _ c / s r c / t a r g e t . h
d m r _ c / s r c / t o k e n . h
d m r _ c / s r c / s s a . h
d m r _ c / s r c / w a l k s y m b o l . h
)
@ -260,13 +255,11 @@ if (EMBEDDED_DMRC)
d m r _ c / s r c / t o k e n i z e . c
d m r _ c / s r c / p r e - p r o c e s s . c
d m r _ c / s r c / p t r l i s t . c
d m r _ c / s r c / p t r m a p . c
d m r _ c / s r c / s c o p e . c
d m r _ c / s r c / s h o w - p a r s e . c
d m r _ c / s r c / s i m p l i f y . c
d m r _ c / s r c / s y m b o l . c
d m r _ c / s r c / u n s s a . c
d m r _ c / s r c / s s a . c
d m r _ c / s r c / w a l k s y m b o l . c
s r c / r a v i _ d m r c _ p a r s e s y m b o l s . c
)
@ -278,8 +271,12 @@ if (EMBEDDED_DMRC)
set ( DMR_C_JIT_HEADERS
d m r _ c / l l v m - b a c k e n d / d m r _ c . h
)
include_directories ( "${PROJECT_SOURCE_DIR}/dmr_c/llvm-backend" )
else ( )
set ( DMR_C_JIT_HEADERS
d m r _ c / n u l l - b a c k e n d / d m r _ c . h
)
include_directories ( "${PROJECT_SOURCE_DIR}/dmr_c/null-backend" )
endif ( )
if ( MSVC OR APPLE )
@ -370,16 +367,64 @@ if (NOT STATIC_BUILD)
if ( WIN32 )
# e n a b l e D L L e x p o r t
set_target_properties ( ${ LIBRAVI_NAME } PROPERTIES DEFINE_SYMBOL "LUA_BUILD_AS_DLL" )
else ( )
else ( )
set_target_properties ( ${ LIBRAVI_NAME } PROPERTIES PREFIX "" )
endif ( )
endif ( )
endif ( )
if ( LLVM_JIT )
set_target_properties ( ${ LIBRAVI_NAME } PROPERTIES COMPILE_DEFINITIONS "USE_LLVM=1" )
endif ( )
if ( EMBEDDED_DMRC )
set_target_properties ( ${ LIBRAVI_NAME } PROPERTIES COMPILE_DEFINITIONS "USE_DMR_C=1" )
endif ( )
target_link_libraries ( ${ LIBRAVI_NAME } ${ EXTRA_LIBRARIES } ${ LLVM_LIBS } )
# R a v i e x e c u t a b l e
# Ma i n Ra v i e x e c u t a b l e
add_executable ( ravi src/lua.c )
if ( LLVM_JIT )
set_target_properties ( ravi PROPERTIES COMPILE_DEFINITIONS "USE_LLVM=1" )
endif ( )
if ( EMBEDDED_DMRC )
set_target_properties ( ravi PROPERTIES COMPILE_DEFINITIONS "USE_DMR_C=1" )
endif ( )
target_link_libraries ( ravi ${ LIBRAVI_NAME } )
# S o u r c e s t h a t a r e n e e d e d f o r a s t a t i c N O J I T b a s i c l i b r a r y
set ( NOJIT_RAVI_SRCS
$ { R A V I _ H E A D E R S }
$ { L U A _ L I B _ S R C S }
$ { L U A _ C O R E _ S R C S }
s r c / r a v i _ n o j i t . c )
# W e a l w a y s b u i l d a s t a t i c l i b r a r y w i t h o u t J I T s o t h a t
# w e c a n c r e a t e s o m e d e f a u l t e x e c u t a b l e s
add_library ( libravinojit_static
$ { N O J I T _ R A V I _ S R C S } )
set_target_properties ( libravinojit_static PROPERTIES PREFIX "" ) # A s w e a l r e a d y p r e f i x w i t h l i b
target_link_libraries ( libravinojit_static ${ EXTRA_LIBRARIES } )
# C r e a t e a s i m p l e N o J I T v e r s i o n o f s t a t i c a l l y l i n k e d r a v i
# T h i s i s s o m e t i m e s u s e f u l i n o t h e r p r o j e c t s t h a t j u s t n e e d a L u a c o m m a n d l i n e
# b u t d o n o t c a r e a b o u t t h e s h a r e d l i b r a r y
add_executable ( ravi_s
s r c / l u a . c )
target_link_libraries ( ravi_s libravinojit_static )
# R a v i V S C o d e D e b u g a d a p t e r
set ( RAVI_DEBUGGER_TARGET ravidebug )
add_executable ( ${ RAVI_DEBUGGER_TARGET }
v s c o d e - d e b u g g e r / s r c / r a v i d e b u g . c
v s c o d e - d e b u g g e r / s r c / j s o n . c
v s c o d e - d e b u g g e r / s r c / p r o t o c o l . c )
target_link_libraries ( ${ RAVI_DEBUGGER_TARGET } libravinojit_static )
# T e s t s f o r V S C o d e D e b u g A d a p t e r
add_executable ( testravidebug
v s c o d e - d e b u g g e r / s r c / t e s t r a v i d e b u g . c
v s c o d e - d e b u g g e r / s r c / j s o n . c
v s c o d e - d e b u g g e r / s r c / p r o t o c o l . c )
target_link_libraries ( testravidebug libravinojit_static )
# S i m p l e V M t e s t s
add_executable ( test_vm tests/test_vm.c )
target_link_libraries ( test_vm ${ LIBRAVI_NAME } )
@ -387,38 +432,23 @@ target_link_libraries(test_vm ${LIBRAVI_NAME})
if ( LLVM_JIT )
# L L V M p l a y g r o u n d
add_executable ( test_llvm tests/test_llvm.cpp )
set_target_properties ( test_llvm PROPERTIES COMPILE_DEFINITIONS "USE_LLVM=1" )
target_link_libraries ( test_llvm ${ LIBRAVI_NAME } )
endif ( )
add_executable ( test_misc tests/test_misc.c )
add_test ( TestRaviDebug testravidebug )
if ( LLVM_JIT )
add_test ( TestLLVM test_llvm )
endif ( )
add_test ( TestVM test_vm )
add_test ( TestMisc test_misc )
# B u i l d V S C o d e D e b u g A d a p t e r f o r R a v i
if ( STATIC_BUILD )
add_executable ( testravidebug vscode-debugger/src/testravidebug.c vscode-debugger/src/json.c vscode-debugger/src/protocol.c )
target_link_libraries ( testravidebug ${ LIBRAVI_NAME } )
add_test ( TestRaviDebug testravidebug )
if ( LLVM_JIT )
set ( RAVI_DEBUGGER_TARGET ravidebugllvm )
else ( )
set ( RAVI_DEBUGGER_TARGET ravidebug )
endif ( )
# R a v i V S C o d e D e b u g a d a p t e r
add_executable ( ${ RAVI_DEBUGGER_TARGET } vscode-debugger/src/ravidebug.c vscode-debugger/src/json.c vscode-debugger/src/protocol.c )
target_link_libraries ( ${ RAVI_DEBUGGER_TARGET } ${ LIBRAVI_NAME } )
endif ( )
install ( FILES ${ LUA_HEADERS }
D E S T I N A T I O N i n c l u d e / r a v i )
install ( TARGETS ${ LIBRAVI_NAME } ravi ${ RAVI_DEBUGGER_TARGET }
install ( TARGETS ${ LIBRAVI_NAME } ravi ${ RAVI_DEBUGGER_TARGET } ravi_s
R U N T I M E D E S T I N A T I O N b i n
A R C H I V E D E S T I N A T I O N l i b
L I B R A R Y D E S T I N A T I O N l i b )