apfl/src/CMakeLists.txt

145 lines
3.9 KiB
Text
Raw Normal View History

2022-09-16 21:04:20 +00:00
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_EXTENSIONS OFF)
2023-02-10 20:39:51 +00:00
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
2022-09-16 21:04:20 +00:00
alloc.c
bytecode.c
compile.c
context.c
2023-03-05 16:02:42 +00:00
encode.c
eval.c
2022-09-16 21:04:20 +00:00
error.c
expr.c
format.c
gc.c
hashmap.c
2023-03-05 16:02:42 +00:00
io.c
2022-09-16 21:04:20 +00:00
messages.c
modules.c
2023-07-03 21:33:19 +00:00
numparse.c
2022-09-16 21:04:20 +00:00
parser.c
position.c
registry.c
2022-09-16 21:04:20 +00:00
resizable.c
scope.c
2022-09-16 21:04:20 +00:00
source_readers.c
strings.c
symbols.c
2022-09-16 21:04:20 +00:00
token.c
tokenizer.c
value.c
)
add_library(apfl
${commonfiles}
globals.c
re.c
mod_globals.c
mod_re.c
)
2023-03-05 16:02:42 +00:00
target_link_libraries(apfl PUBLIC m)
target_link_libraries(apfl PUBLIC ${PCRE2_LIBRARIES})
2023-03-05 16:02:42 +00:00
2022-09-16 21:04:20 +00:00
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)
2022-09-16 21:04:20 +00:00
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()
2022-09-16 21:04:20 +00:00
endfunction()
unittest(tokenizer_test "")
unittest(parser_test "")
unittest(resizable_test "resizable.h")
unittest(hashmap_test "hashmap.h")
unittest(strings_test "")
unittest(alloc_test "")
2023-03-05 16:02:42 +00:00
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")
2022-10-30 22:07:53 +00:00
functionaltest("factorial")
functionaltest("function-const-capture")
functionaltest("function-mutable-capture")
functionaltest("map")
functionaltest("deconstruct")
functionaltest("shadowing")
functionaltest("mathops")
functionaltest("len")
functionaltest("not")
functionaltest("type")
2022-10-31 14:50:51 +00:00
functionaltest("if")
2023-03-07 20:37:37 +00:00
functionaltest("loop")
2022-10-31 14:51:56 +00:00
functionaltest("while")
2023-03-07 20:37:37 +00:00
functionaltest("for")
functionaltest("keach")
functionaltest("each")
2022-11-04 20:51:31 +00:00
functionaltest("eq")
2022-11-19 20:27:08 +00:00
functionaltest("chained-assignments")
functionaltest("dictionary-assignments")
functionaltest("variadic-functions")
functionaltest("predicate")
2022-11-20 12:47:38 +00:00
functionaltest("compare")
functionaltest("concat")
functionaltest("join")
2023-03-03 21:25:25 +00:00
functionaltest("quine")
functionaltest("string-manip")
functionaltest("pairs")
2023-03-23 22:38:35 +00:00
functionaltest("symbols")
functionaltest("get-optional")
functionaltest("has-key")
2023-07-03 21:33:19 +00:00
functionaltest("tonumber")
functionaltest("re")
functionaltest("slice")
functionaltest("splice")
2022-09-16 21:04:20 +00:00
install(TARGETS apfl DESTINATION lib)
install(TARGETS apfl-bin DESTINATION bin)
install(FILES apfl.h DESTINATION include)