datetime-fortran icon indicating copy to clipboard operation
datetime-fortran copied to clipboard

CMake uses different compiler flags to autotools

Open harshula opened this issue 2 years ago • 6 comments

Please note that the static library built via CMake is built with different flags compared to when it is built with Autotools.

e.g. Cmake:

/usr/bin/f95   -O3 -DNDEBUG -O3 -Jinclude -c [...]/datetime-fortran.git/src/datetime_module.f90 -o CMakeFiles/datetime.dir/src/datetime_module.f90.o
...
/usr/bin/ar qc lib/libdatetime.a CMakeFiles/datetime.dir/src/datetime_module.f90.o
/usr/bin/ranlib lib/libdatetime.a

e.g. Autotools:

gfortran -c -Wall datetime_module.f90
...
ar ruv libdatetime.a datetime_module.o
ar: `u' modifier ignored since `D' is the default (see `U')
ar: creating libdatetime.a
a - datetime_module.o

Environment:

$ gfortran --version
GNU Fortran (Debian 12.2.0-3) 12.2.0

$ ar --version
GNU ar (GNU Binutils for Debian) 2.39

harshula avatar Oct 14 '22 12:10 harshula

Thanks! As I understand it #76 doesn't address this, right? We can easily add a default -O3 to the autotools build.

milancurcic avatar Oct 14 '22 15:10 milancurcic

https://github.com/wavebitscientific/datetime-fortran/pull/75 does not address this issue.

harshula avatar Oct 15 '22 10:10 harshula

Is -O3 preferred over -O2 by the fortran community?

harshula avatar Oct 15 '22 11:10 harshula

Notes:

$ gfortran --version
GNU Fortran (GCC) 8.5.0 20210514 (Red Hat 8.5.0-10)

$ ar --version
GNU ar version 2.30-113.el8
/bin/f95   -O3 -DNDEBUG -O3 -Jinclude -c [...]/datetime-fortran.git/src/datetime_module.f90 -o CMakeFiles/datetime.dir/src/datetime_module.f90.o
...
/bin/ar qc lib/libdatetime.a CMakeFiles/datetime.dir/src/datetime_module.f90.o
/bin/ranlib lib/libdatetime.a
gfortran -c -Wall datetime_module.f90
...
ar ruv libdatetime.a datetime_module.o
ar: creating libdatetime.a
a - datetime_module.o

harshula avatar Oct 17 '22 01:10 harshula

I think -O3 is fine to use as a default.

milancurcic avatar Oct 17 '22 14:10 milancurcic

I haven't seen any problems with -O3 on modern compilers. There are corner cases where -O2 is preferred by certain projects or certain applications, but those users already know that can can apply option cmake -DCMAKE_Fortran_FLAGS=-O2

scivision avatar Jan 31 '23 19:01 scivision