xref: /aosp_15_r20/external/swiftshader/third_party/llvm-16.0/scripts/template_CMakeLists.txt (revision 03ce13f70fcc45d86ee91b7ee4cab1936a95046e)
1# Copyright 2023 The SwiftShader Authors. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#    http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15%$%generated_file_comment
16
17set(LLVM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/llvm)
18set(LLVM_CONFIG_DIR ${CMAKE_CURRENT_SOURCE_DIR}/configs)
19
20set(LLVM_LIST
21%$%files_llvm
22)
23
24if(ARCH STREQUAL "x86" OR ARCH STREQUAL "x86_64")
25    list(APPEND LLVM_LIST
26%$%files_x86
27    )
28elseif(ARCH STREQUAL "mipsel" OR ARCH STREQUAL "mips64el")
29    list(APPEND LLVM_LIST
30%$%files_Mips
31    )
32elseif(ARCH STREQUAL "aarch64")
33    list(APPEND LLVM_LIST
34%$%files_AArch64
35    )
36elseif(ARCH STREQUAL "arm")
37    list(APPEND LLVM_LIST
38%$%files_ARM
39    )
40elseif(ARCH STREQUAL "loongarch64")
41    list(APPEND LLVM_LIST
42%$%files_LoongArch
43    )
44elseif(ARCH STREQUAL "ppc64le")
45    list(APPEND LLVM_LIST
46%$%files_PowerPC
47    )
48elseif(ARCH STREQUAL "riscv64")
49    list(APPEND LLVM_LIST
50%$%files_RISCV
51    )
52endif()
53
54if(REACTOR_EMIT_DEBUG_INFO)
55    list(APPEND LLVM_LIST
56        ${LLVM_DIR}/lib/Demangle/ItaniumDemangle.cpp
57    )
58endif()
59
60set(LLVM_INCLUDE_DIR "")
61
62if(WIN32)
63    list(APPEND LLVM_INCLUDE_DIR ${LLVM_CONFIG_DIR}/windows/include)
64elseif(LINUX)
65    list(APPEND LLVM_INCLUDE_DIR ${LLVM_CONFIG_DIR}/linux/include)
66    list(APPEND LIBBACKTRACE_INCLUDE_DIR ${LIBBACKTRACE_CONFIG_DIR}/linux/include)
67elseif(APPLE)
68    list(APPEND LLVM_INCLUDE_DIR ${LLVM_CONFIG_DIR}/darwin/include)
69    list(APPEND LIBBACKTRACE_INCLUDE_DIR ${LIBBACKTRACE_CONFIG_DIR}/darwin/include)
70elseif(ANDROID)
71    list(APPEND LLVM_INCLUDE_DIR ${LLVM_CONFIG_DIR}/android/include)
72    list(APPEND LIBBACKTRACE_INCLUDE_DIR ${LIBBACKTRACE_CONFIG_DIR}/android/include)
73elseif(FUCHSIA)
74    list(APPEND LLVM_INCLUDE_DIR ${LLVM_CONFIG_DIR}/fuchsia/include)
75endif()
76
77list(APPEND LLVM_INCLUDE_DIR
78    ${LLVM_DIR}/include
79    ${LLVM_DIR}/lib/Target/AArch64
80    ${LLVM_DIR}/lib/Target/ARM
81    ${LLVM_DIR}/lib/Target/LoongArch
82    ${LLVM_DIR}/lib/Target/Mips
83    ${LLVM_DIR}/lib/Target/PowerPC
84    ${LLVM_DIR}/lib/Target/RISCV
85    ${LLVM_DIR}/lib/Target/X86
86    ${LLVM_CONFIG_DIR}/common/include
87    ${LLVM_CONFIG_DIR}/common/lib/IR
88    ${LLVM_CONFIG_DIR}/common/lib/Target/AArch64
89    ${LLVM_CONFIG_DIR}/common/lib/Target/ARM
90    ${LLVM_CONFIG_DIR}/common/lib/Target/LoongArch
91    ${LLVM_CONFIG_DIR}/common/lib/Target/Mips
92    ${LLVM_CONFIG_DIR}/common/lib/Target/PowerPC
93    ${LLVM_CONFIG_DIR}/common/lib/Target/RISCV
94    ${LLVM_CONFIG_DIR}/common/lib/Target/X86
95    ${LLVM_CONFIG_DIR}/common/lib/Transforms/InstCombine
96    ${LLVM_CONFIG_DIR}/common/lib/ExecutionEngine/JITLink
97)
98
99# Suppress known LLVM warnings
100set(LLVM_COMPILE_OPTIONS "")
101
102if(FUCHSIA)
103    list(APPEND LLVM_COMPILE_OPTIONS
104         "-Wno-cpp"   # Ignore #warning for unimplemented features in Process.inc.
105    )
106elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
107    list(APPEND LLVM_COMPILE_OPTIONS
108         "-Wno-deprecated-declarations"
109    )
110elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
111    list(APPEND LLVM_COMPILE_OPTIONS
112        "-Wno-noexcept-type"           # mangled name for ‘X’ will change in C++17 because the exception specification is part of a function type
113        "-Wno-maybe-uninitialized"     # ‘X’ may be used uninitialized in this function
114        "-Wno-deprecated-declarations"
115        "-Wno-missing-template-keyword"
116        "-Wno-missing-braces"
117    )
118    if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8)
119        list(APPEND LLVM_COMPILE_OPTIONS
120            "-Wno-class-memaccess"  # memset/memcmp used on non-trivial class object
121            "-Wno-attributes"	# declared inline but not inline
122        )
123    endif()
124    if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 9)
125        list(APPEND LLVM_COMPILE_OPTIONS
126            "-Wno-init-list-lifetime"  # assignment from temporary initializer_list does not extend the lifetime of the underlying array
127        )
128    endif()
129elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
130    list(APPEND LLVM_COMPILE_OPTIONS
131        "/wd4141" # 'inline': used more than once
132        "/wd4146" # unary minus operator applied to unsigned type, result still unsigned
133        "/wd4244" # 'X': conversion from 'uint64_t' to 'const unsigned int', possible loss of data
134        "/wd4267" # 'X': conversion from 'size_t' to 'unsigned int', possible loss of data
135        "/wd4291" # 'void X new(size_t,unsigned int,unsigned int)': no matching operator delete found; memory will not be freed if initialization throws an exception
136        "/wd4319" # 'X': zero extending 'unsigned int' to 'uint64_t' of greater size
137        "/wd4624" # 'X': destructor was implicitly defined as deleted
138        "/wd4805" # 'X': unsafe mix of type 'unsigned int' and type 'bool' in operation
139        "/wd4996" # 'X': Call to 'Y' with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct.
140    )
141endif()
142
143# Disable SIMD in Blake3
144list(APPEND LLVM_COMPILE_OPTIONS
145    "-DBLAKE3_NO_AVX512"
146    "-DBLAKE3_NO_AVX2"
147    "-DBLAKE3_NO_SSE41"
148    "-DBLAKE3_NO_SSE2"
149    "-DBLAKE3_USE_NEON=0"
150)
151
152add_library(llvm STATIC EXCLUDE_FROM_ALL ${LLVM_LIST})
153
154set_target_properties(llvm PROPERTIES
155    POSITION_INDEPENDENT_CODE 1
156)
157
158target_include_directories(llvm
159    PUBLIC
160        "${LLVM_INCLUDE_DIR}"
161)
162
163target_compile_options(llvm
164    PUBLIC
165        "${LLVM_COMPILE_OPTIONS}"
166)
167
168target_compile_definitions(llvm
169    PUBLIC
170        "__STDC_CONSTANT_MACROS"
171        "__STDC_LIMIT_MACROS"
172)
173
174# Add required libraries for LLVM
175if(LINUX OR APPLE)
176    target_link_libraries(llvm dl)
177endif()
178
179if(SWIFTSHADER_EMIT_COVERAGE)
180    # llvm-with-cov is an llvm target with additional coverage library
181    # functionality. This is used to build 'turbo-cov', a custom and faster
182    # reimplementation of llvm-cov.
183    add_library(llvm-with-cov STATIC EXCLUDE_FROM_ALL
184        ${LLVM_DIR}/lib/ProfileData/InstrProfReader.cpp
185        ${LLVM_DIR}/lib/ProfileData/ProfileSummaryBuilder.cpp
186        ${LLVM_DIR}/lib/ProfileData/Coverage/CoverageMapping.cpp
187        ${LLVM_DIR}/lib/ProfileData/Coverage/CoverageMappingReader.cpp
188        ${LLVM_DIR}/lib/Support/Compression.cpp
189    )
190    set_target_properties(llvm-with-cov PROPERTIES
191        POSITION_INDEPENDENT_CODE 1
192        FOLDER "LLVM"
193    )
194
195    target_include_directories(llvm-with-cov
196        PUBLIC
197            ${LLVM_INCLUDE_DIR}
198    )
199
200    target_compile_definitions(llvm-with-cov
201        PUBLIC
202            "__STDC_CONSTANT_MACROS"
203            "__STDC_LIMIT_MACROS"
204    )
205
206    if(LINUX OR APPLE)
207        target_link_libraries(llvm-with-cov llvm pthread)
208    endif()
209endif()
210