[flang-dev] Flang + CMake

Andrzej Warzynski via flang-dev flang-dev at lists.llvm.org
Thu Jul 1 06:19:28 PDT 2021


These upper-case predefinitions were added to CMake long before LLVM 
Flang [1]. I think that it is safe to assume that they were meant for 
"classic Flang" rather than LLVM Flang.

`__flang__`, `__flang_major__`, `__flang_minor__` and 
`__flang_patchlevel__` are defined by the driver rather then the 
preprocessor. These pre-definitions are consistent with Clang.

@Nick, thank you for sending that link! It looks like a non-trivial 
amount of effort. I wonder whether there are any low hanging fruits for us?

@Michael, clearly LLVM Flang and CMake are currently out-of-sync and I 
guess that we should be pro-active about these things? Btw, I authored 
[3] :)

-Andrzej

[1] https://gitlab.kitware.com/cmake/cmake/-/merge_requests/1141

On 30/06/2021 18:56, Michael Kruse wrote:
> If I understand correctly, [3] only renamed __FLANG_MAJOR__ to
> FLANG_VERSION_MAJOR_STRING in its own internal configuration. This
> name is not discoverable by invoking flang. Instead, flang's
> preprocessor defines `__flang__`, `__flang_major__`, `__flang_minor__`
> and `__flang_patchlevel__` which have not changed in [3].
> 
> Maybe CMake checks the upper case versions because classic flang sets
> them? In any case, CMake should work with any unknown fortran
> compiler, so you could file a bug with CMake.
> 
> Michael
> 
> 
> Am Mi., 30. Juni 2021 um 11:36 Uhr schrieb Andrzej Warzynski via
> flang-dev <flang-dev at lists.llvm.org>:
>>
>> [Flang = llvm-project/flang]
>>
>> Hello,
>>
>> I have been trying to use Flang with CMake and this integration seems to
>> be dysfunctional right now. Has anyone been using/testing it?
>>
>> *Minimal reproducer*
>> ```CMakeLists.txt
>> project(hello_fortran Fortran)
>> add_executable(hello hello.f90)
>> ```
>>
>> *How to test*
>> ```bash
>>
>> mkdir build && cd build
>> cmake -G Ninja -DCMAKE_Fortran_COMPILER=<path-to-flang-or-gfortran> ../
>> ```
>>
>> *The error*
>> My minimal reproducer works fine with `gfortran`, but it fails with `flang`:
>> ```bash
>> CMake Error: Error required internal CMake variable not set, cmake may
>> not be built correctly.
>> Missing variable is:
>> CMAKE_Fortran_PREPROCESS_SOURCE
>> ```
>>
>> If I understand correctly, CMake fails to identify Flang because the
>> driver does not define the following preprocessor variables currently
>> expected by CMake [1]:
>> * __FLANG
>> * __FLANG_MAJOR__
>> * __FLANG_MINOR__
>> These macros were first discussed and added in [2], but then deleted in
>> [3] in order to keep Flang consistent with the rest of LLVM.
>>
>> This seems to have been broken for a while, so I suspect that this has
>> not been required by anyone recently?
>>
>> Thank you,
>> -Andrzej
>>
>> [1]
>> https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/CMakeFortranCompilerId.F.in#L143-147
>> [2] https://reviews.llvm.org/D84334
>> [3] https://reviews.llvm.org/D94422
>> _______________________________________________
>> flang-dev mailing list
>> flang-dev at lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/flang-dev


More information about the flang-dev mailing list