95 lines
2.6 KiB
CMake
95 lines
2.6 KiB
CMake
set(CMAKE_C_STANDARD 11)
|
|
set(CMAKE_C_EXTENSIONS OFF)
|
|
|
|
option(BUILD_SHARED_LIBS "Build dynamic / shared libraries" ON)
|
|
option(TEST_WITH_VALGRIND_MEMCHECK "Also run tests with valgrind / memcheck" ON)
|
|
|
|
add_library(apfl
|
|
alloc.c
|
|
bytecode.c
|
|
compile.c
|
|
encode.c
|
|
context.c
|
|
error.c
|
|
eval.c
|
|
expr.c
|
|
format.c
|
|
gc.c
|
|
hashmap.c
|
|
io.c
|
|
globals.c
|
|
messages.c
|
|
parser.c
|
|
position.c
|
|
resizable.c
|
|
source_readers.c
|
|
scope.c
|
|
strings.c
|
|
token.c
|
|
tokenizer.c
|
|
value.c
|
|
)
|
|
|
|
target_link_libraries(apfl PUBLIC m)
|
|
|
|
add_executable(apfl-bin main.c)
|
|
target_link_libraries(apfl-bin PUBLIC apfl)
|
|
|
|
add_executable(functional-test-runner functional-test-runner.c)
|
|
target_link_libraries(functional-test-runner PUBLIC apfl)
|
|
|
|
set_target_properties(apfl-bin
|
|
PROPERTIES RUNTIME_OUTPUT_NAME apfl
|
|
)
|
|
|
|
function(unittest name moresources)
|
|
add_executable(${name} test.h ${name}.c ${moresources})
|
|
target_link_libraries(${name} PUBLIC apfl)
|
|
add_test(NAME ${name} COMMAND ${name})
|
|
if(${TEST_WITH_VALGRIND_MEMCHECK})
|
|
add_test(NAME "valgrind_memcheck__${name}" COMMAND valgrind --tool=memcheck --leak-check=full -q --error-exitcode=99 $<TARGET_FILE:${name}>)
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
unittest(tokenizer_test "")
|
|
unittest(parser_test "")
|
|
unittest(resizable_test "resizable.h")
|
|
unittest(hashmap_test "hashmap.h")
|
|
unittest(strings_test "")
|
|
unittest(alloc_test "")
|
|
unittest(encode_test "encode.h")
|
|
|
|
function(functionaltest name)
|
|
add_test(NAME "functionaltest_${name}" COMMAND functional-test-runner ${CMAKE_SOURCE_DIR}/src/functional-tests/${name}.at)
|
|
if(${TEST_WITH_VALGRIND_MEMCHECK})
|
|
add_test(NAME "valgrind_memcheck__functionaltest_${name}" COMMAND valgrind --tool=memcheck --leak-check=full -q --error-exitcode=99 $<TARGET_FILE:functional-test-runner> ${CMAKE_SOURCE_DIR}/src/functional-tests/${name}.at)
|
|
endif()
|
|
endfunction()
|
|
|
|
functionaltest("hello-world")
|
|
functionaltest("factorial")
|
|
functionaltest("function-const-capture")
|
|
functionaltest("function-mutable-capture")
|
|
functionaltest("map")
|
|
functionaltest("deconstruct")
|
|
functionaltest("shadowing")
|
|
functionaltest("mathops")
|
|
functionaltest("len")
|
|
functionaltest("not")
|
|
functionaltest("type")
|
|
functionaltest("if")
|
|
functionaltest("while")
|
|
functionaltest("eq")
|
|
functionaltest("chained-assignments")
|
|
functionaltest("dictionary-assignments")
|
|
functionaltest("variadic-functions")
|
|
functionaltest("predicate")
|
|
functionaltest("compare")
|
|
functionaltest("concat")
|
|
functionaltest("join")
|
|
functionaltest("quine")
|
|
|
|
install(TARGETS apfl DESTINATION lib)
|
|
install(TARGETS apfl-bin DESTINATION bin)
|
|
install(FILES apfl.h DESTINATION include)
|