| 
								
							 | 
							
								cmake_minimum_required(VERSION 3.14)
							 | 
						
						
						
							| 
								
							 | 
							
								project(ink C)
							 | 
						
						
						
							| 
								
							 | 
							
								
							 | 
						
						
						
							| 
								
							 | 
							
								include(CTest)
							 | 
						
						
						
							| 
								
							 | 
							
								
							 | 
						
						
						
							| 
								
							 | 
							
								set(CMAKE_C_STANDARD 90)
							 | 
						
						
						
							| 
								
							 | 
							
								
							 | 
						
						
						
							| 
								
							 | 
							
								add_library(ink lib.c include/ink.h)
							 | 
						
						
						
							| 
								
							 | 
							
								
							 | 
						
						
						
							| 
								
							 | 
							
								# Uncomment to disable the redundant arithmetic
							 | 
						
						
						
							| 
								
							 | 
							
								# add_definitions(-DNOEXTRAARITHMETIC)
							 | 
						
						
						
							| 
								
							 | 
							
								
							 | 
						
						
						
							| 
								
							 | 
							
								# Uncomment to disable array types
							 | 
						
						
						
							| 
								
							 | 
							
								# add_definitions(-DNOARRAYLIB)
							 | 
						
						
						
							| 
								
							 | 
							
								
							 | 
						
						
						
							| 
								
							 | 
							
								# Uncomment to disable string literal
							 | 
						
						
						
							| 
								
							 | 
							
								# add_definitions(-DNOSTRINGLITERALS)
							 | 
						
						
						
							| 
								
							 | 
							
								
							 | 
						
						
						
							| 
								
							 | 
							
								# Ensures the interpreter doesn't use the standard C library functions
							 | 
						
						
						
							| 
								
							 | 
							
								# add_definitions(-DNOSTDLIB)
							 | 
						
						
						
							| 
								
							 | 
							
								
							 | 
						
						
						
							| 
								
							 | 
							
								# Removes several checks to improve performance in cases where ink is used as a bytecode
							 | 
						
						
						
							| 
								
							 | 
							
								# add_definitions(-DNOEXTRACHECKS)
							 | 
						
						
						
							| 
								
							 | 
							
								
							 | 
						
						
						
							| 
								
							 | 
							
								add_definitions(-DINK_STEP_BATCH_COUNT=20)
							 | 
						
						
						
							| 
								
							 | 
							
								
							 | 
						
						
						
							| 
								
							 | 
							
								add_executable(ink_exe main.c)
							 | 
						
						
						
							| 
								
							 | 
							
								target_link_libraries(ink_exe PUBLIC ink)
							 | 
						
						
						
							| 
								
							 | 
							
								target_include_directories(ink PUBLIC include)
							 | 
						
						
						
							| 
								
							 | 
							
								
							 | 
						
						
						
							| 
								
							 | 
							
								add_executable(inksh sh.c)
							 | 
						
						
						
							| 
								
							 | 
							
								target_link_libraries(inksh PUBLIC ink)
							 | 
						
						
						
							| 
								
							 | 
							
								
							 | 
						
						
						
							| 
								
							 | 
							
								# Functional tests
							 | 
						
						
						
							| 
								
							 | 
							
								
							 | 
						
						
						
							| 
								
							 | 
							
								function(add_success_compiled_test cfile success_regex)
							 | 
						
						
						
							| 
								
							 | 
							
								    add_executable(${cfile} test/${cfile}.c)
							 | 
						
						
						
							| 
								
							 | 
							
								    target_link_libraries(${cfile} PUBLIC ink)
							 | 
						
						
						
							| 
								
							 | 
							
								    add_test(NAME ${cfile} COMMAND ${cfile})
							 | 
						
						
						
							| 
								
							 | 
							
								    set_property (TEST ${cfile}
							 | 
						
						
						
							| 
								
							 | 
							
								            PROPERTY PASS_REGULAR_EXPRESSION "${success_regex}")
							 | 
						
						
						
							| 
								
							 | 
							
								endfunction()
							 | 
						
						
						
							| 
								
							 | 
							
								
							 | 
						
						
						
							| 
								
							 | 
							
								add_success_compiled_test(sequence_of_20s "[20]+")
							 | 
						
						
						
							| 
								
							 | 
							
								add_success_compiled_test(macro_optimized "1000")
							 | 
						
						
						
							| 
								
							 | 
							
								add_success_compiled_test(array_shenanigans "Hello World\n\\[ 104 2 9 9 12 64 119 12 15 9 1 42 \\]\n")
							 | 
						
						
						
							| 
								
							 | 
							
								add_success_compiled_test(garbage_shenanigans "[Hello World\n\\[ 104 2 9 9 12 64 119 12 15 9 1 42 \\]\n]*")
							 | 
						
						
						
							| 
								
							 | 
							
								add_success_compiled_test(stacktrace "\\_\\_-MAIN-\\_\\_.*\nbeatrice.*\ngolden.*\nwitch.*\nsys\\.trace\n.*23\n.*16\n.*15\n.*8\n.*4")
							 | 
						
						
						
							| 
								
							 | 
							
								
							 | 
						
						
						
							| 
								
							 | 
							
								if(MSVC)
							 | 
						
						
						
							| 
								
							 | 
							
								    target_compile_options(ink PRIVATE /W4 /WX)
							 | 
						
						
						
							| 
								
							 | 
							
								else()
							 | 
						
						
						
							| 
								
							 | 
							
								    target_compile_options(ink PRIVATE -Wall -Wextra -Wpedantic -Werror)
							 | 
						
						
						
							| 
								
							 | 
							
								endif()
							 | 
						
						
						
							| 
								
							 | 
							
								
							 | 
						
						
						
							| 
								
							 | 
							
								# Benchmark is broken since the addition to coroutines
							 | 
						
						
						
							| 
								
							 | 
							
								# add_executable(ink_bench bench.c)
							 | 
						
						
						
							| 
								
							 | 
							
								# target_link_libraries(ink_bench PUBLIC ink)
							 | 
						
						
						
							| 
								
							 | 
							
								
							 | 
						
						
						
							| 
								
							 | 
							
								# Valgrind testing should run `./test/test01.nk ./test/test03.nk ./test/test06.nk` as arguments
							 |