Empty prefix/suffix in FotranCInterface detection.
I detected a potential issue in cmake 3.12.4
while compiling Paraview 5.5.0 with XL compiler (latest release candidate).
There is a piece under VTK Catalyst component that relies on the outcome of FortranCInterface_GLOBAL_FOUND
to decide weather new mangled symbols are created in the C++ code (FortranAdaptorAPI.cxx
).
For this specific compile, FortranCInterface_GLOBAL_FOUND
is set to true but the symbols in the file generated by FortranCInterface_HEADER
get the exact same name as the original C symbols.
I don't know CMake well enough to be absolutely sure about this, but my understanding is that FortranCInterface_GLOBAL_FOUND
should be set only if there actually any mangling needed to match symbols with Fortran. Certainly that's the semantic that Paraview build system expects.
After poking around the code, I realised that the reason for that being set to true is that in cmake-3.12/Modules/FortranCInterface/Detect.cmake
the code is allowing empty-string prefix/suffixes to count as an actual mangling.
In the code:
string(REGEX REPLACE "${_global_${form}regex}"
"\\1;\\2;\\3" pieces "${symbol}")
list(LENGTH pieces len)
if(len EQUAL 3)
set(FortranCInterface_GLOBAL_${form}SYMBOL "${symbol}")
list(GET pieces 0 FortranCInterface_GLOBAL_${form}PREFIX)
list(GET pieces 1 name)
list(GET pieces 2 FortranCInterface_GLOBAL_${form}SUFFIX)
set(FortranCInterface_GLOBAL_${form}CASE "${_case_${name}}")
endif()
pieces
can be ;my_sub;
, which will cause len
to be 3
, FortranCInterface_GLOBAL_${form}SYMBOL
to be set and , further down FortranCInterface_GLOBAL_FOUND
to be set true.
Changing the code to something like:
string(REGEX REPLACE "${_global_${form}regex}"
"\\1;\\2;\\3" pieces "${symbol}")
list(LENGTH pieces len)
if(len EQUAL 3)
list(GET pieces 0 FortranCInterface_GLOBAL_${form}PREFIX)
list(GET pieces 1 name)
list(GET pieces 2 FortranCInterface_GLOBAL_${form}SUFFIX)
set(FortranCInterface_GLOBAL_${form}CASE "${_case_${name}}")
if (FortranCInterface_GLOBAL_${form}PREFIX OR
FortranCInterface_GLOBAL_${form}SUFFIX)
set(FortranCInterface_GLOBAL_${form}SYMBOL "${symbol}")
endif()
endif()
Fixed the problem for me. It is possible that the "MODULE" variant below this code suffers similar problem with some compilers.