@@ -9,6 +9,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
99option (LIBSCRATCHCPP_BUILD_UNIT_TESTS "Build unit tests" ON )
1010option (LIBSCRATCHCPP_NETWORK_SUPPORT "Support for downloading projects" ON )
1111option (LIBSCRATCHCPP_COMPUTED_GOTO "Support for computed goto" ON )
12+ option (LIBSCRATCHCPP_USE_LLVM "Compile scripts to LLVM IR (work in progress)" OFF )
13+ option (LIBSCRATCHCPP_PRINT_LLVM_IR "Print LLVM IR of compiled Scratch scripts (for debugging)" OFF )
1214
1315if (NOT (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" ))
1416 # Computed goto not supported on anything except GCC
@@ -45,7 +47,6 @@ target_sources(scratchcpp
4547 include /scratchcpp/field.h
4648 include /scratchcpp/script.h
4749 include /scratchcpp/broadcast.h
48- include /scratchcpp/compiler.h
4950 include /scratchcpp/virtualmachine.h
5051 include /scratchcpp/blockprototype.h
5152 include /scratchcpp/block.h
@@ -65,6 +66,25 @@ target_sources(scratchcpp
6566 include /scratchcpp/imonitorhandler.h
6667)
6768
69+ if (LIBSCRATCHCPP_USE_LLVM)
70+ target_compile_definitions (scratchcpp PUBLIC USE_LLVM)
71+ target_sources (scratchcpp
72+ PUBLIC
73+ include /scratchcpp/dev/compiler.h
74+ include /scratchcpp/dev/executablecode.h
75+ include /scratchcpp/dev/executioncontext.h
76+ )
77+
78+ if (LIBSCRATCHCPP_PRINT_LLVM_IR)
79+ target_compile_definitions (scratchcpp PRIVATE PRINT_LLVM_IR)
80+ endif ()
81+ else ()
82+ target_sources (scratchcpp
83+ PUBLIC
84+ include /scratchcpp/compiler.h
85+ )
86+ endif ()
87+
6888include (FetchContent)
6989set (ZIP_SRC thirdparty/zip/src)
7090set (UTFCPP_SRC thirdparty/utfcpp/source )
@@ -94,6 +114,12 @@ if (LIBSCRATCHCPP_NETWORK_SUPPORT)
94114 target_compile_definitions (scratchcpp PRIVATE LIBSCRATCHCPP_NETWORK_SUPPORT)
95115endif ()
96116
117+ if (LIBSCRATCHCPP_USE_LLVM)
118+ include (build /HunterPackages.cmake)
119+ include (build /LLVM.cmake)
120+ target_link_libraries (scratchcpp PRIVATE LLVM)
121+ endif ()
122+
97123target_compile_definitions (scratchcpp PRIVATE LIBSCRATCHCPP_LIBRARY)
98124target_compile_definitions (scratchcpp PRIVATE LIBSCRATCHCPP_VERSION="${PROJECT_VERSION} " )
99125target_compile_definitions (scratchcpp PRIVATE LIBSCRATCHCPP_VERSION_MAJOR=${PROJECT_VERSION_MAJOR} )
0 commit comments