Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake Fortran compiler detection fails #3694

Closed
teamblubee opened this issue Oct 22, 2018 · 8 comments
Closed

CMake Fortran compiler detection fails #3694

teamblubee opened this issue Oct 22, 2018 · 8 comments
Labels
Framework tasks Framework tasks (used internally by Framework team) impacting: configure or build The issue is primarily related to configuring or building

Comments

@teamblubee
Copy link

@trilinos/

Expectations

Current Behavior

I am trying to use the Ninja generator to compile Trilinos using the newly open source Fortran compiler; Flang: https://github.com/flang-compiler/flang

The cmake test fails

Probing the environment ...

-- USE_XSDK_DEFAULTS='FALSE'
-- BUILD_SHARED_LIBS='FALSE'
-- CMAKE_BUILD_TYPE='RELEASE'
-- CMAKE_C_COMPILER_ID='Clang'
-- CMAKE_C_COMPILER_VERSION='5.0.1'
-- CMAKE_CXX_COMPILER_ID='Clang'
-- CMAKE_CXX_COMPILER_VERSION='5.0.1'
-- The Fortran compiler identification is Flang 99.99.1
-- Check for working Fortran compiler: /usr/local/bin/flang
-- Check for working Fortran compiler: /usr/local/bin/flang  -- broken
CMake Error at /usr/local/share/cmake/Modules/CMakeTestFortranCompiler.cmake:45 (message):
  The Fortran compiler

    "/usr/local/bin/flang"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /wrkdirs/usr/ports/math/trilinos/work/.build/CMakeFiles/CMakeTmp
    
    Run Build Command:"/usr/local/bin/ninja" "cmTC_2dfa4"
    [1/4] Building Fortran preprocessed CMakeFiles/cmTC_2dfa4.dir/testFortranCompiler.f-pp.f
    FAILED: CMakeFiles/cmTC_2dfa4.dir/testFortranCompiler.f-pp.f CMakeFiles/cmTC_2dfa4.dir/testFortranCompiler.f-pp.f.ddi 
    /usr/local/bin/flang -cpp    -E testFortranCompiler.f -o CMakeFiles/cmTC_2dfa4.dir/testFortranCompiler.f-pp.f && /usr/local/bin/cmake -E cmake_ninja_depends --tdi=CMakeFiles/cmTC_2dfa4.dir/FortranDependInfo.json --pp=CMakeFiles/cmTC_2dfa4.dir/testFortranCompiler.f-pp.f --dep=CMakeFiles/cmTC_2dfa4.dir/testFortranCompiler.f-pp.f.d --obj=CMakeFiles/cmTC_2dfa4.dir/testFortranCompiler.f.o --ddi=CMakeFiles/cmTC_2dfa4.dir/testFortranCompiler.f-pp.f.ddi
    # 1 "testFortranCompiler.f"
    # 2 "testFortranCompiler.f"
            PROGRAM TESTFortran
            PRINT *, 'Hello'
            END
      
    CMake Error: -E cmake_ninja_depends failed to open CMakeFiles/cmTC_2dfa4.dir/testFortranCompiler.f-pp.f
    ninja: build stopped: subcommand failed.
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  cmake/tribits/core/package_arch/TribitsGlobalMacros.cmake:1830 (ENABLE_LANGUAGE)
  cmake/tribits/core/package_arch/TribitsProjectImpl.cmake:188 (TRIBITS_SETUP_ENV)
  cmake/tribits/core/package_arch/TribitsProject.cmake:93 (TRIBITS_PROJECT_IMPL)
  CMakeLists.txt:90 (TRIBITS_PROJECT)

but if I manually run the program and test it works
creating test program with the same contents of the above cmake command

            PROGRAM TESTFortran
            PRINT *, 'Hello'
            END

save that as test.f
flang test.f

flang -v test.f 
clang version 6.0.1 
Target: x86_64-portbld-freebsd12.0
Thread model: posix
InstalledDir: /usr/local/flang/bin
 "/usr/local/flang/bin/flang1" test.f -opt 0 -terse 1 -inform warn -nohpf -nostatic -inform warn -x 19 0x400000 -quad -x 68 0x1 -x 59 4 -x 15 2 -x 49 0x400004 -x 51 0x20 -x 57 0x4c -x 58 0x10000 -x 124 0x1000 -tp px -x 57 0xfb0000 -x 58 0x78031040 -x 47 0x08 -x 48 4608 -x 49 0x100 -def unix -def __unix -def __unix__ -def __FreeBSD__ -def __NO_MATH_INLINES -def __LP64__ -def __LONG_MAX__=9223372036854775807L -def __SIZE_TYPE__=unsigned long int -def __PTRDIFF_TYPE__=long int -def __x86_64 -def __x86_64__ -def __amd_64__amd64__ -def __k8 -def __k8__ -def __THROW= -def __extension__= -def __PGLLVM__ -nofreeform -idir /usr/local/include -idir /usr/local/flang/include -idir /usr/local/llvm60/include -idir /usr/local/llvm60/lib/clang/6.0.1/include -vect 48 -x 54 1 -x 70 0x40000000 -y 163 0xc0000000 -x 189 0x10 -stbfile test-2a5590.stb -modexport test-2a5590.cmod -modindex test-2a5590.cmdx -output test-2a5590.ilm
 "/usr/local/flang/bin/flang2" test-2a5590.ilm -y 129 2 -ieee 0 -fn test.f -opt 0 -terse 1 -inform warn -inform warn -x 68 0x1 -x 51 0x20 -x 119 0xa10000 -x 122 0x40 -x 123 0x1000 -x 127 4 -x 127 17 -x 19 0x400000 -x 28 0x40000 -x 120 0x10000000 -x 70 0x8000 -x 122 1 -x 125 0x20000 -x 164 0x800000 -quad -x 59 4 -tp px -x 120 0x1000 -x 124 0x1400 -y 15 2 -x 57 0x3b0000 -x 58 0x48000000 -x 49 0x100 -astype 0 -x 183 4 -x 121 0x800 -x 54 0x10 -x 70 0x40000000 -x 249 50 -x 124 1 -y 163 0xc0000000 -x 189 0x10 -y 189 0x4000000 -x 183 0x10 -stbfile test-2a5590.stb -asm /tmp/test-2a5590.ll
 "/usr/local/flang/bin/clang-6.0" -cc1 -triple x86_64-portbld-freebsd12.0 -emit-obj -mrelax-all -disable-free -main-file-name test.f -mrelocation-model static -mthread-model posix -mdisable-fp-elim -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -v -resource-dir /usr/local/flang/lib/clang/6.0.1 -Wno-unused-command-line-argument -fdebug-compilation-dir /wrkdirs/usr/ports/math/trilinos/work/.build -ferror-limit 19 -fmessage-length 294 -fobjc-runtime=gnustep -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/test-02b4b5.o -x ir /tmp/test-2a5590.ll
clang -cc1 version 6.0.1 based upon LLVM 6.0.1 default target x86_64-portbld-freebsd12.0
 "/usr/bin/ld" --eh-frame-hdr -dynamic-linker /libexec/ld-elf.so.1 --hash-style=both --enable-new-dtags -o a.out /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o -L/usr/local/lib -L/usr/local/flang/lib -L/usr/local/llvm60/lib -L/usr/lib -lflangmain -lm -lflang -lflangrti -lomptarget -lompstub -lomp -lpgmath -lm -lexecinfo /tmp/test-02b4b5.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/crtend.o /usr/lib/crtn.o

running

 ./a.out 
 Hello

Possible Solution

properly detect flang compiler?

Your Environment

./configure -GNinja;
I already have the Kitware ninja fork that supports fortran.

Additional Information

//Enable support for the TPL ExodusII in all supported Trilinos
// packages.  This can be set to 'ON', 'OFF', or left empty ''.
Determining if the Fortran compiler works failed with the following output:
Change Dir: /wrkdirs/usr/ports/math/trilinos/work/.build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/local/bin/ninja" "cmTC_6274f"
[1/4] Building Fortran preprocessed CMakeFiles/cmTC_6274f.dir/testFortranCompiler.f-pp.f
FAILED: CMakeFiles/cmTC_6274f.dir/testFortranCompiler.f-pp.f CMakeFiles/cmTC_6274f.dir/testFortranCompiler.f-pp.f.ddi
/usr/local/bin/flang -cpp    -E testFortranCompiler.f -o CMakeFiles/cmTC_6274f.dir/testFortranCompiler.f-pp.f && /usr/local/bin/cmake -E cmake_ninja_depends --tdi=CMakeFiles/cmTC_6274f.dir/FortranDependInfo.json --pp=CMakeFiles/cmTC_6274f.dir/testFortranCompiler.f-pp.f --dep=CMakeFiles/cmTC_62
74f.dir/testFortranCompiler.f-pp.f.d --obj=CMakeFiles/cmTC_6274f.dir/testFortranCompiler.f.o --ddi=CMakeFiles/cmTC_6274f.dir/testFortranCompiler.f-pp.f.ddi
# 1 "testFortranCompiler.f"
# 2 "testFortranCompiler.f"
        PROGRAM TESTFortran
        PRINT *, 'Hello'
        END

CMake Error: -E cmake_ninja_depends failed to open CMakeFiles/cmTC_6274f.dir/testFortranCompiler.f-pp.f
ninja: build stopped: subcommand failed.


Determining if the Fortran compiler works failed with the following output:
Change Dir: /wrkdirs/usr/ports/math/trilinos/work/.build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/local/bin/ninja" "cmTC_2dfa4"
[1/4] Building Fortran preprocessed CMakeFiles/cmTC_2dfa4.dir/testFortranCompiler.f-pp.f
FAILED: CMakeFiles/cmTC_2dfa4.dir/testFortranCompiler.f-pp.f CMakeFiles/cmTC_2dfa4.dir/testFortranCompiler.f-pp.f.ddi
/usr/local/bin/flang -cpp    -E testFortranCompiler.f -o CMakeFiles/cmTC_2dfa4.dir/testFortranCompiler.f-pp.f && /usr/local/bin/cmake -E cmake_ninja_depends --tdi=CMakeFiles/cmTC_2dfa4.dir/FortranDependInfo.json --pp=CMakeFiles/cmTC_2dfa4.dir/testFortranCompiler.f-pp.f --dep=CMakeFiles/cmTC_2d
fa4.dir/testFortranCompiler.f-pp.f.d --obj=CMakeFiles/cmTC_2dfa4.dir/testFortranCompiler.f.o --ddi=CMakeFiles/cmTC_2dfa4.dir/testFortranCompiler.f-pp.f.ddi
# 1 "testFortranCompiler.f"
# 2 "testFortranCompiler.f"
        PROGRAM TESTFortran
        PRINT *, 'Hello'
        END

CMake Error: -E cmake_ninja_depends failed to open CMakeFiles/cmTC_2dfa4.dir/testFortranCompiler.f-pp.f
ninja: build stopped: subcommand failed.
@mhoemmen
Copy link
Contributor

@trilinos/framework How recent does Ninja need to be in order to work with Fortran? I remember this being an issue.

@teamblubee Do you need Trilinos to have Fortran support? If not, you could just turn it off: Trilinos_ENABLE_Fortran:BOOL=OFF.

This was referenced Oct 22, 2018
@teamblubee
Copy link
Author

@trilinos/framework How recent does Ninja need to be in order to work with Fortran? I remember this being an issue.

@teamblubee Do you need Trilinos to have Fortran support? If not, you could just turn it off: Trilinos_ENABLE_Fortran:BOOL=OFF.

Hi @mhoemmen I would like to make sure that the fortran compiler does work as it's newly open sourced and this is more testing as well as making sure that FreeBSD has fortran compiler that works with the native toolchain.

I was just doing some more testing and it seems that it's the -E flag at the end that causes the compilation to fail.

/usr/local/bin/flang -cpp -O -O2 -pipe -I/usr/local/include -I/usr/local/flang/include -I/usr/local/llvm60/include -I/usr/local/llvm60/lib/clang/6.0.1/include -fstack-protector -fno-strict-aliasing -E test.f -o hi

just prints out the fortran sample code while removing the -E flag

/usr/local/bin/flang -cpp -O -O2 -pipe -I/usr/local/include -I/usr/local/flang/include -I/usr/local/llvm60/include -I/usr/local/llvm60/lib/clang/6.0.1/include -fstack-protector -fno-strict-aliasing test.f -o hi

creates a valid executable.

I think this is an upstream CMAKE issue and not Trilinos issue.

@mhoemmen
Copy link
Contributor

@teamblubee Does this work if you don't use Ninja and instead use the default back-end? This could be a Ninja + Fortran issue.

@teamblubee
Copy link
Author

teamblubee commented Oct 23, 2018

@teamblubee Does this work if you don't use Ninja and instead use the default back-end? This could be a Ninja + Fortran issue.

Yes, building with -GUnix Makefiles works just fine;
Although I have built other projects with CMake ninja generator and fortran.

But I don't think that has anything to do with the Trilinos project, unless they'd be interested in looking into it further.

quick edit
I am using this version of ninja: https://github.com/Kitware/ninja
which supports Fortran

@mhoemmen mhoemmen added Framework tasks Framework tasks (used internally by Framework team) impacting: configure or build The issue is primarily related to configuring or building labels Oct 23, 2018
@mhoemmen
Copy link
Contributor

Thanks for the info! I'll just pass this along to @trilinos/framework and see if there's a work-around. Good to know that you're using the updated Ninja.

@prwolfe
Copy link
Contributor

prwolfe commented Oct 23, 2018

The -E is just asking for all the preprocessing to be done instead of a compile. The actual err is a file not found issue from the dependency system

cmake_ninja_depends failed to open CMakeFiles/cmTC_2dfa4.dir/testFortranCompiler.f-pp.f

I'm not sure why that would happen.

@jwillenbring
Copy link
Member

@teamblubee @mhoemmen @prwolfe

Can this issue be closed based on @prwolfe 's comment?

@teamblubee
Copy link
Author

@teamblubee @mhoemmen @prwolfe

Can this issue be closed based on @prwolfe 's comment?

yes please, it was solved upstream with cmake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Framework tasks Framework tasks (used internally by Framework team) impacting: configure or build The issue is primarily related to configuring or building
Projects
None yet
Development

No branches or pull requests

4 participants