-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCMakeLists.txt
157 lines (128 loc) · 5.3 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(lc LANGUAGES C CXX)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release
CACHE STRING "Build type (Debug, Release)" FORCE)
endif ()
if (NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR
CMAKE_BUILD_TYPE STREQUAL "Release"))
message("${CMAKE_BUILD_TYPE}")
message(FATAL_ERROR "CMAKE_BUILD_TYPE must be one of: Debug, Release (current value: '${CMAKE_BUILD_TYPE}')")
endif ()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
# In Debug mode we enable assertions
set(WITH_LFORTRAN_ASSERT_DEFAULT yes)
else()
set(WITH_LFORTRAN_ASSERT_DEFAULT no)
endif()
# LFORTRAN_ASSERT
set(WITH_LFORTRAN_ASSERT ${WITH_LFORTRAN_ASSERT_DEFAULT}
CACHE BOOL "Enable LFORTRAN_ASSERT macro")
if (NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17
CACHE STRING "C++ standard" FORCE)
endif ()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# LLVM
set(WITH_LLVM no CACHE BOOL "Build with LLVM support")
set(WITH_TARGET_AARCH64 no CACHE BOOL "Enable target AARCH64")
set(WITH_TARGET_X86 no CACHE BOOL "Enable target X86")
set(WITH_TARGET_WASM no CACHE BOOL "Enable target WebAssembly")
if (WITH_LLVM)
set(LFORTRAN_LLVM_COMPONENTS core support mcjit orcjit native asmparser asmprinter)
find_package(LLVM REQUIRED)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
# Always enable the native target
if ("${LLVM_NATIVE_ARCH}" STREQUAL "AArch64")
set(WITH_TARGET_AARCH64 yes)
endif()
if ("${LLVM_NATIVE_ARCH}" STREQUAL "X86")
set(WITH_TARGET_X86 yes)
endif()
if (WITH_TARGET_AARCH64)
if (NOT ("${LLVM_TARGETS_TO_BUILD}" MATCHES "AArch64"))
message(FATAL_ERROR "The selected LLVM library doesn't have support for AArch64 targets")
endif()
list(APPEND LFORTRAN_LLVM_COMPONENTS aarch64info aarch64utils aarch64desc aarch64asmparser aarch64codegen aarch64disassembler)
add_definitions("-DHAVE_TARGET_AARCH64=1")
endif()
if (WITH_TARGET_X86)
if (NOT ("${LLVM_TARGETS_TO_BUILD}" MATCHES "X86"))
message(FATAL_ERROR "The selected LLVM library doesn't have support for X86 targets")
endif()
list(APPEND LFORTRAN_LLVM_COMPONENTS x86info x86desc x86codegen x86asmparser x86disassembler)
add_definitions("-DHAVE_TARGET_X86=1")
endif()
if (WITH_TARGET_WASM)
if (NOT ("${LLVM_TARGETS_TO_BUILD}" MATCHES "WebAssembly"))
message(FATAL_ERROR "The selected LLVM library doesn't have support for WebAssembly targets")
endif()
list(APPEND LFORTRAN_LLVM_COMPONENTS webassemblyasmparser webassemblycodegen webassemblydesc webassemblydisassembler webassemblyinfo)
add_definitions("-DHAVE_TARGET_WASM=1")
endif()
# Clang dependencies
list(APPEND LFORTRAN_LLVM_COMPONENTS windowsdriver)
llvm_map_components_to_libnames(llvm_libs ${LFORTRAN_LLVM_COMPONENTS})
unset(LFORTRAN_LLVM_COMPONENTS)
add_library(p::llvm INTERFACE IMPORTED)
set_property(TARGET p::llvm PROPERTY INTERFACE_INCLUDE_DIRECTORIES
${LLVM_INCLUDE_DIRS})
#set_property(TARGET p::llvm PROPERTY INTERFACE_COMPILE_DEFINITIONS
# ${LLVM_DEFINITIONS})
#set_property(TARGET p::llvm PROPERTY INTERFACE_COMPILE_OPTIONS
# ${LLVM_DEFINITIONS})
set_property(TARGET p::llvm PROPERTY INTERFACE_COMPILE_OPTIONS
$<$<COMPILE_LANGUAGE:CXX>:${LFORTRAN_CXX_NO_RTTI_FLAG}>)
set_property(TARGET p::llvm PROPERTY INTERFACE_LINK_LIBRARIES
${llvm_libs})
if (MSVC)
# LLVM on Windows appends zlib shared library and we must provide
# a path to find it:
get_filename_component(mypath ${ZLIB_LIBRARY} DIRECTORY)
target_link_directories(p::llvm BEFORE INTERFACE ${mypath})
message(STATUS "ZLIB LIBRARY PATH: ${mypath}")
endif()
set(HAVE_LFORTRAN_LLVM yes)
find_package(clang 15 REQUIRED)
add_library(p::clang INTERFACE IMPORTED)
set_property(TARGET p::clang PROPERTY INTERFACE_INCLUDE_DIRECTORIES
${CLANG_INCLUDE_DIRS})
set_property(TARGET p::clang PROPERTY INTERFACE_LINK_LIBRARIES
${CLANG_LIBRARIES})
endif()
set(WITH_WHEREAMI yes
CACHE BOOL "Include whereami.cpp")
set(WITH_MACHO no
CACHE BOOL "Build with mach-o support")
if (APPLE)
set(WITH_MACHO yes)
endif()
if (WITH_MACHO)
find_package(MACHO REQUIRED)
set(HAVE_LFORTRAN_MACHO yes)
endif()
if (WITH_WHEREAMI)
add_definitions("-DHAVE_WHEREAMI=1")
endif()
enable_testing()
message("\n")
message("Configuration results")
message("---------------------")
message("C compiler : ${CMAKE_C_COMPILER}")
message("C++ compiler : ${CMAKE_CXX_COMPILER}")
message("Build type: ${CMAKE_BUILD_TYPE}")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
message("C compiler flags : ${CMAKE_C_FLAGS_DEBUG}")
message("C++ compiler flags : ${CMAKE_CXX_FLAGS_DEBUG}")
else ()
message("C compiler flags : ${CMAKE_C_FLAGS_RELEASE}")
message("C++ compiler flags : ${CMAKE_CXX_FLAGS_RELEASE}")
endif ()
message("Installation prefix: ${CMAKE_INSTALL_PREFIX}")
message("WITH_LLVM: ${WITH_LLVM}")
message("WITH_TARGET_AARCH64: ${WITH_TARGET_AARCH64}")
message("WITH_TARGET_X86: ${WITH_TARGET_X86}")
message("WITH_TARGET_WASM: ${WITH_TARGET_WASM}")
add_subdirectory(src)