Skip to content

Commit

Permalink
Merge pull request #3 from wkensuke/add_linkfortran_option
Browse files Browse the repository at this point in the history
Add configure option(--enable-linkfortran) to link the Fortran runtime library
  • Loading branch information
tetsuzo-usui authored Feb 28, 2024
2 parents 9266e08 + 263cd2c commit 3922f7c
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 135 deletions.
24 changes: 15 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,13 @@ if (ENABLE_QUAD_PRECISION)
set (BENCHFFT_QUAD TRUE)
set (PREC_SUFFIX q)
endif ()
set (fftw3_lib fftw3${PREC_SUFFIX})

set (FORT_SUFFIX)
if (ENABLE_LINKFORTRAN)
set (FORT_SUFFIX _fortran)
endif ()

set (fftw3_lib fftw3${PREC_SUFFIX}${FORT_SUFFIX})

configure_file (cmake.config.h.in config.h @ONLY)
include_directories (${CMAKE_CURRENT_BINARY_DIR})
Expand Down Expand Up @@ -411,24 +417,24 @@ set (exec_prefix ${CMAKE_INSTALL_PREFIX})
set (libdir ${CMAKE_INSTALL_FULL_LIBDIR})
set (includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
set (VERSION ${FFTW_VERSION})
configure_file (fftw.pc.in fftw3${PREC_SUFFIX}.pc @ONLY)
configure_file (fftw.pc.in fftw3${PREC_SUFFIX}${FORT_SUFFIX}.pc @ONLY)
install (FILES
${CMAKE_CURRENT_BINARY_DIR}/fftw3${PREC_SUFFIX}.pc
${CMAKE_CURRENT_BINARY_DIR}/fftw3${PREC_SUFFIX}${FORT_SUFFIX}.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
COMPONENT Development)

# cmake file
set (FFTW3_LIBRARIES "FFTW3::${fftw3_lib}")
configure_file (FFTW3Config.cmake.in FFTW3${PREC_SUFFIX}Config.cmake @ONLY)
configure_file (FFTW3ConfigVersion.cmake.in FFTW3${PREC_SUFFIX}ConfigVersion.cmake @ONLY)
configure_file (FFTW3Config.cmake.in FFTW3${PREC_SUFFIX}${FORT_SUFFIX}Config.cmake @ONLY)
configure_file (FFTW3ConfigVersion.cmake.in FFTW3${PREC_SUFFIX}${FORT_SUFFIX}ConfigVersion.cmake @ONLY)
install (FILES
${CMAKE_CURRENT_BINARY_DIR}/FFTW3${PREC_SUFFIX}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/FFTW3${PREC_SUFFIX}ConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/fftw3${PREC_SUFFIX}
${CMAKE_CURRENT_BINARY_DIR}/FFTW3${PREC_SUFFIX}${FORT_SUFFIX}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/FFTW3${PREC_SUFFIX}${FORT_SUFFIX}ConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/fftw3${PREC_SUFFIX}${FORT_SUFFIX}
COMPONENT Development)

export (TARGETS ${fftw3_lib} NAMESPACE FFTW3:: FILE ${PROJECT_BINARY_DIR}/FFTW3LibraryDepends.cmake)
install(EXPORT FFTW3LibraryDepends
NAMESPACE FFTW3::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/fftw3${PREC_SUFFIX}
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/fftw3${PREC_SUFFIX}${FORT_SUFFIX}
COMPONENT Development)
6 changes: 3 additions & 3 deletions FFTW3Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ endif ()
# Allows loading FFTW3 settings from another project
set (FFTW3_CONFIG_FILE "${CMAKE_CURRENT_LIST_FILE}")

set (FFTW3@PREC_SUFFIX@_LIBRARIES fftw3@PREC_SUFFIX@)
set (FFTW3@PREC_SUFFIX@_LIBRARY_DIRS @CMAKE_INSTALL_FULL_LIBDIR@)
set (FFTW3@PREC_SUFFIX@_INCLUDE_DIRS @CMAKE_INSTALL_FULL_INCLUDEDIR@)
set (FFTW3@PREC_SUFFIX@@FORT_SUFFIX@_LIBRARIES fftw3@PREC_SUFFIX@@FORT_SUFFIX@)
set (FFTW3@PREC_SUFFIX@@FORT_SUFFIX@_LIBRARY_DIRS @CMAKE_INSTALL_FULL_LIBDIR@)
set (FFTW3@PREC_SUFFIX@@FORT_SUFFIX@_INCLUDE_DIRS @CMAKE_INSTALL_FULL_INCLUDEDIR@)

include ("${CMAKE_CURRENT_LIST_DIR}/FFTW3LibraryDepends.cmake")

Expand Down
31 changes: 16 additions & 15 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
#===============================================================================

OPTIONS_AUTOMAKE=gnu
lib_LTLIBRARIES = libfftw3@PREC_SUFFIX@.la
lib_LTLIBRARIES = libfftw3@PREC_SUFFIX@@FORT_SUFFIX@.la

# pkgincludedir = $(includedir)/fftw3@PREC_SUFFIX@
# nodist_pkginclude_HEADERS = config.h

# recompile genfft if maintainer mode is true
if MAINTAINER_MODE
GENFFT = genfft
EXTRA_libfftw3@PREC_SUFFIX@_la_DEPENDENCIES = assert-shared-version-info
EXTRA_libfftw3@PREC_SUFFIX@@FORT_SUFFIX@_la_DEPENDENCIES = assert-shared-version-info
else
GENFFT =
endif
Expand Down Expand Up @@ -129,13 +129,13 @@ endif

if THREADS
if COMBINED_THREADS
COMBINED_THREADLIBS=threads/libfftw3@PREC_SUFFIX@_threads.la
COMBINED_THREADLIBS=threads/libfftw3@PREC_SUFFIX@@FORT_SUFFIX@_threads.la
endif
endif

libfftw3@PREC_SUFFIX@_la_SOURCES =
libfftw3@PREC_SUFFIX@@FORT_SUFFIX@_la_SOURCES =

libfftw3@PREC_SUFFIX@_la_LIBADD = \
libfftw3@PREC_SUFFIX@@FORT_SUFFIX@_la_LIBADD = \
kernel/libkernel.la \
dft/libdft.la \
dft/scalar/libdft_scalar.la \
Expand All @@ -155,38 +155,39 @@ libfftw3@PREC_SUFFIX@_la_LIBADD = \

if QUAD
# cannot use -no-undefined since dependent on libquadmath
libfftw3@PREC_SUFFIX@_la_LDFLAGS = -version-info @SHARED_VERSION_INFO@ $(ENVIRONMENT_LIBFFTW3_LDFLAGS)
libfftw3@PREC_SUFFIX@@FORT_SUFFIX@_la_LDFLAGS = -version-info @SHARED_VERSION_INFO@ $(ENVIRONMENT_LIBFFTW3_LDFLAGS)
else
libfftw3@PREC_SUFFIX@_la_LDFLAGS = -no-undefined -version-info \
libfftw3@PREC_SUFFIX@@FORT_SUFFIX@_la_LDFLAGS = -no-undefined -version-info \
@SHARED_VERSION_INFO@ $(ENVIRONMENT_LIBFFTW3_LDFLAGS)
endif

fftw3@PREC_SUFFIX@.pc: fftw.pc
cp -f fftw.pc fftw3@PREC_SUFFIX@.pc
fftw3@PREC_SUFFIX@@FORT_SUFFIX@.pc: fftw.pc
cp -f fftw.pc fftw3@PREC_SUFFIX@@FORT_SUFFIX@.pc
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = fftw3@PREC_SUFFIX@.pc
pkgconfig_DATA = fftw3@PREC_SUFFIX@@FORT_SUFFIX@.pc

FFTW3@PREC_SUFFIX@Config.cmake: $(top_srcdir)/FFTW3Config.cmake.in
FFTW3@PREC_SUFFIX@@FORT_SUFFIX@Config.cmake: $(top_srcdir)/FFTW3Config.cmake.in
$(SED) \
-e 's|[@]PREC_SUFFIX@|@PREC_SUFFIX@|g' \
-e 's|[@]FORT_SUFFIX@|@FORT_SUFFIX@|g' \
-e 's|[@]CMAKE_INSTALL_FULL_LIBDIR@|$(libdir)|g' \
-e 's|[@]CMAKE_INSTALL_FULL_INCLUDEDIR@|$(includedir)|g' \
$(top_srcdir)/FFTW3Config.cmake.in > $@
FFTW3@PREC_SUFFIX@ConfigVersion.cmake: $(top_srcdir)/FFTW3ConfigVersion.cmake.in
FFTW3@PREC_SUFFIX@@FORT_SUFFIX@ConfigVersion.cmake: $(top_srcdir)/FFTW3ConfigVersion.cmake.in
$(SED) \
-e 's|[@]FFTW_VERSION@|@PACKAGE_VERSION@|g' \
$(top_srcdir)/FFTW3ConfigVersion.cmake.in > $@
cmakedir = $(libdir)/cmake/fftw3
cmake_DATA = FFTW3@PREC_SUFFIX@Config.cmake FFTW3@PREC_SUFFIX@ConfigVersion.cmake
cmake_DATA = FFTW3@PREC_SUFFIX@@FORT_SUFFIX@Config.cmake FFTW3@PREC_SUFFIX@@FORT_SUFFIX@ConfigVersion.cmake

WISDOM_DIR = /etc/fftw
WISDOM = wisdom@PREC_SUFFIX@
WISDOM = wisdom@PREC_SUFFIX@@FORT_SUFFIX@

WISDOM_TIME=12 # default to 12-hour limit, i.e. overnight
WISDOM_FLAGS=--verbose --canonical --time-limit=$(WISDOM_TIME)

wisdom:
tools/fftw@PREC_SUFFIX@-wisdom -o $@ $(WISDOM_FLAGS)
tools/fftw@PREC_SUFFIX@@FORT_SUFFIX@-wisdom -o $@ $(WISDOM_FLAGS)

install-wisdom: wisdom
$(mkinstalldirs) $(WISDOM_DIR)
Expand Down
148 changes: 85 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,49 +36,54 @@ $ autoreconf --verbose --install --symlink --force

## Building FFTW3

### Notice
* To create a library for fortran, specify `--enable-linkfortran` at configure,
if the compiler option -Nclang is specified in the environment variable for
compile command or in the compilation profile file.

### Single precision
* Native compilation using Fujitsu compiler (AArch64 target).

```
$ ./configure \
CC="fcc" \
F77="frt" \
CFLAGS='-Nclang -Ofast' \
FFLAGS='-Kfast' \
--enable-sve \
--enable-armv8-cntvct-el0 \
--enable-float \
--enable-fma \
--enable-fortran \
--enable-openmp \
--enable-shared \
--prefix="$INSTALL_PATH" \
--libdir="$INSTALL_PATH/lib64" \
ac_cv_prog_f77_v='-###' \
$ ./configure \
CC="fcc" \
F77="frt" \
CFLAGS='-Nclang -Ofast -ffj-no-fast-matmul' \
FFLAGS='-Kfast' \
--enable-sve \
--enable-armv8-cntvct-el0 \
--enable-float \
--enable-fma \
--enable-fortran \
--enable-openmp \
--enable-shared \
--prefix="$INSTALL_PATH" \
--libdir="$INSTALL_PATH/lib64" \
ac_cv_prog_f77_v='-###' \
OPENMP_CFLAGS='-Kopenmp'
$ make -j30
```

* Cross compilation using Fujitsu compiler (AArch64 target).

```
$ ./configure \
CC="fccpx" \
F77="frtpx" \
CFLAGS='-Nclang -Ofast' \
FFLAGS='-Kfast' \
--host=aarch64-unknown-linux-gnu \
--build=x86_64-cross-linux-gnu \
--enable-sve \
--enable-armv8-cntvct-el0 \
--enable-float \
--enable-fma \
--enable-fortran \
--enable-openmp \
--enable-shared \
--prefix="$INSTALL_PATH" \
--libdir="$INSTALL_PATH/lib64" \
ac_cv_prog_f77_v='-###' \
$ ./configure \
CC="fccpx" \
F77="frtpx" \
CFLAGS='-Nclang -Ofast -ffj-no-fast-matmul' \
FFLAGS='-Kfast' \
--host=aarch64-unknown-linux-gnu \
--build=x86_64-cross-linux-gnu \
--enable-sve \
--enable-armv8-cntvct-el0 \
--enable-float \
--enable-fma \
--enable-fortran \
--enable-openmp \
--enable-shared \
--prefix="$INSTALL_PATH" \
--libdir="$INSTALL_PATH/lib64" \
ac_cv_prog_f77_v='-###' \
OPENMP_CFLAGS='-Kopenmp'
$ make -j30
```
Expand All @@ -87,43 +92,43 @@ $ make -j30
* Native compilation using Fujitsu compiler (AArch64 target).

```
$ ./configure \
CC="fcc" \
F77="frt" \
CFLAGS='-Nclang -Ofast' \
FFLAGS='-Kfast' \
--enable-sve \
--enable-armv8-cntvct-el0 \
--enable-fma \
--enable-fortran \
--enable-openmp \
--enable-shared \
--prefix="$INSTALL_PATH" \
--libdir="$INSTALL_PATH/lib64" \
ac_cv_prog_f77_v='-###' \
$ ./configure \
CC="fcc" \
F77="frt" \
CFLAGS='-Nclang -Ofast -ffj-no-fast-matmul' \
FFLAGS='-Kfast' \
--enable-sve \
--enable-armv8-cntvct-el0 \
--enable-fma \
--enable-fortran \
--enable-openmp \
--enable-shared \
--prefix="$INSTALL_PATH" \
--libdir="$INSTALL_PATH/lib64" \
ac_cv_prog_f77_v='-###' \
OPENMP_CFLAGS='-Kopenmp'
$ make -j30
```

* Cross compilation using Fujitsu compiler (AArch64 target).

```
$ ./configure \
CC="fccpx" \
F77="frtpx" \
CFLAGS='-Nclang -Ofast' \
FFLAGS='-Kfast' \
--host=aarch64-unknown-linux-gnu \
--build=x86_64-cross-linux-gnu \
--enable-sve \
--enable-armv8-cntvct-el0 \
--enable-fma \
--enable-fortran \
--enable-openmp \
--enable-shared \
--prefix="$INSTALL_PATH" \
--libdir="$INSTALL_PATH/lib64" \
ac_cv_prog_f77_v='-###' \
$ ./configure \
CC="fccpx" \
F77="frtpx" \
CFLAGS='-Nclang -Ofast -ffj-no-fast-matmul' \
FFLAGS='-Kfast' \
--host=aarch64-unknown-linux-gnu \
--build=x86_64-cross-linux-gnu \
--enable-sve \
--enable-armv8-cntvct-el0 \
--enable-fma \
--enable-fortran \
--enable-openmp \
--enable-shared \
--prefix="$INSTALL_PATH" \
--libdir="$INSTALL_PATH/lib64" \
ac_cv_prog_f77_v='-###' \
OPENMP_CFLAGS='-Kopenmp'
$ make -j30
```
Expand Down Expand Up @@ -154,12 +159,29 @@ $ make install
| Double precision and sequential version   | -lfftw3 -lm |
| Double precision and thread-parallel version | -lfftw3_omp -lfftw3 -lm |

* If you specified `--enable-linkfortran` at configure, compile with one of the
following options.

| FFTW3 libraries       | Options |
| --------------------------------------------- | ----------------------------------------- |
| Single precision and sequential version | -lfftw3f_fortran -lm |
| Single precision and thread-parallel version | -lfftw3f_fortran_omp -lfftw3f_fortran -lm |
| Double precision and sequential version   | -lfftw3_fortran -lm |
| Double precision and thread-parallel version | -lfftw3_fortran_omp -lfftw3_fortran -lm |

## Example

* Case with the single precision and sequential library.

```
$ frt a.f -L$(INSTALL_PATH)/lib64 -lfftw3f -lm
$ fcc a.c -L$(INSTALL_PATH)/lib64 -lfftw3f -lm
```

* If `--enable-linkfortran` is specified at configure, case with
the single precision and sequential library.

```
$ frt a.f -L$(INSTALL_PATH)/lib64 -lfftw3f_fortran -lm
```

# License
Expand Down
27 changes: 27 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,33 @@ if test "$with_combined_threads" = yes; then
fi
fi

#LINKFORTRAN=""
FORT_SUFFIX=""
dnl -----------------------------------------------------------------------
dnl linkfortran option add
AC_ARG_ENABLE(linkfortran, [AC_HELP_STRING([--enable-linkfortran],[enable to link fujitsu fortran runtime libraries])], enable_linkfortran=$enableval, enable_linkfortran=no)
if test "$enable_linkfortran"x = "yes"x; then
case "${host_cpu}" in
aarch64)
case "${CC}" in
fcc*)
archive_expsym_cmds="$archive_expsym_cmds --linkfortran"
archive_cmds="$archive_cmds --linkfortran"
FORT_SUFFIX=_fortran
;;
esac
;;
*)
AC_MSG_ERROR([Do not specify this option])
;;
esac
fi

AC_SUBST(FORT_SUFFIX)
AM_CONDITIONAL(LINKFORTRAN, test "$enable_linkfortran" = "yes")



dnl Check for threads library...
THREADLIBS=""
if test "$enable_threads" = "yes"; then
Expand Down
2 changes: 1 addition & 1 deletion fftw.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ includedir=@includedir@
Name: FFTW
Description: fast Fourier transform library
Version: @VERSION@
Libs: -L${libdir} -lfftw3@PREC_SUFFIX@ @LIBQUADMATH@
Libs: -L${libdir} -lfftw3@PREC_SUFFIX@@FORT_SUFFIX@ @LIBQUADMATH@
Libs.private: -lm
Cflags: -I${includedir}
Loading

0 comments on commit 3922f7c

Please sign in to comment.