Skip to content

Commit 7f71455

Browse files
committed
Modern CMake
1 parent fee71db commit 7f71455

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

flang-rt/cmake/modules/AddFlangRT.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,28 @@ function (add_flangrt_library name)
225225
# Minimum required C++ version for Flang-RT, even if CMAKE_CXX_STANDARD is defined to something else.
226226
target_compile_features(${tgtname} PRIVATE cxx_std_17)
227227

228+
target_compile_options(${tgtname} PRIVATE
229+
# Always enable preprocessor regardless of file extention
230+
"$<$<COMPILE_LANGUAGE:Fortran>:-cpp>"
231+
232+
# Missing type descriptors are expected for intrinsic modules
233+
"$<$<COMPILE_LANGUAGE:Fortran>:SHELL:-mmlir;SHELL:-ignore-missing-type-desc>"
234+
235+
# Flang bug workaround: Reformating of cooked token buffer causes identifier to be split between lines
236+
"$<$<COMPILE_LANGUAGE:Fortran>:SHELL:-Xflang;SHELL:-fno-reformat>"
237+
)
238+
228239
# When building the flang runtime if LTO is enabled the archive file
229240
# contains LLVM IR rather than object code. Currently flang is not
230241
# LTO aware so cannot link this file to compiled Fortran code.
231242
if (FLANG_RT_HAS_FNO_LTO_FLAG)
232243
target_compile_options(${tgtname} PRIVATE -fno-lto)
233244
endif ()
234245

246+
if (FORTRAN_SUPPORTS_REAL16)
247+
target_compile_definitions(${tgtname} PRIVATE FLANG_SUPPORT_R16=1)
248+
endif ()
249+
235250
# Use compiler-specific options to disable exceptions and RTTI.
236251
if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
237252
target_compile_options(${tgtname} PRIVATE

flang-rt/lib/runtime/CMakeLists.txt

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,22 @@ if (LLVM_TARGET_TRIPLE MATCHES "^ppc|^powerpc")
113113
)
114114
endif ()
115115

116-
list(APPEND host_sources
117-
__cuda_device.f90
118-
cooperative_groups.f90
119-
cudadevice.f90
120-
)
121-
122-
# Compile as CUDA-Fortran, not directly supported by CMake
123-
set_property(SOURCE
116+
if (FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "CUDA")
117+
list(APPEND host_sources
124118
__cuda_device.f90
125119
cooperative_groups.f90
126120
cudadevice.f90
127-
APPEND PROPERTY
128-
COMPILE_OPTIONS --offload-host-only -xcuda
129-
)
121+
)
122+
123+
# Compile as CUDA-Fortran, not directly supported by CMake
124+
set_property(SOURCE
125+
__cuda_device.f90
126+
cooperative_groups.f90
127+
cudadevice.f90
128+
APPEND PROPERTY
129+
COMPILE_OPTIONS --offload-host-only -xcuda
130+
)
131+
endif ()
130132

131133
# Sources that can be compiled directly for the GPU.
132134
set(gpu_sources
@@ -215,26 +217,11 @@ endif ()
215217

216218
if (LLVM_RUNTIMES_TARGET MATCHES "^amdgcn|^nvptx")
217219
set(sources ${gpu_sources})
218-
elseif(FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT STREQUAL "CUDA")
219-
set(sources ${supported_sources} ${host_sources})
220220
else ()
221221
set(sources ${supported_sources} ${host_sources} ${f128_sources})
222222
endif ()
223223

224224

225-
if (FORTRAN_SUPPORTS_REAL16)
226-
add_compile_definitions(FLANG_SUPPORT_R16=1)
227-
add_compile_options("$<$<COMPILE_LANGUAGE:Fortran>:-cpp>")
228-
endif ()
229-
230-
add_compile_options(
231-
"$<$<COMPILE_LANGUAGE:Fortran>:SHELL:-mmlir;SHELL:-ignore-missing-type-desc>"
232-
233-
# Flang bug workaround: Reformating of cooked token buffer causes identifier to be split between lines
234-
"$<$<COMPILE_LANGUAGE:Fortran>:SHELL:-Xflang;SHELL:-fno-reformat>"
235-
)
236-
237-
238225
# check-flang depends on this to build intrinsic modules
239226
if (NOT TARGET flang-rt-mod)
240227
add_custom_target(flang-rt-mod)

0 commit comments

Comments
 (0)