We'll soon need the full apfl_ctx, where we previously only needed the gc. apflc was the only place manually constructing a struct gc without an apfl_ctx, so lets change that.
144 lines
3.9 KiB
CMake
144 lines
3.9 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)
|
|
|
|
include(FindPkgConfig)
|
|
|
|
pkg_check_modules(PCRE2 REQUIRED libpcre2-8)
|
|
|
|
include_directories(${PCRE2_INCLUDE_DIRS})
|
|
set(commonfiles
|
|
alloc.c
|
|
bytecode.c
|
|
compile.c
|
|
context.c
|
|
encode.c
|
|
eval.c
|
|
error.c
|
|
expr.c
|
|
format.c
|
|
gc.c
|
|
hashmap.c
|
|
io.c
|
|
messages.c
|
|
modules.c
|
|
numparse.c
|
|
parser.c
|
|
position.c
|
|
registry.c
|
|
resizable.c
|
|
scope.c
|
|
source_readers.c
|
|
strings.c
|
|
symbols.c
|
|
token.c
|
|
tokenizer.c
|
|
value.c
|
|
)
|
|
|
|
add_library(apfl
|
|
${commonfiles}
|
|
globals.c
|
|
re.c
|
|
|
|
mod_globals.c
|
|
mod_re.c
|
|
)
|
|
target_link_libraries(apfl PUBLIC m)
|
|
target_link_libraries(apfl PUBLIC ${PCRE2_LIBRARIES})
|
|
|
|
add_executable(apfl-bin main.c)
|
|
target_link_libraries(apfl-bin PUBLIC apfl)
|
|
|
|
if(CMAKE_CROSSCOMPILING)
|
|
find_package(ApflApflcNative)
|
|
else()
|
|
add_executable(apflc apflc.c ${commonfiles} stubs_for_apflc.c)
|
|
target_link_libraries(apflc PUBLIC m)
|
|
export(TARGETS apflc FILE "${CMAKE_BINARY_DIR}/ApflApflcNativeConfig.cmake")
|
|
endif()
|
|
|
|
function(apfl_to_c apflfile cfile cfuncname)
|
|
add_custom_command(
|
|
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${cfile}"
|
|
COMMAND apflc -c ${cfuncname} "${CMAKE_CURRENT_SOURCE_DIR}/${apflfile}" "${CMAKE_CURRENT_BINARY_DIR}/${cfile}"
|
|
DEPENDS apflc "${CMAKE_CURRENT_SOURCE_DIR}/${apflfile}"
|
|
)
|
|
endfunction()
|
|
|
|
apfl_to_c(globals.apfl mod_globals.c apfl_mod_globals)
|
|
apfl_to_c(re.apfl mod_re.c apfl_mod_re)
|
|
|
|
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("loop")
|
|
functionaltest("while")
|
|
functionaltest("for")
|
|
functionaltest("keach")
|
|
functionaltest("each")
|
|
functionaltest("eq")
|
|
functionaltest("chained-assignments")
|
|
functionaltest("dictionary-assignments")
|
|
functionaltest("variadic-functions")
|
|
functionaltest("predicate")
|
|
functionaltest("compare")
|
|
functionaltest("concat")
|
|
functionaltest("join")
|
|
functionaltest("quine")
|
|
functionaltest("string-manip")
|
|
functionaltest("pairs")
|
|
functionaltest("symbols")
|
|
functionaltest("get-optional")
|
|
functionaltest("has-key")
|
|
functionaltest("tonumber")
|
|
functionaltest("re")
|
|
functionaltest("slice")
|
|
functionaltest("splice")
|
|
|
|
install(TARGETS apfl DESTINATION lib)
|
|
install(TARGETS apfl-bin DESTINATION bin)
|
|
install(FILES apfl.h DESTINATION include)
|