-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
118 lines (93 loc) · 4.54 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
cmake_minimum_required(VERSION 3.22.1)
include(CMakeDependentOption)
option(ENABLE_LOGGING "Enable logging support" ON)
option(ENABLE_STACKTRACE "Enable stacktrace support" ON)
option(ENABLE_TESTS "Enable tests" ON)
option(ENABLE_BENCHMARKS "Enables tracing and backend benchmarks" OFF)
option(ENABLE_COMPILER "Enables tracing and backend compilers" ON)
option(USE_EXTERNAL_FMT "Use a externally provided version of fmt" OFF)
option(USE_EXTERNAL_SPDLOG "Use a externally provided version of spdlog" OFF)
option(USE_EXTERNAL_MLIR "Use a externally provided version of MLIR" OFF)
cmake_dependent_option(ENABLE_TRACING "Enable the tracing" ON "ENABLE_COMPILER" OFF)
cmake_dependent_option(ENABLE_MLIR_BACKEND "Enable the MLIR compiler backend" ON "ENABLE_COMPILER" OFF)
cmake_dependent_option(NAUTILUS_DOWNLOAD_MLIR "USE_PRE_BUILD_MLIR" ON "ENABLE_MLIR_BACKEND;NOT USE_EXTERNAL_MLIR" OFF)
cmake_dependent_option(ENABLE_C_BACKEND "Enable the C compiler backend" ON "ENABLE_COMPILER" OFF)
cmake_dependent_option(ENABLE_BC_BACKEND "Enable the bytecode interpreter backend" ON "ENABLE_COMPILER" OFF)
cmake_dependent_option(ENABLE_ASMJIT_BACKEND "Enable the asmjit interpreter backend" OFF "ENABLE_COMPILER" OFF)
option(ENABLE_TEST_COVERAGE "Enable the collection of test coverage." OFF)
option(ENABLE_ADDRESS_SANITIZER "Enable address sanitizer." OFF)
option(ENABLE_THREAD_SANITIZER "Enable thread sanitizer." OFF)
option(ENABLE_UB_SANITIZER "Enable undefined behavior sanitizer." OFF)
project(nautilus VERSION 0.1)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_WARNINGS "-Wall -Wextra -pedantic-errors -Werror=extra-semi -Werror=extra -Werror=all -Werror=delete-non-virtual-dtor -Werror=deprecated -Werror=array-bounds -Werror=ignored-qualifiers -Werror=sign-compare")
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_WARNINGS "${CMAKE_CXX_WARNINGS} -Wpedantic-macros -Werror=integer-overflow -Werror=return-type -Werror=return-stack-address -Werror=writable-strings")
else ()
set(CMAKE_CXX_WARNINGS "${CMAKE_CXX_WARNINGS} -Woverflow -Werror=return-type -Werror=return-local-addr -Werror=write-strings")
endif ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_WARNINGS} -fpermissive -fno-omit-frame-pointer")
if (ENABLE_TEST_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcoverage-mapping -fprofile-instr-generate")
endif ()
if (ENABLE_SANITIZER)
add_link_options(-fsanitize=address)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
elseif (ENABLE_THREAD_SANITIZER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
elseif (ENABLE_UB_SANITIZER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined -fno-sanitize-recover=all")
elseif (ENABLE_LEAK_SANITIZER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=leak")
endif ()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_DEBUG} -O3")
include(cmake/macros.cmake)
set(THIRD_PARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party)
if (ENABLE_MLIR_BACKEND AND NOT USE_EXTERNAL_MLIR)
include(cmake/ImportMLIR.cmake)
endif ()
set(EXPORT_TARGETS)
if (ENABLE_TESTS OR ENABLE_BENCHMARKS)
set(CATCH_ENABLE_REPRODUCIBLE_BUILD OFF CACHE INTERNAL "Turn off tests")
add_subdirectory(${THIRD_PARTY_DIR}/Catch2)
list(APPEND EXPORT_TARGETS Catch2)
endif ()
if (USE_EXTERNAL_FMT)
find_package(fmt CONFIG REQUIRED)
else ()
add_subdirectory(${THIRD_PARTY_DIR}/fmt EXCLUDE_FROM_ALL)
disable_target_warnings(fmt)
list(APPEND EXPORT_TARGETS fmt)
endif ()
if (ENABLE_LOGGING)
if (USE_EXTERNAL_SPDLOG)
find_package(spdlog CONFIG REQUIRED)
else ()
set(SPDLOG_COMPILED_LIB ON)
set(SPDLOG_BUILD_SHARED OFF)
set(SPDLOG_FMT_EXTERNAL ON)
add_subdirectory(${THIRD_PARTY_DIR}/spdlog)
list(APPEND EXPORT_TARGETS spdlog)
endif ()
endif ()
if (ENABLE_STACKTRACE)
# Also requires one of: libbfd (gnu binutils), libdwarf, libdw (elfutils)
add_subdirectory(${THIRD_PARTY_DIR}/backward-cpp)
list(APPEND EXPORT_TARGETS backward_interface)
endif ()
if (ENABLE_BC_BACKEND)
add_subdirectory(${THIRD_PARTY_DIR}/dyncall)
list(APPEND EXPORT_TARGETS dyncall_s)
endif ()
if (ENABLE_ASMJIT_BACKEND)
set(ASMJIT_STATIC ON)
set(ASMJIT_BUILD_RELEASE ON)
set(ASMJIT_NO_FOREIGN ON)
set(ASMJIT_NO_DEPRECATED ON)
add_subdirectory(${THIRD_PARTY_DIR}/asmjit)
target_compile_options(asmjit PUBLIC -Wno-deprecated-anon-enum-enum-conversion -Wno-nested-anon-types -Wno-gnu-anonymous-struct)
endif ()
add_subdirectory(nautilus)
add_make_format()