[clangd] Fix erroneous qualification of template type parameters (#116821)
[llvm-project.git] / flang / runtime / CMakeLists.txt
blobcdd2de541c6730b66779c659918b2b098c697d48
1 #===-- runtime/CMakeLists.txt ----------------------------------------------===#
3 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 # See https://llvm.org/LICENSE.txt for license information.
5 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 #===------------------------------------------------------------------------===#
9 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
10   cmake_minimum_required(VERSION 3.20.0)
12   project(FlangRuntime C CXX)
14   set(CMAKE_CXX_STANDARD 17)
15   set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
16   set(CMAKE_CXX_EXTENSIONS OFF)
18   set(FLANG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..")
20   set(LLVM_COMMON_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../cmake")
21   set(LLVM_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../llvm/cmake")
22   set(CLANG_CMAKE_UTILS "${FLANG_SOURCE_DIR}/../clang/cmake")
24   # Add path for custom modules
25   list(INSERT CMAKE_MODULE_PATH 0
26     "${FLANG_SOURCE_DIR}/cmake"
27     "${FLANG_SOURCE_DIR}/cmake/modules"
28     "${LLVM_COMMON_CMAKE_UTILS}"
29     "${LLVM_COMMON_CMAKE_UTILS}/Modules"
30     "${LLVM_CMAKE_UTILS}"
31     "${LLVM_CMAKE_UTILS}/modules"
32     "${CLANG_CMAKE_UTILS}/modules"
33     )
35   include(AddClang)
36   include(AddLLVM)
37   include(AddFlang)
38   include(HandleLLVMOptions)
40   include(TestBigEndian)
41   test_big_endian(IS_BIGENDIAN)
42   if (IS_BIGENDIAN)
43     add_compile_definitions(FLANG_BIG_ENDIAN=1)
44   else ()
45     add_compile_definitions(FLANG_LITTLE_ENDIAN=1)
46   endif ()
47   include_directories(BEFORE
48     ${FLANG_SOURCE_DIR}/include)
50   # The out of tree builds of the compiler and the Fortran runtime
51   # must use the same setting of FLANG_RUNTIME_F128_MATH_LIB
52   # to be composable. Failure to synchronize this setting may result
53   # in linking errors or fatal failures in F128 runtime functions.
54   set(FLANG_RUNTIME_F128_MATH_LIB "" CACHE STRING
55     "Specifies the target library used for implementing IEEE-754 128-bit float \
56     math in F18 runtime, e.g. it might be libquadmath for targets where \
57     REAL(16) is mapped to __float128, or libm for targets where REAL(16) \
58     is mapped to long double, etc."
59     )
60 endif()
62 include(CheckCXXSymbolExists)
63 include(CheckCXXSourceCompiles)
64 check_cxx_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
65 # Can't use symbol exists here as the function is overloaded in C++
66 check_cxx_source_compiles(
67   "#include <string.h>
68    int main() {
69      char buf[4096];
70      return strerror_s(buf, 4096, 0);
71    }
72   "
73   HAVE_DECL_STRERROR_S)
75 # Check if 128-bit float computations can be done via long double.
76 check_cxx_source_compiles(
77   "#include <cfloat>
78    #if LDBL_MANT_DIG != 113
79    #error LDBL_MANT_DIG != 113
80    #endif
81    int main() { return 0; }
82   "
83   HAVE_LDBL_MANT_DIG_113)
85 check_cxx_compiler_flag(-fno-lto FLANG_RUNTIME_HAS_FNO_LTO_FLAG)
86 if (FLANG_RUNTIME_HAS_FNO_LTO_FLAG)
87   set(NO_LTO_FLAGS "-fno-lto")
88 else()
89   set(NO_LTO_FLAGS "")
90 endif()
92 configure_file(config.h.cmake config.h)
93 # include_directories is used here instead of target_include_directories
94 # because add_flang_library creates multiple objects (STATIC/SHARED, OBJECT)
95 # with different names
96 include_directories(AFTER ${CMAKE_CURRENT_BINARY_DIR})
98 append(${NO_LTO_FLAGS} CMAKE_C_FLAGS)
99 append(${NO_LTO_FLAGS} CMAKE_CXX_FLAGS)
101 # Disable libstdc++/libc++ assertions, even in an LLVM_ENABLE_ASSERTIONS build,
102 # to avoid an unwanted dependency on libstdc++/libc++.so.
103 add_definitions(-U_GLIBCXX_ASSERTIONS)
104 add_definitions(-U_LIBCPP_ENABLE_ASSERTIONS)
106 add_subdirectory(Float128Math)
108 set(sources
109   ISO_Fortran_binding.cpp
110   allocator-registry.cpp
111   allocatable.cpp
112   array-constructor.cpp
113   assign.cpp
114   buffer.cpp
115   character.cpp
116   command.cpp
117   complex-powi.cpp
118   complex-reduction.c
119   connection.cpp
120   copy.cpp
121   derived-api.cpp
122   derived.cpp
123   descriptor-io.cpp
124   descriptor.cpp
125   dot-product.cpp
126   edit-input.cpp
127   edit-output.cpp
128   environment.cpp
129   exceptions.cpp
130   execute.cpp
131   extensions.cpp
132   external-unit.cpp
133   extrema.cpp
134   file.cpp
135   findloc.cpp
136   format.cpp
137   inquiry.cpp
138   internal-unit.cpp
139   io-api.cpp
140   io-api-minimal.cpp
141   io-error.cpp
142   io-stmt.cpp
143   iostat.cpp
144   main.cpp
145   matmul-transpose.cpp
146   matmul.cpp
147   memory.cpp
148   misc-intrinsic.cpp
149   namelist.cpp
150   non-tbp-dio.cpp
151   numeric.cpp
152   pointer.cpp
153   product.cpp
154   pseudo-unit.cpp
155   ragged.cpp
156   random.cpp
157   reduce.cpp
158   reduction.cpp
159   stat.cpp
160   stop.cpp
161   sum.cpp
162   support.cpp
163   temporary-stack.cpp
164   terminator.cpp
165   time-intrinsic.cpp
166   tools.cpp
167   transformational.cpp
168   type-code.cpp
169   type-info.cpp
170   unit-map.cpp
171   unit.cpp
172   utf.cpp
173   ${FORTRAN_MODULE_OBJECTS}
176 include(AddFlangOffloadRuntime)
178 # List of files that are buildable for all devices.
179 set(supported_files
180   ISO_Fortran_binding.cpp
181   allocatable.cpp
182   allocator-registry.cpp
183   array-constructor.cpp
184   assign.cpp
185   buffer.cpp
186   character.cpp
187   connection.cpp
188   copy.cpp
189   derived-api.cpp
190   derived.cpp
191   descriptor.cpp
192   descriptor-io.cpp
193   dot-product.cpp
194   edit-input.cpp
195   edit-output.cpp
196   environment.cpp
197   extrema.cpp
198   external-unit.cpp
199   file.cpp
200   findloc.cpp
201   format.cpp
202   inquiry.cpp
203   internal-unit.cpp
204   io-api.cpp
205   io-api-minimal.cpp
206   io-error.cpp
207   io-stmt.cpp
208   iostat.cpp
209   matmul-transpose.cpp
210   matmul.cpp
211   memory.cpp
212   misc-intrinsic.cpp
213   namelist.cpp
214   non-tbp-dio.cpp
215   numeric.cpp
216   pointer.cpp
217   product.cpp
218   pseudo-unit.cpp
219   ragged.cpp
220   stat.cpp
221   sum.cpp
222   support.cpp
223   terminator.cpp
224   tools.cpp
225   transformational.cpp
226   type-code.cpp
227   type-info.cpp
228   unit.cpp
229   utf.cpp
230   )
232 enable_cuda_compilation(FortranRuntime "${supported_files}")
233 enable_omp_offload_compilation("${supported_files}")
235 if (NOT TARGET FortranFloat128Math)
236   # If FortranFloat128Math is not defined, then we are not building
237   # standalone FortranFloat128Math library. Instead, include
238   # the relevant sources into FortranRuntime itself.
239   # The information is provided via FortranFloat128MathILib
240   # interface library.
241   get_target_property(f128_sources
242     FortranFloat128MathILib INTERFACE_SOURCES
243     )
244   if (f128_sources)
245     # The interface may define special macros for Float128Math files,
246     # so we need to propagate them.
247     get_target_property(f128_defs
248       FortranFloat128MathILib INTERFACE_COMPILE_DEFINITIONS
249       )
250     set_property(SOURCE ${f128_sources}
251       APPEND PROPERTY COMPILE_DEFINITIONS
252       ${f128_defs}
253       )
254     get_target_property(f128_include_dirs
255       FortranFloat128MathILib INTERFACE_INCLUDE_DIRECTORIES
256       )
257     set_property(SOURCE ${f128_sources}
258       APPEND PROPERTY INCLUDE_DIRECTORIES
259       ${f128_include_dirs}
260       )
261     list(APPEND sources ${f128_sources})
262   endif()
263 endif()
265 if (NOT DEFINED MSVC)
266   add_flang_library(FortranRuntime
267     ${sources}
268     LINK_LIBS
269     FortranDecimal
271     INSTALL_WITH_TOOLCHAIN
272   )
273 else()
274   add_flang_library(FortranRuntime
275     ${sources}
276     LINK_LIBS
277     FortranDecimal
278   )
279   set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
280   add_flang_library(FortranRuntime.static ${sources}
281     LINK_LIBS
282     FortranDecimal.static
283     INSTALL_WITH_TOOLCHAIN)
284   set_target_properties(FortranRuntime.static PROPERTIES FOLDER "Flang/Runtime Libraries")
285   set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
286   add_flang_library(FortranRuntime.dynamic ${sources}
287     LINK_LIBS
288     FortranDecimal.dynamic
289     INSTALL_WITH_TOOLCHAIN)
290   set_target_properties(FortranRuntime.dynamic PROPERTIES FOLDER "Flang/Runtime Libraries")
291   set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebug)
292   add_flang_library(FortranRuntime.static_dbg ${sources}
293     LINK_LIBS
294     FortranDecimal.static_dbg
295     INSTALL_WITH_TOOLCHAIN)
296   set_target_properties(FortranRuntime.static_dbg PROPERTIES FOLDER "Flang/Runtime Libraries")
297   set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreadedDebugDLL)
298   add_flang_library(FortranRuntime.dynamic_dbg ${sources}
299     LINK_LIBS
300     FortranDecimal.dynamic_dbg
301     INSTALL_WITH_TOOLCHAIN)
302   set_target_properties(FortranRuntime.dynamic_dbg PROPERTIES FOLDER "Flang/Runtime Libraries")
303   add_dependencies(FortranRuntime FortranRuntime.static FortranRuntime.dynamic
304     FortranRuntime.static_dbg FortranRuntime.dynamic_dbg)
305 endif()
306 set_target_properties(FortranRuntime PROPERTIES FOLDER "Flang/Runtime Libraries")
308 # If FortranRuntime is part of a Flang build (and not a separate build) then
309 # add dependency to make sure that Fortran runtime library is being built after
310 # we have the Flang compiler available.  This also includes the MODULE files
311 # that compile when the 'flang' target is built.
313 # TODO: This is a workaround and should be updated when runtime build procedure
314 # is changed to a regular runtime build.  See discussion in PR #95388.
315 if (TARGET flang AND TARGET module_files)
316   add_dependencies(FortranRuntime flang module_files)
317 endif()
319 if (FLANG_CUF_RUNTIME)
320   add_subdirectory(CUDA)
321 endif()