-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
82 lines (66 loc) · 3.35 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
cmake_minimum_required(VERSION 3.4.3)
project(mila)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# You can always add more flags without hardcoding them here using the following pattern
# $ CXXFLAGS='-g -fsanitize=address -fsanitize=undefined' cmake <source_dir>
set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic ${CMAKE_CXX_FLAGS}")
# Change this to force specific version of LLVM
# find_package(LLVM "${MAJOR}.${MINOR}" REQUIRED CONFIG)
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/)
add_executable(
mila
compiler/main.cpp
compiler/lexer/lexer.hpp compiler/lexer/lexer.cpp
compiler/parser/parser.hpp compiler/parser/parser.cpp compiler/parser/descent.hpp compiler/parser/descent.cpp
compiler/ast/ast.hpp compiler/ast/ast.cpp compiler/ast/ast_gen.cpp compiler/ast/ast_print.cpp
)
target_include_directories(mila PRIVATE ${LLVM_INCLUDE_DIRS})
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
target_compile_options(mila PRIVATE ${LLVM_DEFINITIONS_LIST})
# Find the libraries that correspond to the LLVM components that we wish to use and link against them
# https://github.com/llvm/llvm-project/issues/34593
# llvm_map_components_to_libnames(llvm_libs support core irreader)
# target_link_libraries(mila ${llvm_libs})
llvm_config(mila USE_SHARED support core irreader)
include(CTest)
if (BUILD_TESTING)
file(GLOB_RECURSE MILA_SOURCES LIST_DIRECTORIES false CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/samples/*.mila")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/tests")
# compile tests
foreach(src ${MILA_SOURCES})
get_filename_component(basename ${src} NAME_WE)
add_test(NAME "compiler:${basename}" COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/mila" "${src}" "-o" "${CMAKE_CURRENT_BINARY_DIR}/tests/${basename}")
set_tests_properties("compiler:${basename}" PROPERTIES FIXTURES_SETUP "${basename}")
endforeach()
# run tests
file(GLOB MILA_OUTPUTS LIST_DIRECTORIES false CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/tests/run/*.run[0-9]*.out")
foreach(out ${MILA_OUTPUTS})
get_filename_component(outname ${out} NAME)
get_filename_component(extensionOut ${out} EXT)
get_filename_component(basename ${out} NAME_WE)
string(REPLACE "out" "in" extensionIn "${extensionOut}")
set(inname "${basename}${extensionIn}")
set(executable ${CMAKE_CURRENT_BINARY_DIR}/tests/${basename})
set(outfile ${CMAKE_CURRENT_SOURCE_DIR}/tests/run/${outname})
set(infile ${CMAKE_CURRENT_SOURCE_DIR}/tests/run/${inname})
if(EXISTS "${infile}")
add_test(NAME "run:${outname}" COMMAND
${CMAKE_COMMAND}
-D executable=${executable}
-D expected=${outfile}
-D input=${infile}
-P ${CMAKE_CURRENT_SOURCE_DIR}/tests/run_test.cmake)
else()
add_test(NAME "run:${outname}" COMMAND
${CMAKE_COMMAND}
-D executable=${executable}
-D expected=${outfile}
-P ${CMAKE_CURRENT_SOURCE_DIR}/tests/run_test.cmake)
endif()
set_tests_properties("run:${outname}" PROPERTIES FIXTURES_REQUIRED "${basename}")
endforeach()
endif()