Problems with fortran an Xcode generator

Fabian188
Wed, 26 Jun 2024 15:29:42 +0000
Usage

I don’t know if this a bug, principally not possible or if I’m doing something wrong.

I have a C,C++,Fortran cmake project which builds nicely with Apple clang and gfortran from brew on macOS.

Usually I use Eclipse with external make project but now I want to try Xcode.

I need to give the compilers and run
cmake -G Xcode -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang -DCMAKE_Fortran_COMPILER=gfortran ..
and get

-- Using CMake 3.26.3 with generator Xcode
-- The C compiler identification is AppleClang 15.0.0.15000309
-- The CXX compiler identification is AppleClang 15.0.0.15000309
-- The Fortran compiler identification is unknown
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Checking whether Fortran compiler has -isysroot
-- Checking whether Fortran compiler has -isysroot - yes
-- Checking whether Fortran compiler supports OSX deployment target flag
-- Checking whether Fortran compiler supports OSX deployment target flag - yes
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - failed
-- Check for working Fortran compiler: /opt/homebrew/bin/gfortran
-- Check for working Fortran compiler: /opt/homebrew/bin/gfortran - broken
CMake Error at /opt/homebrew/Cellar/cmake/3.26.3/share/cmake/Modules/CMakeTestFortranCompiler.cmake:59 (message):
  The Fortran compiler

    "/opt/homebrew/bin/gfortran"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /Users/fwein/code/cfs/xcode/CMakeFiles/CMakeScratch/TryCompile-xSyBNY

    Run Build Command(s):/usr/bin/xcodebuild -project CMAKE_TRY_COMPILE.xcodeproj build -target cmTC_03712 -parallelizeTargets -configuration Debug -hideShellScriptEnvironment && Command line invocation:
        /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -project CMAKE_TRY_COMPILE.xcodeproj build -target cmTC_03712 -parallelizeTargets -configuration Debug -hideShellScriptEnvironment

    User defaults from command line:
        HideShellScriptEnvironment = YES
        IDEPackageSupportUseBuiltinSCM = YES

    ComputeTargetDependencyGraph
    note: Building targets in dependency order
    note: Target dependency graph (1 target)
        Target 'cmTC_03712' in project 'CMAKE_TRY_COMPILE' (no dependencies)

    GatherProvisioningInputs

    CreateBuildDescription

    ExecuteExternalTool /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -v -E -dM -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -x c -c /dev/null

    Build description signature: 76ea46e32cab0d3dddb69af387d79758
    Build description path: /Users/fwein/code/cfs/xcode/CMakeFiles/CMakeScratch/TryCompile-xSyBNY/build/XCBuildData/76ea46e32cab0d3dddb69af387d79758.xcbuilddata
    CreateBuildDirectory /Users/fwein/code/cfs/xcode/CMakeFiles/CMakeScratch/TryCompile-xSyBNY/Debug
        cd /Users/fwein/code/cfs/xcode/CMakeFiles/CMakeScratch/TryCompile-xSyBNY/CMAKE_TRY_COMPILE.xcodeproj
        builtin-create-build-directory /Users/fwein/code/cfs/xcode/CMakeFiles/CMakeScratch/TryCompile-xSyBNY/Debug

    CreateBuildDirectory /Users/fwein/code/cfs/xcode/CMakeFiles/CMakeScratch/TryCompile-xSyBNY/build
        cd /Users/fwein/code/cfs/xcode/CMakeFiles/CMakeScratch/TryCompile-xSyBNY/CMAKE_TRY_COMPILE.xcodeproj
        builtin-create-build-directory /Users/fwein/code/cfs/xcode/CMakeFiles/CMakeScratch/TryCompile-xSyBNY/build

    ClangStatCache /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang-stat-cache /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk /var/folders/q5/g9j2r7ps5tz94gkrhf85mqbr0000gn/C/com.apple.DeveloperTools/15.4-15F31d/Xcode/SDKStatCaches.noindex/macosx14.5-23F73-7e3fd6dc4171e65dbd154ba8db3956d2.sdkstatcache
        cd /Users/fwein/code/cfs/xcode/CMakeFiles/CMakeScratch/TryCompile-xSyBNY/CMAKE_TRY_COMPILE.xcodeproj
        /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang-stat-cache /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -o /var/folders/q5/g9j2r7ps5tz94gkrhf85mqbr0000gn/C/com.apple.DeveloperTools/15.4-15F31d/Xcode/SDKStatCaches.noindex/macosx14.5-23F73-7e3fd6dc4171e65dbd154ba8db3956d2.sdkstatcache

    CreateBuildDirectory /Users/fwein/code/cfs/xcode/CMakeFiles/CMakeScratch/TryCompile-xSyBNY/build/EagerLinkingTBDs/Debug
        cd /Users/fwein/code/cfs/xcode/CMakeFiles/CMakeScratch/TryCompile-xSyBNY/CMAKE_TRY_COMPILE.xcodeproj
        builtin-create-build-directory /Users/fwein/code/cfs/xcode/CMakeFiles/CMakeScratch/TryCompile-xSyBNY/build/EagerLinkingTBDs/Debug

    RegisterExecutionPolicyException /Users/fwein/code/cfs/xcode/CMakeFiles/CMakeScratch/TryCompile-xSyBNY/Debug/cmTC_03712 (in target 'cmTC_03712' from project 'CMAKE_TRY_COMPILE')
        cd /Users/fwein/code/cfs/xcode/CMakeFiles/CMakeScratch/TryCompile-xSyBNY
        builtin-RegisterExecutionPolicyException /Users/fwein/code/cfs/xcode/CMakeFiles/CMakeScratch/TryCompile-xSyBNY/Debug/cmTC_03712
    error: Build input file cannot be found: '/Users/fwein/code/cfs/xcode/CMakeFiles/CMakeScratch/TryCompile-xSyBNY/Debug/cmTC_03712'. Did you forget to declare this file as an output of a script phase or custom build rule which produces it? (in target 'cmTC_03712' from project 'CMAKE_TRY_COMPILE')

    warning: no rule to process file '/Users/fwein/code/cfs/xcode/CMakeFiles/CMakeScratch/TryCompile-xSyBNY/testFortranCompiler.f' of type 'sourcecode.fortran.f90' for architecture 'arm64' (in target 'cmTC_03712' from project 'CMAKE_TRY_COMPILE')
    ** BUILD FAILED **


    The following build commands failed:
    	RegisterExecutionPolicyException /Users/fwein/code/cfs/xcode/CMakeFiles/CMakeScratch/TryCompile-xSyBNY/Debug/cmTC_03712 (in target 'cmTC_03712' from project 'CMAKE_TRY_COMPILE')
    (1 failure)

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:59 (project)

-- Configuring incomplete, errors occurred!

I cannot reproduce, as /Users/fwein/code/cfs/xcode/CMakeFiles/CMakeScratch/ is empty.

/opt/homebrew/bin/gfortran is the correct compiler, I use for the default Unix Makefiles generator

3 posts - 2 participants