[CMake] try_run or similar to find available Fortran integer kinds

Brad King brad.king at kitware.com
Fri Sep 20 11:30:18 EDT 2013


On 09/19/2013 04:03 PM, Zaak Beekman wrote:
> I think what I need to do is create a test program and use try_run()
> and then configure_file()

If a runtime check is really necessary then something like this will
be needed.  However, see Yngve's sibling response.  Is your original
message saying that a Fortran compiler might compile

 integer*8 myinteger

but fail at runtime?

>  1. Can I have a multiple source file program and pass it to try_run()?

No, but try_compile does allow an entire test project source tree to be
built, and that can have multiple sources.  CMake's FortranCInterface
module uses this to do mangling detection:

 http://cmake.org/gitweb?p=cmake.git;a=blob;f=Modules/FortranCInterface/Detect.cmake;hb=v2.8.11.2#l37

The try_run command in CMake has not kept up with try_compile's features
because the former is not useful for cross-compiling so it is seldom used.

>  2. Since Fortran has no concept of a return value (not formally as
>     far as the standard is concerned) it looks like I need to pass
>     the information about available kind types in the
>     RUN_OUTPUT_VARIABLE back to CMake and manipulate it there.
>     Does this variable just get populated with a string which is
>     whatever your code (that you try_ran) outputs to stdout?

Yes, but with the above suggestion using try_compile to build the
test case you'll have to find the executable and use the
execute_process command to run it.  That has options to capture
the output too.

-Brad


More information about the CMake mailing list