-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
95 lines (73 loc) · 2.87 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
cmake_minimum_required(VERSION 3.20.0)
project(jcc VERSION 0.1.0)
set (CMAKE_CXX_STANDARD 23)
cmake_policy(SET CMP0069 NEW)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin)
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
include_directories(${LLVM_INCLUDE_DIRS})
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
add_definitions(${LLVM_DEFINITIONS_LIST})
add_subdirectory(jb)
add_library(jcc_lib OBJECT
${CMAKE_CURRENT_SOURCE_DIR}/src/compiler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/lexer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/parser.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/llvm_ir_gen.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/jb_ir_gen.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/platform.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/sema.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/common.cpp
)
target_include_directories(jcc_lib
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/lib
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/jb/include
)
set(cmd_driver_src
$<TARGET_OBJECTS:jb_lib>
$<TARGET_OBJECTS:jcc_lib>
${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp
)
add_executable(jcc ${cmd_driver_src})
target_include_directories(jcc
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/lib
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/jb/include
)
llvm_map_components_to_libnames(llvm_libs support core irreader native)
# llvm_map_components_to_libnames(llvm_libs all)
target_link_libraries(jcc ${llvm_libs})
set(test_driver_src
$<TARGET_OBJECTS:jb_lib>
$<TARGET_OBJECTS:jcc_lib>
${CMAKE_CURRENT_SOURCE_DIR}/tests/run_tests.cpp
)
add_executable(jcc_tests ${test_driver_src})
target_include_directories(jcc_tests
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/lib
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/jb/include
)
target_link_libraries(jcc_tests ${llvm_libs})
# if(${LTO})
# include(CheckIPOSupported)
# check_ipo_supported(RESULT result)
# if(result)
# set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
# endif()
# endif()
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
target_compile_options(jcc PRIVATE -Wall -Wextra -pedantic)
target_compile_options(jcc_tests PRIVATE -Wall -Wextra -pedantic)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
target_compile_options(jcc PRIVATE -Wall -Wextra -pedantic)
target_compile_options(jcc_tests PRIVATE -Wall -Wextra -pedantic)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
target_compile_options(jcc PRIVATE -Wall -Wextra -pedantic)
target_compile_options(jcc_tests PRIVATE -Wall -Wextra -pedantic)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
target_compile_options(jcc PRIVATE /W3 /wd4624)
target_compile_options(jcc_tests PRIVATE /W3 /wd4624)
endif()