-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
112 lines (95 loc) · 3.23 KB
/
CMakeLists.txt
File metadata and controls
112 lines (95 loc) · 3.23 KB
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
cmake_minimum_required(VERSION 3.20)
project(Ola VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Build options
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(ENABLE_LLVM "Enable LLVM backend" ON)
option(BUILD_TESTS "Build tests" ON)
option(BUILD_PLAYGROUND "Build playground executable" ON)
option(ENABLE_ASAN "Enable AddressSanitizer" OFF)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(OLA_COMPILER_PATH ${CMAKE_CURRENT_SOURCE_DIR}/OlaCompiler/)
set(OLA_LIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/OlaLib/)
set(OLA_TESTS_PATH ${CMAKE_CURRENT_SOURCE_DIR}/OlaTests/)
set(OLA_PLAYGROUND_PATH ${CMAKE_CURRENT_SOURCE_DIR}/OlaPlayground/)
set(OLA_BINARY_PATH ${CMAKE_BINARY_DIR}/bin/)
# Platform-specific executable name
if(WIN32)
set(OLA_EXE_NAME "Ola.exe")
else()
set(OLA_EXE_NAME "Ola")
endif()
# Handle different generator types (multi-config vs single-config)
if(CMAKE_CONFIGURATION_TYPES)
message(STATUS "Multi-configuration generator detected")
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE)
else()
message(STATUS "Single-configuration generator detected")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build type (Debug or Release)" FORCE)
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
endif()
# MSVC-specific settings
if(MSVC)
add_compile_options(/MP) # Multi-processor compilation
add_definitions(/MT)
endif()
# AddressSanitizer support
if(ENABLE_ASAN)
if(MSVC)
add_compile_options(/fsanitize=address)
add_link_options(/fsanitize=address)
else()
add_compile_options(-fsanitize=address -fno-omit-frame-pointer -g)
add_link_options(-fsanitize=address)
endif()
add_compile_definitions(OLA_ENABLE_ASAN=1)
message(STATUS "AddressSanitizer enabled")
endif()
# Define DEBUG/RELEASE macros
add_compile_definitions(
"$<$<CONFIG:DEBUG>:DEBUG>"
"$<$<CONFIG:RELEASE>:RELEASE>"
)
# Add subdirectories
add_subdirectory(OlaLib)
# LLVM detection (must be before subdirectories so LLVM_FOUND is visible to all)
if(ENABLE_LLVM)
message(STATUS "LLVM backend is enabled, searching for LLVM...")
find_package(LLVM 17 QUIET CONFIG)
if(LLVM_FOUND)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "LLVM include dirs: ${LLVM_INCLUDE_DIRS}")
message(STATUS "LLVM library dirs: ${LLVM_LIBRARY_DIRS}")
else()
message(WARNING "LLVM backend was enabled, but LLVM 17 was not found! Disabling LLVM backend...")
endif()
else()
message(STATUS "LLVM backend is disabled.")
endif()
add_subdirectory(OlaCompiler)
if(BUILD_TESTS)
add_subdirectory(OlaTests)
endif()
if(BUILD_PLAYGROUND)
add_subdirectory(OlaPlayground)
endif()
# Set up dependencies
add_dependencies(OlaCompiler OlaLib)
add_dependencies(OlaDriver OlaCompiler)
if(BUILD_TESTS)
add_dependencies(OlaTests OlaDriver)
add_dependencies(OlaTestsE2E OlaDriver)
add_dependencies(OlaTestsInterpreter OlaDriver)
if(LLVM_FOUND)
add_dependencies(OlaTestsLLVM OlaDriver)
endif()
endif()
if(BUILD_PLAYGROUND)
add_dependencies(OlaPlayground OlaCompiler)
endif()