LLVMFlang compiler profile adds unsupported -fPIC flag
when enabling POSITION_INDEPENDENT_CODE option with llvm-flang (not classic-flang), cmake adds -fPIC which is not supported and throws a warning:
-- The Fortran compiler identification is LLVMFlang 15.0.7
...
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Check for working Fortran compiler: /usr/bin/flang-new - skipped
-- Configuring done (1.0s)
-- Generating done (0.0s)
-- Build files have been written to: /tmp/prima
[ 1%] Building Fortran object fortran/CMakeFiles/primaf.dir/common/consts.F90.o
flang-new: warning: argument unused during compilation: '-fPIC'
I tried adding set(CMAKE_Fortran_COMPILE_OPTIONS_PIC)
in Modules/Compiler/LLVMFlang-Fortran.cmake
but unfortunately this is not allowed to be empty (or just spaces) from Modules/CMakeFortranInformation.cmake:
if(NOT CMAKE_Fortran_COMPILE_OPTIONS_PIC)
set(CMAKE_Fortran_COMPILE_OPTIONS_PIC ${CMAKE_C_COMPILE_OPTIONS_PIC})
endif()
dirty workaround:
set(CMAKE_Fortran_COMPILE_OPTIONS_PIC "-D_FPIC_IS_A_LIE_")
Edited by Julien Schueller