mirror-llvm-project/openmp
Michael Kruse c1869ffacf
[flang-rt][CMake] Avoid 'use, intrinsic ::' (#205634)
Two build failures reported after #204260

* Unix Makefiles generator stops working: The cause is that the rules
for building each OBJECT library lands in its own Makefile, e.g.
`flang_rt.mod.fortran.builtins.dir/build.make` and
`libomp-mod.dir/build.make`. Trying to inject dependencies directly for
build rules in the other file does not work.

* `__ppc_types.f90` not tracked: Forgotten in #204260 due to being only
conditionally enabled for PowerPC targets.

The solution for both is to just remove the workaround for CMake not
recognizing modules uses declared using `intrinsic` which caused these
problems. This PR promotes the `use` constructs in the module sources to
normal dependencies that are not ignored by CMake.

The `intrinsic` modifier changes the search path to only look for such a
module in `-fintrinsic-modules-path`. The difference is only
theoretical:
1. When compiling the intrinsic modules, there are no other search paths
than for the intrinsics anyway
2. Users should strongly avoid naming their modules the same as an
intrinsic module
3. Most of our intrinsic sources don't even use the `intrinsic` modifier
in the first place (e.g.
1c9412432f/flang-rt/lib/runtime/__cuda_builtins.f90 (L13)).
That is, if there was a problem with lookup ambiguity, these would have
already been a problem for those.
4. The checksum of used modules is only added into the .mod file (the
only reason why modules would need to be transitively rebuilt) when a
`use` statement appears. Many intrinsic modules don't explicitly use the
modules that are added implicitly by the compiler, such as
`__fortran_builtins`, and hence do not even need to be rebuilt.

I started this PR with a tested-working fix
([71c5e7f0ffcf2ebd58812d2e2812b22663be1631](https://github.com/llvm/llvm-project/pull/205634/changes/BASE..71c5e7f0ffcf2ebd58812d2e2812b22663be1631))
to the workaround code. But given the points above, there seems to be no
benefit of keeping the workaround code handling CMake version < 4.5
around just for some intrinsic modules to keep the `intrinsic` modifier
with no practical effect. A non-workaround path using CMake's
`Fortran_BUILDING_IN(S)TRINSIC_MODULES` setting had to be added in any
case for Unix Makefile generators (reported issue 1.) because injecting
dependencies is not possible with Unix Makefiles as stated, but
`Fortran_BUILDING_IN(S)TRINSIC_MODULES` also does not work with the
Ninja generator. Avoiding `use, intrinsic` keeps just one configuration
path.

I tested that modules are properly updated with Ninja and Unix
Makefiles:
 * Build from scratch
 * Modifying `__fortran_builtins.f90` rebuilds its dependent modules
 * Modifying `iso_c_binding.f90` rebuilds its dependent modules
(omp_lib.mod)
2026-06-25 16:50:13 +02:00
..
cmake [Flang] Move builtin .mod generation into runtimes (Reapply #137828) (#171515) 2026-05-29 10:50:52 +02:00
device Reapply "[OpenMP][offload] Cross-team reductions with variable number of teams" (#204914) (#205071) 2026-06-22 17:40:45 +02:00
docs [docs] Create utils/docs (#203962) 2026-06-24 15:12:48 -04:00
libompd [OpenMP] Fix missing install-openmp component (#197603) 2026-05-15 07:37:18 -05:00
module [flang-rt][CMake] Avoid 'use, intrinsic ::' (#205634) 2026-06-25 16:50:13 +02:00
runtime [OpenMP] Control KMP_CANCEL_THREADS via CMake and detect pthread_cancel (#193681) 2026-06-19 00:04:01 +08:00
tools [openmp][omptest] Include cstdlib for malloc() (#202021) 2026-06-06 10:46:45 +01:00
.gitignore
CMakeLists.txt [Flang] Move builtin .mod generation into runtimes (Reapply #137828) (#171515) 2026-05-29 10:50:52 +02:00
CREDITS.txt
LICENSE.TXT
Maintainers.md Nominate Michael Klemm as lead maintainer of OpenMP (#175964) 2026-01-14 15:17:26 +00:00