Bug in Kitware's release of Ninja when compiling with PGI Fortran

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Bug in Kitware's release of Ninja when compiling with PGI Fortran

Daniel Carrera
Hello,

First of all, I want to say that I think it's amazing that Kitware has gone through the trouble of maintaining a separate build of Ninja with bugfixes so that us Fortran users can use Ninja with CMake:




Since no good deed goes unpunished... I want to report that this release of Ninja doesn't seem to like the PGI compiler. Let me show you. I have a toy project with just two files:

- CMakeLists.txt
- src/foo.f90


Where foo.f90 is a toy program that adds two integers, and CMakeLists.tx contains the bare minimum:

--------------------------
$ cat CMakeLists.txt 
cmake_minimum_required(VERSION 3.7)

project(hello)
enable_language(Fortran)

add_executable(prog src/foo.f90)
--------------------------

At this point I should say that I am running CMake 3.7.1 freshly downloaded from cmake.org and my OS is Ubuntu Linux 16.04 LTS. So anyway, if we produce Makefiles everything is fine:

--------------------------
$ mkdir build
$ cd build
build $ echo $FC   # <---- PGI compiler.
pgfortran

build $ cmake ..
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The Fortran compiler identification is PGI 16.10.0
-- Check for working Fortran compiler: /usr/local/bin/pgfortran
-- Check for working Fortran compiler: /usr/local/bin/pgfortran  -- works
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Checking whether /usr/local/bin/pgfortran supports Fortran 90
-- Checking whether /usr/local/bin/pgfortran supports Fortran 90 -- yes
-- Configuring done
-- Generating done
-- Build files have been written to: <snip>/build
--------------------------

But when I ask CMake to make Ninja files, I have a problem:


--------------------------
build $ rm -rf [a-zA-Z]*
build $ cmake -GNinja ..
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The Fortran compiler identification is PGI 16.10.0
-- Check for working Fortran compiler: /usr/local/bin/pgfortran
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_Fortran_PREPROCESS_SOURCE
CMake Error: Internal CMake error, TryCompile generation of cmake failed
-- Check for working Fortran compiler: /usr/local/bin/pgfortran  -- broken
CMake Error at /opt/cmake-3.7.1-Linux-x86_64/share/cmake-3.7/Modules/CMakeTestFortranCompiler.cmake:44 (message):
  The Fortran compiler "/usr/local/bin/pgfortran" is not able to compile a
  simple test program.

  It fails with the following output:

   

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:4 (enable_language)


-- Configuring incomplete, errors occurred!
See also "<snip>/build/CMakeFiles/CMakeOutput.log".
See also "<snip>/build/CMakeFiles/CMakeError.log".
--------------------------

I have attached CMakeError.log and CMakeOutput.log inside the Zip file "CMakeFiles.zip". I looked at the log files and I didn't see anything informative. This problem only occurs with the PGI compiler. CMake+Ninja seem to work just fine for the GNU and Intel compilers.

I have verified that I can compile Fortran programs with the PGI compiler. The PGI compiler is also a very recent download from their website. I'm using the free "Community Edition" compiler.

I hope this helps someone find a fix so that CMake+Ninja works even better. Once again, thank you for going through the trouble of patching somebody else's source tree just to give me another feature.

Cheers,
Daniel.


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

CMakeFiles.zip (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Ninja+Fortran support for PGI compiler (was: Bug in Kitware's release of Ninja when compiling with PGI Fortran)

Brad King
On 12/13/2016 09:26 PM, Daniel Carrera wrote:
> First of all, I want to say that I think it's amazing that Kitware has
> gone through the trouble of maintaining a separate build of Ninja with
> bugfixes so that us Fortran users can use Ninja with CMake:

Thanks for trying it out!

> -- The Fortran compiler identification is PGI 16.10.0
> -- Check for working Fortran compiler: /usr/local/bin/pgfortran
> CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
> Missing variable is:
> CMAKE_Fortran_PREPROCESS_SOURCE

This is not a problem with Ninja or our branch of it, but rather with
CMake's information about the PGI Fortran compiler not being updated
to support the Ninja generator.  One can see the value for a few other
compilers (from commit 39ebfc79e614dc395d5ace2ad5818b3ba75ca478):

```
$ git grep -A 1 Fortran_PREPROCESS_SOURCE
Modules/Compiler/GNU-Fortran.cmake:set(CMAKE_Fortran_PREPROCESS_SOURCE
Modules/Compiler/GNU-Fortran.cmake-  "<CMAKE_Fortran_COMPILER> -cpp <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> -o <PREPROCESSED_SOURCE>")
--
Modules/Compiler/Intel-Fortran.cmake:set(CMAKE_Fortran_PREPROCESS_SOURCE
Modules/Compiler/Intel-Fortran.cmake-  "<CMAKE_Fortran_COMPILER> -fpp <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
--
Modules/Compiler/SunPro-Fortran.cmake:set(CMAKE_Fortran_PREPROCESS_SOURCE
Modules/Compiler/SunPro-Fortran.cmake-  "<CMAKE_Fortran_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -F <SOURCE> -o <PREPROCESSED_SOURCE>")
```

The `Modules/Compiler/PGI-Fortran.cmake` module needs to be updated too.
I don't have that compiler handy, so if you can figure out the appropriate
line to add to that file, please try it out.  If you get it working please
post it and Cc me so it can be integrated.

Thanks,
-Brad

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Ninja+Fortran support for PGI compiler (was: Bug in Kitware's release of Ninja when compiling with PGI Fortran)

Daniel Carrera

On 15 December 2016 at 17:35, Brad King <[hidden email]> wrote:

This is not a problem with Ninja or our branch of it, but rather with
CMake's information about the PGI Fortran compiler not being updated
to support the Ninja generator.  One can see the value for a few other
compilers (from commit 39ebfc79e614dc395d5ace2ad5818b3ba75ca478):

```
$ git grep -A 1 Fortran_PREPROCESS_SOURCE
Modules/Compiler/GNU-Fortran.cmake:set(CMAKE_Fortran_PREPROCESS_SOURCE
Modules/Compiler/GNU-Fortran.cmake-  "<CMAKE_Fortran_COMPILER> -cpp <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> -o <PREPROCESSED_SOURCE>")
--
Modules/Compiler/Intel-Fortran.cmake:set(CMAKE_Fortran_PREPROCESS_SOURCE
Modules/Compiler/Intel-Fortran.cmake-  "<CMAKE_Fortran_COMPILER> -fpp <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
--
Modules/Compiler/SunPro-Fortran.cmake:set(CMAKE_Fortran_PREPROCESS_SOURCE
Modules/Compiler/SunPro-Fortran.cmake-  "<CMAKE_Fortran_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -F <SOURCE> -o <PREPROCESSED_SOURCE>")
```

The `Modules/Compiler/PGI-Fortran.cmake` module needs to be updated too.
I don't have that compiler handy, so if you can figure out the appropriate
line to add to that file, please try it out.  If you get it working please
post it and Cc me so it can be integrated.


Ok... keeping in mind that I don't know much about CMake or PGI, this seems to be the correct line:

set(CMAKE_Fortran_PREPROCESS_SOURCE
"<CMAKE_Fortran_COMPILER> -Mpreprocess <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")


The PGI documentation says that -Mpreprocess "instructs the compiler to perform cpp-like preprocessing on assembly and Fortran input source files". The -E flag causes the compiler to spit the result to stdout instead of saving it to a file. Since the -E flag behaves as in the Intel compiler, I used copied the stdout redirect ">" from the Intel-Fortran.cmake example.

I added that line to PGI-Fortran.cmake and it seems to work. CMake can now make Ninja files for PGI.

Cheers,
Daniel.

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Ninja+Fortran support for PGI compiler

Brad King
On 12/15/2016 09:10 PM, Daniel Carrera wrote:
> set(CMAKE_Fortran_PREPROCESS_SOURCE
> "<CMAKE_Fortran_COMPILER> -Mpreprocess <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
>
> I added that line to PGI-Fortran.cmake and it seems to work.

Great!  I'll integrate that for CMake 3.8.

Thanks,
-Brad

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Ninja+Fortran support for PGI compiler

Bill Hoffman
On 12/16/2016 8:38 AM, Brad King wrote:
> Great!  I'll integrate that for CMake 3.8.
Daniel, do you think you could setup a dashboard so this stays working?
https://cmake.org/testing/

-Bill

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Ninja+Fortran support for PGI compiler

Daniel Carrera

On 16 December 2016 at 17:18, Bill Hoffman <[hidden email]> wrote:
On 12/16/2016 8:38 AM, Brad King wrote:
Great!  I'll integrate that for CMake 3.8.
Daniel, do you think you could setup a dashboard so this stays working?
https://cmake.org/testing/

-Bill

Ok. I'll try. I need some help with the script:

# Client maintainer: [hidden email]
set(CTEST_SITE "machine.site")
set(CTEST_BUILD_NAME "pgfortran")
set(CTEST_BUILD_CONFIGURATION Debug)
set(CTEST_CMAKE_GENERATOR "Ninja")
include(${CTEST_SCRIPT_DIRECTORY}/cmake_common.cmake)


What should I write for "machine.site"?

FYI, I will change computer in two months and I will forget to set this up again. You might want to add PGI to your own nightly tests. The PGI "community edition" is free. That's the one I have.


Cheers,
Daniel.

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Ninja+Fortran support for PGI compiler

Daniel Carrera
In reply to this post by Brad King

On 16 December 2016 at 14:38, Brad King <[hidden email]> wrote:
On 12/15/2016 09:10 PM, Daniel Carrera wrote:
> set(CMAKE_Fortran_PREPROCESS_SOURCE
> "<CMAKE_Fortran_COMPILER> -Mpreprocess <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
>
> I added that line to PGI-Fortran.cmake and it seems to work.

Great!  I'll integrate that for CMake 3.8.



Awesome!

Look... I just tested the Oracle compiler. I don't actually use it myself but I have it installed and it also has problems with CMake + Ninja. It looks like the same problem. So again I went to Modules/Compiler but this time I did not see an obvious .cmake file for Oracle. If you want to try to add Oracle to the list of compilers that CMake knows about, this might help:

1) Free download:



2) To identify the compiler, the -V flag should help:

$ f90 -V
f90: Studio 12.5 Fortran 95 8.8 Linux_i386 2016/05/31


3) This is how you pre-process sources:

$ f90 -fpp -F foo.f90 -o output_file


Cheers,
Daniel.

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake