Skip to content

Commit

Permalink
meson: move find/capability logic to cmake/meson.build
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Oct 28, 2019
1 parent 116a852 commit 33d4688
Show file tree
Hide file tree
Showing 22 changed files with 206 additions and 202 deletions.
3 changes: 2 additions & 1 deletion array/meson.build
Expand Up @@ -2,4 +2,5 @@ rotflip = library('rotflip', 'rot90.f90')

rotflip_test = executable('rotflip_test', 'test_rot90.f90',
link_with : rotflip)
test('Rotate Flip', rotflip_test)
test('Rotate Flip', rotflip_test,
timeout: 10)
3 changes: 2 additions & 1 deletion benchmarks/meson.build
@@ -1,2 +1,3 @@
ackermann = executable('ackermann', 'ackermann.f90')
test('Ackermann', ackermann, args : ['2','3'], timeout: 10)
test('Ackermann', ackermann, args : ['2','3'],
timeout: 10)
5 changes: 2 additions & 3 deletions block/meson.build
@@ -1,6 +1,5 @@
f08block = fc.links('block; end block; end', name : 'F2008 block')

if f08block
block_exe = executable('block', 'block.f90')
test('block', block_exe, timeout: 10)
test('block', block_exe,
timeout: 10)
endif
20 changes: 13 additions & 7 deletions character/meson.build
@@ -1,22 +1,28 @@
ascii = executable('ascii', 'ascii.f90')
test('Ascii Special', ascii)
test('Ascii Special', ascii,
timeout: 10)

split = executable('split', 'split_string.f90')
test('Split Character', split)
test('Split Character', split,
timeout: 10)

printorwrite = executable('printorwrite', 'print_vs_write.f90')
test('UTF8', printorwrite)
test('UTF8', printorwrite,
timeout: 10)

str2int = executable('str2int', 'str2int.f90')
test('Str2Int', str2int)
test('Str2Int', str2int,
timeout: 10)

special_char = executable('special_char', 'special_characters.f90')
test('Special Characters', special_char)
test('Special Characters', special_char,
timeout: 10)

charlen = executable('charlen', 'charlen.f90')
test('Character Len', charlen)
test('Character Len', charlen,
timeout: 10)

if os != 'windows'
overwrite_stdout = executable('overwrite_stdout', 'overwrite_stdout.f90')
test('Overwrite Stdout', overwrite_stdout, timeout: 6)
test('Overwrite Stdout', overwrite_stdout, timeout: 10)
endif
113 changes: 113 additions & 0 deletions cmake/meson.build
@@ -0,0 +1,113 @@
fc = meson.get_compiler('fortran')
f18flag = fc.first_supported_argument(['-std=f2018', '-stand f18', '/stand:f18'])
impnone = fc.first_supported_argument(['-fimplicit-none', '-warn declarations', '/warn:declarations', '-Mdclchk'])
oldargs = fc.first_supported_argument(['-w', '-nowarn', '/nowarn'])

if fc.get_id() == 'gcc'
add_global_arguments('-Wextra', '-Wpedantic', f18flag, impnone, language : 'fortran')
oldargs += '-std=legacy'
elif fc.get_id() == 'intel'
add_global_arguments(f18flag, impnone, '-heap-arrays', language: 'fortran')
elif fc.get_id() == 'intel-cl'
# /fpp allows #include etc preprocessor lines
# /heap-arrays necessary to avoid segfault
add_global_arguments(f18flag, impnone, '/fpp', '/heap-arrays', language: 'fortran')
elif fc.get_id() == 'pgi'
add_global_arguments('-C', impnone, language: 'fortran')
elif fc.get_id() == 'flang'
add_global_arguments('-W', language: 'fortran')
endif

os = host_machine.system()

# -- compiler capabilities

f18errorstop = fc.links('character :: b; error stop b; end', name: 'F2018 error stop')
f08block = fc.links('block; end block; end', name : 'F2008 block')
f08contig = fc.links('contig = is_contiguous([1,2,3]); end', name: 'F2008 contiguous')
f08command = fc.links('integer foo; call execute_command_line(" ", exitstat=foo); end', name : 'F2008 execute_command_line')
f18random = fc.links('call random_init(.false., .false.); end', name:'F2018 random_init')

code = '''
use, intrinsic:: iso_fortran_env, only: real128
use, intrinsic:: ieee_arithmetic, only: ieee_is_nan
if (huge(0._real128) /= 1.18973149535723176508575932662800702E+4932_real128) stop 1
end program'''
f08kind = fc.links(code, name: 'F2008 ieee kinds')
f18prop = fc.links('complex :: z; print *,z%re,z%im,z%kind; end', name: 'F2018 properties')
# -- Fortran coarray

coarray = dependency('coarray', required : false, disabler: true)
# must be "run" in case of broken MPI library that only shows up on run.
if not (fc.run('sync all; end', dependencies: coarray, name:'Coarray').returncode() == 0)
coarray = disabler()
endif

f18coarray = fc.run('real :: x[*]; call co_sum(x); sync all; end', dependencies: coarray, name: 'F2018 coarray').returncode() == 0


# -- MPI

mpi = dependency('mpi', language : 'fortran', required : false, disabler: true)
code = '''
use mpi
integer :: i
call mpi_init(i)
call mpi_finalize(i)
end program'''
if not fc.links(code,
dependencies : mpi,
name: 'Fortran MPI links')
mpi = disabler()
endif

mpiexec = find_program('mpiexec', required : false, disabler: true) # MS-MPI has only mpiexec

# -- HDF5

hdf5 = dependency('hdf5', language : 'fortran', required : false, disabler: true)

if hdf5.found() and not fc.links('use h5lt; end', name: 'HDF5', dependencies : hdf5)
hdf5 = disabler()
endif

# -- NetCDF
# apt install libnetcdf-dev libnetcdff-dev # need BOTH installed

# when using CMake, need to capitalize module name like in CMake
netcdf = dependency('NetCDF', required : false, disabler: true,
cmake_module_path : meson.source_root() / 'cmake/Modules')

if netcdf.found() and not fc.links('use netcdf; end', name: 'NetCDF', dependencies : netcdf)
netcdf = disabler()
endif

# --- Lapack
lapack = dependency('lapack', required: false, disabler: true)

# --- Scalapack
# dependency('scalapack') not yet working in Meson
# scalapack = dependency('scalapack', cmake_module_path : 'cmake/Modules', required: false, disabler: true)
scalapack = fc.find_library('scalapack-openmpi', required: false, disabler: true)
if not scalapack.found()
scalapack = fc.find_library('scalapack', required: false, disabler: true)
endif

# --- MUMPS
# mumps = dependency('mumps', required: false, disabler: true)
if os == 'linux'
mumpsinc = '/usr/include'
else
mumpsinc = ''
endif
mumpslib = fc.find_library('dmumps', required : false, disabler: true)
mumps = declare_dependency(include_directories: mumpsinc, dependencies: mumpslib)

# -- OpenMP
openmp = dependency('openmp', language : 'fortran', required : false, disabler: true)

if openmp.found() and not fc.links('use omp_lib; rate = omp_get_wtick(); end', name: 'OpenMP', dependencies : openmp)
openmp = disabler()
endif
25 changes: 9 additions & 16 deletions coarray/meson.build
@@ -1,22 +1,15 @@
coarray = dependency('coarray', required : false)

if not (fc.run('sync all; end', dependencies: coarray, name:'Coarray runs').returncode() == 0)
coarray = disabler()
endif

# this needs to be "run" to verify no dll runtime issues, particularly on Windows.
f18coarray = fc.run('real :: x[*]; call co_sum(x); sync all; end', dependencies: coarray, name: 'F2018 coarray').returncode() == 0

hello = executable('coarray_hello', 'helloworld.f90',
dependencies : coarray)
test('Coarray Hello', hello, timeout: 20, is_parallel : false)
test('Coarray Hello', hello,
timeout: 20,
is_parallel : false)

pi_src = f18coarray ? 'pi.f90' : 'pi2008.f90'

# Intel >= 20 supports Fortran 2018 co_sum
if f18coarray
pi = executable('coarray_pi', 'pi.f90', dependencies : coarray)
else
pi = executable('coarray_pi', 'pi2008.f90', dependencies : coarray)
endif
pi = executable('coarray_pi', pi_src,
dependencies : coarray)

test('Coarray Pi', pi, timeout: 20, is_parallel : false)
test('Coarray Pi', pi,
timeout: 20,
is_parallel : false)
12 changes: 2 additions & 10 deletions contiguous/meson.build
@@ -1,17 +1,9 @@
if fc.get_id() == 'intel-cl'
message('Intel Fortran on Windows has a continuous bug')
subdir_done()
endif

if fc.links('contig = is_contiguous([1,2,3]); end', name: 'F2008 contiguous')
f08contig='-DISCONTIG'
else
f08contig=''
endif
args = f08contig ? '-DISCONTIG' : ''

if fc.get_id() != 'gcc'
contig_exe = executable('contig', 'contiguous.F90',
fortran_args : f08contig)
fortran_args : args)
test('Contiguous', contig_exe)
else
message('contiguous: Meson bug with gfortran')
Expand Down
2 changes: 1 addition & 1 deletion cxx/meson.build
Expand Up @@ -4,7 +4,7 @@ if not add_languages('cpp', required: false)
endif

if os == 'darwin'
message('cxx: Meson build on Mac')
message('cxx: SKIP Meson build on Mac')
subdir_done()
endif

Expand Down
8 changes: 0 additions & 8 deletions debug/CMakeLists.txt
@@ -1,16 +1,8 @@
add_executable(badbounds badbounds.f90)
if(CMAKE_Fortran_COMPILER_ID STREQUAL GCC)
target_compile_options(badbounds PRIVATE -fcheck=bounds)
set(xfail true)
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL Intel)
set(xfail true)
else()
set(xfail false)
endif()

# falsely trips with segfault
# add_test(NAME BoundsFail COMMAND badbounds WILL_FAIL ${xfail})

if(WIN32 AND CMAKE_Fortran_COMPILER_ID STREQUAL PGI)
message(STATUS "CMake bug with PGI on Windows -- pgfortran.exe itself works")
else()
Expand Down
14 changes: 5 additions & 9 deletions debug/meson.build
@@ -1,19 +1,15 @@

if fc.get_id() == 'gcc'
boundsargs = '-fcheck=bounds'
xfail = true
else
boundsargs = []
xfail = false
endif
boundsargs = fc.get_id() == 'gcc' ? '-fcheck=bounds' : []

badbounds = executable('badbounds', 'badbounds.f90',
fortran_args : boundsargs)
# Too unreliable to test--that's the point.

nanmaxmin_exe = executable('nanmaxmin', 'maxmin_nan.f90')
test('debug: NaN min, max', nanmaxmin_exe, timeout: 10)
test('debug: NaN min, max', nanmaxmin_exe,
timeout: 10)

typecast_exe = executable('typecast', 'typecast.f90',
fortran_args: oldargs)
test('debug: typecase', typecast_exe, timeout: 10)
test('debug: typecase', typecast_exe,
timeout: 10)
6 changes: 0 additions & 6 deletions hdf5/meson.build
@@ -1,9 +1,3 @@
hdf5 = dependency('HDF5', language : 'fortran', required : false, disabler: true)

if hdf5.found() and not fc.links('use h5lt; end', name: 'HDF5', dependencies : hdf5)
hdf5 = disabler()
endif

h5mod = library('h5mod', 'h5mod.f90', dependencies : hdf5)

h5simple = executable('h5simple', 'hdf5simple.f90',
Expand Down
3 changes: 2 additions & 1 deletion io/meson.build
Expand Up @@ -5,7 +5,8 @@ append_exe = executable('test_logging', 'append_file.f90',
termio = executable('termio', 'terminal_io.f90')

leading_zeros = executable('leading_zeros', 'leading_zeros.f90')
test('LeadingZeros', leading_zeros)
test('LeadingZeros', leading_zeros,
timeout: 10)

expanduser = executable('expanduser', 'expanduser.f90')

Expand Down
22 changes: 1 addition & 21 deletions meson.build
Expand Up @@ -4,27 +4,7 @@ project('Fortran2018examples', 'fortran', 'c',

realbits = get_option('realbits')

fc = meson.get_compiler('fortran')
f18flag = fc.first_supported_argument(['-std=f2018', '-stand f18', '/stand:f18'])
impnone = fc.first_supported_argument(['-fimplicit-none', '-warn declarations', '/warn:declarations', '-Mdclchk'])
oldargs = fc.first_supported_argument(['-w', '-nowarn', '/nowarn'])
if fc.get_id() == 'gcc'
add_global_arguments('-Wextra', '-Wpedantic', f18flag, impnone, language : 'fortran')
oldargs += '-std=legacy'
elif fc.get_id() == 'intel'
add_global_arguments(f18flag, impnone, language: 'fortran')
elif fc.get_id() == 'intel-cl'
# /fpp allows #include etc preprocessor lines
add_global_arguments(f18flag, impnone, '/fpp', language: 'fortran')
elif fc.get_id() == 'pgi'
add_global_arguments('-C', impnone, language: 'fortran')
elif fc.get_id() == 'flang'
add_global_arguments('-W', language: 'fortran')
endif

os = host_machine.system()

f18errorstop = fc.links('character :: b; error stop b; end', name: 'F2018 error stop')
subdir('cmake') # must be before other subdirs to get compiler capabilities and libraries

subdir('array')
subdir('benchmarks')
Expand Down
22 changes: 6 additions & 16 deletions mpi/meson.build
@@ -1,28 +1,18 @@
mpi = dependency('mpi', language : 'fortran', required : false)

if not fc.links('''
use mpi
integer :: i
call mpi_init(i)
call mpi_finalize(i)
end''',
dependencies : mpi,
name: 'Fortran MPI links')
mpi = disabler()
endif

mpiexec = find_program('mpiexec', required : false) # MS-MPI has only mpiexec

ver = executable('mpivers', 'mpivers.f90',
dependencies : mpi)
test('MPI version check', ver)

hello = executable('mpi_hello', 'helloworld.f90',
dependencies : mpi)
test('MPI Hello World', mpiexec, timeout: 20, is_parallel : false,
test('MPI Hello World', mpiexec,
timeout: 20,
is_parallel : false,
args: ['-np', '2', hello])


pass = executable('mpi_pass', 'thread_pass.f90', dependencies : mpi)
test('MPI thread pass', mpiexec, timeout: 20, is_parallel : false,
test('MPI thread pass', mpiexec,
timeout: 20,
is_parallel : false,
args: ['-np', '2', pass])

0 comments on commit 33d4688

Please sign in to comment.