From 219ab0b9b0d3b800d85bcdebd465f3af7aff4e9d Mon Sep 17 00:00:00 2001 From: Kevin Meagher <11620178+kjmeagher@users.noreply.github.com> Date: Wed, 30 Oct 2024 16:59:28 -0500 Subject: [PATCH] New wrap: cfitsio-4.5.0 This is a file wrap with a patch. It is mostly based on the CMakeLists.txt provided in the source. But there were a few defines in the autotolls version that werent in the cmake that I also added. --- ci_config.json | 9 + releases.json | 6 + subprojects/cfitsio.wrap | 9 + subprojects/packagefiles/cfitsio/meson.build | 283 ++++++++++++++++++ .../packagefiles/cfitsio/meson.options | 38 +++ .../packagefiles/cfitsio/test_compare.py | 37 +++ tools/sanity_checks.py | 3 + 7 files changed, 385 insertions(+) create mode 100644 subprojects/cfitsio.wrap create mode 100644 subprojects/packagefiles/cfitsio/meson.build create mode 100644 subprojects/packagefiles/cfitsio/meson.options create mode 100644 subprojects/packagefiles/cfitsio/test_compare.py diff --git a/ci_config.json b/ci_config.json index 8ef616fe8b..9bc79fe864 100644 --- a/ci_config.json +++ b/ci_config.json @@ -55,6 +55,15 @@ "cexception:werror=false" ] }, + "cfitsio": { + "alpine_packages": [ + "gfortran", + "libcurl" + ], + "debian_packages": [ + "gfortran" + ] + }, "cglm": { "build_options": [ "cglm:build_tests=true" diff --git a/releases.json b/releases.json index d23f7ef281..18f587250c 100644 --- a/releases.json +++ b/releases.json @@ -348,6 +348,12 @@ "1.3.3-1" ] }, + "cfitsio":{ + "dependency_names": [ + "cfitsio" + ], + "versions":["4.5.0-1"] + }, "cglm": { "dependency_names": [ "cglm" diff --git a/subprojects/cfitsio.wrap b/subprojects/cfitsio.wrap new file mode 100644 index 0000000000..8e7cf500dd --- /dev/null +++ b/subprojects/cfitsio.wrap @@ -0,0 +1,9 @@ +[wrap-file] +directory = cfitsio-4.5.0 +source_url = https://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c/cfitsio-4.5.0.tar.gz +source_filename = cfitsio-4.5.0.tar.gz +source_hash = e4854fc3365c1462e493aa586bfaa2f3d0bb8c20b75a524955db64c27427ce09 +patch_directory = cfitsio + +[provide] +cfitsio = cfitsio_dep diff --git a/subprojects/packagefiles/cfitsio/meson.build b/subprojects/packagefiles/cfitsio/meson.build new file mode 100644 index 0000000000..cd81c065f5 --- /dev/null +++ b/subprojects/packagefiles/cfitsio/meson.build @@ -0,0 +1,283 @@ +project( + 'cfitsio', + 'c', + version: '4.5.0', + meson_version: '>=1.1.0', + license: 'CFITSIO', + license_files: ['licenses/License.txt'], +) +has_fortran = add_languages( + 'fortran', + native: false, + required: get_option('fortran'), +) +SOVERSION = 10 + +cc = meson.get_compiler('c') +deps = [] +libm = cc.find_library('m', required: false) +if not libm.found() + libm = dependency('', required: false) +endif +deps += libm + +deps += dependency('zlib', method: 'pkg-config', required:true, fallback: ['zlib', 'zlib_dep']) + +if cc.get_id() != 'msvc' + + threads = dependency('threads', required: get_option('reentrant')) + if threads.found() + add_project_arguments('-D_REENTRANT', language: 'c') + deps += threads + endif + + bzip2 = dependency( + 'bzip2', + method: 'pkg-config', + required: get_option('bzip2'), + fallback: ['bzip2', 'bzip2_dep'], + ) + if bzip2.found() + add_project_arguments('-DHAVE_BZIP2=1', language: 'c') + deps += bzip2 + endif + + curl = dependency( + 'libcurl', + method: 'pkg-config', + required: get_option('curl'), + ) + if curl.found() + add_project_arguments('-DCFITSIO_HAVE_CURL', language: 'c') + deps += curl + endif + + if cc.has_header_symbol('unistd.h', 'ftruncate') + add_project_arguments('-DHAVE_UNISTD_H', '-DHAVE_FTRUNCATE', language: 'c') + endif + +else + add_project_arguments('-DYY_NO_UNISTD_H', language: 'c') +endif + + +if get_option('hera') + add_project_arguments('-DBUILD_HERA=1', language: 'c') +endif + +if cc.get_id() != 'msvc' and cc.has_function('gethostbyname') and cc.has_function( + 'connect', +) + add_project_arguments('-DHAVE_NET_SERVICES', language: 'c') + if cc.has_header_symbol('stdio.h', 'fmemopen') + add_project_arguments('-DHAVE_FMEMOPEN', language: 'c') + endif +endif + +if get_option('sse2') + if cc.has_argument('-msse2') + add_project_arguments('-msse2', language: 'c') + elif cc.get_id() == 'msvc' + add_project_arguments('-D__SSE2__=1', language: 'c') + endif +endif + +if get_option('ssse3') + if cc.has_argument('-mssse3') + add_project_arguments('-mssse3', language: 'c') + elif cc.get_id() == 'msvc' + add_project_arguments('-D__SSE2__=1', '-D__SSSE3__=1', language: 'c') + endif +endif + + + +shmem_prefix = [ + '#include ', + '#include ', + '#include ', +] +flock_prefix = ['#include '] + +have_shmem_services = true +foreach func : ['shmat', 'shmdt', 'shmget', 'semget'] + have_shmem_services = have_shmem_services and cc.has_function( + func, + prefix: shmem_prefix, + ) +endforeach +if have_shmem_services + add_project_arguments('-DHAVE_SHMEM_SERVICES', language: 'c') + if cc.has_type('flock_t', prefix: flock_prefix) + add_project_arguments('-DHAVE_FLOCK_T', language: 'c') + endif + if cc.has_type('union semun', prefix: shmem_prefix) + add_project_arguments('-DHAVE_UNION_SEMUN', language: 'c') + endif +endif + +if cc.has_type('long long') + add_project_arguments('-DHAVE_LONGLONG', language: 'c') +endif + +install_headers('fitsio.h', 'fitsio2.h', 'longnam.h') + +libcfitsio_la_SOURCES = [ + 'buffers.c', + 'cfileio.c', + 'checksum.c', + 'drvrfile.c', + 'drvrmem.c', + 'drvrnet.c', + 'drvrsmem.c', + 'editcol.c', + 'edithdu.c', + 'eval_l.c', + 'eval_y.c', + 'eval_f.c', + 'fitscore.c', + 'getcol.c', + 'getcolb.c', + 'getcold.c', + 'getcole.c', + 'getcoli.c', + 'getcolj.c', + 'getcolk.c', + 'getcoll.c', + 'getcols.c', + 'getcolsb.c', + 'getcoluk.c', + 'getcolui.c', + 'getcoluj.c', + 'getkey.c', + 'group.c', + 'grparser.c', + 'histo.c', + 'iraffits.c', + 'modkey.c', + 'putcol.c', + 'putcolb.c', + 'putcold.c', + 'putcole.c', + 'putcoli.c', + 'putcolj.c', + 'putcolk.c', + 'putcoluk.c', + 'putcoll.c', + 'putcols.c', + 'putcolsb.c', + 'putcolu.c', + 'putcolui.c', + 'putcoluj.c', + 'putkey.c', + 'region.c', + 'scalnull.c', + 'swapproc.c', + 'wcssub.c', + 'wcsutil.c', + 'imcompress.c', + 'quantize.c', + 'ricecomp.c', + 'pliocomp.c', + 'fits_hcompress.c', + 'fits_hdecompress.c', + 'simplerng.c', + 'zcompress.c', + 'zuncompress.c', +] + +if has_fortran + libcfitsio_la_SOURCES += [ + 'f77_wrap1.c', + 'f77_wrap2.c', + 'f77_wrap3.c', + 'f77_wrap4.c', + ] +endif + +libcfitsio = shared_library( + 'cfitsio', + libcfitsio_la_SOURCES, + dependencies: deps, + version: meson.project_version(), + soversion: SOVERSION, + install: true, +) + +cfitsio_dep = declare_dependency( + include_directories: include_directories('.'), + link_with: libcfitsio, +) + +pkg = import('pkgconfig') +pkg.generate( + libraries: libcfitsio, + version: meson.project_version(), + name: 'cifitsio', + description: 'FITS File Subroutine Library', + url: 'https://heasarc.gsfc.nasa.gov/fitsio/', +) + +executable( + 'fitscopy', + 'utilities/fitscopy.c', + dependencies: cfitsio_dep, + install: get_option('utils'), +) +executable( + 'fitsverify', + 'utilities/ftverify.c', + 'utilities/fvrf_data.c', + 'utilities/fvrf_file.c', + 'utilities/fvrf_head.c', + 'utilities/fvrf_key.c', + 'utilities/fvrf_misc.c', + c_args: '-DSTANDALONE', + dependencies: cfitsio_dep, + install: get_option('utils'), +) +executable( + 'fpack', + 'utilities/fpack.c', + 'utilities/fpackutil.c', + dependencies: [libm, cfitsio_dep], + install: get_option('utils'), +) +executable( + 'funpack', + 'utilities/funpack.c', + 'utilities/fpackutil.c', + dependencies: [libm, cfitsio_dep], + link_with: libcfitsio, + install: get_option('utils'), +) + +executable('executimcopy', 'utilities/imcopy.c', dependencies: cfitsio_dep) +if have_shmem_services + executable('smem', 'utilities/smem.c', dependencies: cfitsio_dep) +endif + +test( + 'cookbook', + executable('cookbook', 'utilities/cookbook.c', dependencies: cfitsio_dep), +) +cmp = find_program('test_compare.py') +testprog = executable( + 'testprog', + 'utilities/testprog.c', + dependencies: cfitsio_dep, +) +test('testprog', cmp, args: [testprog, meson.current_source_dir()]) +if has_fortran + testf77 = executable( + 'testf77', + 'utilities/testf77.f', + dependencies: cfitsio_dep, + ) + test('testf77', cmp, args: [testf77, meson.current_source_dir()]) +endif + +benchmark( + 'speed', + executable('speed', 'utilities/speed.c', dependencies: cfitsio_dep), +) diff --git a/subprojects/packagefiles/cfitsio/meson.options b/subprojects/packagefiles/cfitsio/meson.options new file mode 100644 index 0000000000..dcc8967c6e --- /dev/null +++ b/subprojects/packagefiles/cfitsio/meson.options @@ -0,0 +1,38 @@ +option( + 'curl', + type: 'feature', + description: 'Enable linking with the curl library. Enables remote file i/o support', +) +option( + 'reentrant', + type: 'feature', + description: 'Enable reentrant multithreading', +) +option( + 'utils', + type: 'boolean', + description: 'Build fpack, funpack, fitscopy, and fitsverify executables', +) +option( + 'sse2', + type: 'boolean', + description: 'Enable use of instructions in the SSE2 extended instruction set', +) +option( + 'ssse3', + type: 'boolean', + description: 'Enable use of instructions in the SSSE3 extended instruction set', +) +option('hera', type: 'boolean', description: 'Build for HERA (ASD use only)') +option( + 'bzip2', + type: 'feature', + description: 'Enable bzip2 support. Optional path to the location of include/bzlib.h and lib/libbz2', +) +# option('gsiftp',type:'feature', description: 'Enable Globus Toolkit gsiftp protocol support') +# option('gsiftp-flavour','Define Globus Toolkit gsiftp protocol flavour') +option( + 'fortran', + type: 'feature', + description: 'Build package with Fortran support', +) diff --git a/subprojects/packagefiles/cfitsio/test_compare.py b/subprojects/packagefiles/cfitsio/test_compare.py new file mode 100644 index 0000000000..6059397d00 --- /dev/null +++ b/subprojects/packagefiles/cfitsio/test_compare.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +""" +cfitsio instructs the user build test executeables, run them, and then compare +the output to provided reference files. This python file does that in a +portable way integrated into meson's test framework +""" + +import sys +from pathlib import Path +import subprocess + +test_exe = Path(sys.argv[1]) +src_dir = Path(sys.argv[2]) +name = test_exe.name.split('.')[0] + +input_name = src_dir / (name + ".tpt") +output_ref = src_dir / (name + ".out") +fits_ref = src_dir / (name + ".std") + +print(f"input file: {input_name} found : {input_name.is_file()}") +print(f"output reference: {output_ref} found : {output_ref.is_file()}") +print(f"fits reference: {fits_ref} found : {fits_ref.is_file()}") + +r = subprocess.run(test_exe.absolute(), cwd=src_dir, capture_output=True) +if r.returncode: + print(r"test returned non zero: {r.returncode}") + exit(r.returncode) + +out_are_same = r.stdout.splitlines() == open(output_ref, "rb").read().splitlines() +print(f"Outputs are the same: {out_are_same}") +fits_are_same = ( + open(fits_ref, "rb").read() == open(src_dir / (name + ".std"), "rb").read() +) +print(f"Fits are the same: {fits_are_same}") + +exit(int(not fits_are_same) * 2 + int(not out_are_same)) diff --git a/tools/sanity_checks.py b/tools/sanity_checks.py index 84ecf3dbde..57fc1bb5bc 100755 --- a/tools/sanity_checks.py +++ b/tools/sanity_checks.py @@ -37,6 +37,9 @@ 'bzip2': [ 'test.py', ], + 'cfitsio': [ + 'test_compare.py', + ], 'curl': [ 'buildinfo.txt.meson', 'extract.mk',