FortranCInterface fails with CMP0056
This CMakeLists.txt
fails:
cmake_minimum_required(VERSION 3.10)
enable_language(C)
enable_language(CXX)
enable_language(Fortran)
INCLUDE(FortranCInterface)
FortranCInterface_VERIFY(CXX)
project("Dakota" NONE)
when run with this command line:
FFLAGS="-O -Wl,-rpath=/usr/local/lib/gcc9" \
FC=gfortran9 \
F77=gfortran9 \
FCFLAGS=-Wl,-rpath=/usr/local/lib/gcc9 \
cmake DCMAKE_C_COMPILER:STRING=cc -DCMAKE_CXX_COMPILER:STRING=c++ -DCMAKE_C_FLAGS:STRING="-O2 -pipe -fno-omit-frame-pointer -fstack-protector-strong -fno-strict-aliasing" -DCMAKE_C_FLAGS_DEBUG:STRING="-O2 -pipe -fno-omit-frame-pointer -fstack-protector-strong -fno-strict-aliasing" -DCMAKE_C_FLAGS_RELEASE:STRING="-O2 -pipe -fno-omit-frame-pointer -fstack-protector-strong -fno-strict-aliasing" -DCMAKE_CXX_FLAGS:STRING="-O2 -pipe -fno-omit-frame-pointer -fstack-protector-strong -fno-strict-aliasing -fno-omit-frame-pointer" -DCMAKE_CXX_FLAGS_DEBUG:STRING="-O2 -pipe -fno-omit-frame-pointer -fstack-protector-strong -fno-strict-aliasing -fno-omit-frame-pointer" -DCMAKE_CXX_FLAGS_RELEASE:STRING="-O2 -pipe -fno-omit-frame-pointer -fstack-protector-strong -fno-strict-aliasing -fno-omit-frame-pointer" -DCMAKE_EXE_LINKER_FLAGS:STRING=" -Wl,-rpath=/usr/local/lib/gcc9 -L/usr/local/lib/gcc9 -B/usr/local/bin -fstack-protector-strong" -DCMAKE_MODULE_LINKER_FLAGS:STRING=" -Wl,-rpath=/usr/local/lib/gcc9 -L/usr/local/lib/gcc9 -B/usr/local/bin -fstack-protector-strong" -DCMAKE_SHARED_LINKER_FLAGS:STRING=" -Wl,-rpath=/usr/local/lib/gcc9 -L/usr/local/lib/gcc9 -B/usr/local/bin -fstack-protector-strong" -DCMAKE_INSTALL_PREFIX:PATH=/usr/local -DCMAKE_BUILD_TYPE:STRING=Release -DTHREADS_HAVE_PTHREAD_ARG:BOOL=YES -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=YES -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON .
Failure log:
-- Check for working Fortran compiler: /usr/local/bin/gfortran9 - skipped
-- Checking whether /usr/local/bin/gfortran9 supports Fortran 90
-- Checking whether /usr/local/bin/gfortran9 supports Fortran 90 - yes
-- Detecting Fortran/C Interface
-- Detecting Fortran/C Interface - Found GLOBAL and MODULE mangling
-- Verifying Fortran/CXX Compiler Compatibility
-- Verifying Fortran/CXX Compiler Compatibility - Failed
CMake Error at /usr/local/share/cmake/Modules/FortranCInterface.cmake:383 (message):
The Fortran compiler:
/usr/local/bin/gfortran9
and the CXX compiler:
/usr/bin/c++
failed to compile a simple test project using both languages. The output
was:
Change Dir: /usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX
Run Build Command(s):/usr/local/bin/gmake VerifyFortranC && /usr/local/bin/cmake -S/usr/local/share/cmake/Modules/FortranCInterface/Verify -B/usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/bin/gmake -f CMakeFiles/Makefile2 VerifyFortranC
gmake[1]: Entering directory '/usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX'
/usr/local/bin/cmake -S/usr/local/share/cmake/Modules/FortranCInterface/Verify -B/usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/bin/cmake -E cmake_progress_start /usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX/CMakeFiles 6
/usr/local/bin/gmake -f CMakeFiles/Makefile2 CMakeFiles/VerifyFortranC.dir/all
gmake[2]: Entering directory '/usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX'
/usr/local/bin/gmake -f CMakeFiles/VerifyFortran.dir/build.make CMakeFiles/VerifyFortran.dir/depend
gmake[3]: Entering directory '/usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX'
cd /usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /usr/local/share/cmake/Modules/FortranCInterface/Verify /usr/local/share/cmake/Modules/FortranCInterface/Verify /usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX /usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX /usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX/CMakeFiles/VerifyFortran.dir/DependInfo.cmake
Scanning dependencies of target VerifyFortran
gmake[3]: Leaving directory '/usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX'
/usr/local/bin/gmake -f CMakeFiles/VerifyFortran.dir/build.make CMakeFiles/VerifyFortran.dir/build
gmake[3]: Entering directory '/usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX'
[ 16%] Building Fortran object CMakeFiles/VerifyFortran.dir/VerifyFortran.f.o
/usr/local/bin/gfortran9 -DVERIFY_CXX -I/usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX -O -Wl,-rpath=/usr/local/lib/gcc9 -O3 -DNDEBUG -O3 -c /usr/local/share/cmake/Modules/FortranCInterface/Verify/VerifyFortran.f -o CMakeFiles/VerifyFortran.dir/VerifyFortran.f.o
[ 33%] Linking Fortran static library libVerifyFortran.a
/usr/local/bin/cmake -P CMakeFiles/VerifyFortran.dir/cmake_clean_target.cmake
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/VerifyFortran.dir/link.txt --verbose=1
/usr/bin/ar qc libVerifyFortran.a CMakeFiles/VerifyFortran.dir/VerifyFortran.f.o
/usr/bin/ranlib libVerifyFortran.a
gmake[3]: Leaving directory '/usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX'
[ 33%] Built target VerifyFortran
/usr/local/bin/gmake -f CMakeFiles/VerifyFortranC.dir/build.make CMakeFiles/VerifyFortranC.dir/depend
gmake[3]: Entering directory '/usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX'
cd /usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX && /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" /usr/local/share/cmake/Modules/FortranCInterface/Verify /usr/local/share/cmake/Modules/FortranCInterface/Verify /usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX /usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX /usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX/CMakeFiles/VerifyFortranC.dir/DependInfo.cmake
Scanning dependencies of target VerifyFortranC
gmake[3]: Leaving directory '/usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX'
/usr/local/bin/gmake -f CMakeFiles/VerifyFortranC.dir/build.make CMakeFiles/VerifyFortranC.dir/build
gmake[3]: Entering directory '/usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX'
[ 50%] Building C object CMakeFiles/VerifyFortranC.dir/main.c.o
/usr/bin/cc -DVERIFY_CXX -I/usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX -O2 -pipe -fno-omit-frame-pointer -fstack-protector-strong -fno-strict-aliasing -O2 -pipe -fno-omit-frame-pointer -fstack-protector-strong -fno-strict-aliasing -o CMakeFiles/VerifyFortranC.dir/main.c.o -c /usr/local/share/cmake/Modules/FortranCInterface/Verify/main.c
[ 66%] Building C object CMakeFiles/VerifyFortranC.dir/VerifyC.c.o
/usr/bin/cc -DVERIFY_CXX -I/usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX -O2 -pipe -fno-omit-frame-pointer -fstack-protector-strong -fno-strict-aliasing -O2 -pipe -fno-omit-frame-pointer -fstack-protector-strong -fno-strict-aliasing -o CMakeFiles/VerifyFortranC.dir/VerifyC.c.o -c /usr/local/share/cmake/Modules/FortranCInterface/Verify/VerifyC.c
[ 83%] Building CXX object CMakeFiles/VerifyFortranC.dir/VerifyCXX.cxx.o
/usr/bin/c++ -DVERIFY_CXX -I/usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX -O2 -pipe -fno-omit-frame-pointer -fstack-protector-strong -fno-strict-aliasing -fno-omit-frame-pointer -O2 -pipe -fno-omit-frame-pointer -fstack-protector-strong -fno-strict-aliasing -fno-omit-frame-pointer -o CMakeFiles/VerifyFortranC.dir/VerifyCXX.cxx.o -c /usr/local/share/cmake/Modules/FortranCInterface/Verify/VerifyCXX.cxx
[100%] Linking CXX executable VerifyFortranC
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/VerifyFortranC.dir/link.txt --verbose=1
/usr/bin/c++ -O2 -pipe -fno-omit-frame-pointer -fstack-protector-strong -fno-strict-aliasing -fno-omit-frame-pointer -O2 -pipe -fno-omit-frame-pointer -fstack-protector-strong -fno-strict-aliasing -fno-omit-frame-pointer CMakeFiles/VerifyFortranC.dir/main.c.o CMakeFiles/VerifyFortranC.dir/VerifyC.c.o CMakeFiles/VerifyFortranC.dir/VerifyCXX.cxx.o -o VerifyFortranC -L/usr/local/bin -L/usr/local/lib/gcc9/gcc/x86_64-portbld-freebsd12.1/9.3.0 libVerifyFortran.a -lgfortran -lssp_nonshared -lquadmath
ld: error: unable to find library -lgfortran
ld: error: unable to find library -lquadmath
c++: error: linker command failed with exit code 1 (use -v to see invocation)
gmake[3]: *** [CMakeFiles/VerifyFortranC.dir/build.make:137: VerifyFortranC] Error 1
gmake[3]: Leaving directory '/usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX'
gmake[2]: *** [CMakeFiles/Makefile2:100: CMakeFiles/VerifyFortranC.dir/all] Error 2
gmake[2]: Leaving directory '/usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX'
gmake[1]: *** [CMakeFiles/Makefile2:107: CMakeFiles/VerifyFortranC.dir/rule] Error 2
gmake[1]: Leaving directory '/usr/ports/math/dakota/x/CMakeFiles/FortranCInterface/VerifyCXX'
gmake: *** [Makefile:140: VerifyFortranC] Error 2
Call Stack (most recent call first):
CMakeLists.txt:8 (FortranCInterface_VERIFY)
But if 3.10
in cmake_minimum_required(VERSION 3.10)
is replaced with 3.1.0
- the failure goes away.
I spotted this in one of the FreeBSD ports that was breaking because of the line cmake_minimum_required(VERSION 3.10)
in the project's CMakeLists.txt
. The port has the line USES=cmake fortran compiler:c++17-lang
in it.
Based on the docs @ https://cmake.org/cmake/help/latest/command/cmake_minimum_required.html some policy settings might be affected by the version. But what is the reason that the command fails?
OS: FreeBSD 12.2
cmake-3.18.3
clang-10
gcc9-9.3.0_1
Edited by Brad King