Questions on stdlib CMake with MSVS & ifx in Windows

Hello everyone,

I’m trying to build stdlib with MSVS 2022 Version 17.14.25, ifx 2025.3, CMake version 4.3.0-rc2 in Win11 x64 with limited success. Out of the box, CMake can’t find the identity of the Fortran compiler, (even though on the next line of output it lists the details of the IntelLLVM compiler). My workaround is to add a CMakeSettings.json file in stdlib root:

{
  "configurations": [
    {
      "name": "x64-Debug",
      "generator": "Visual Studio 17 2022 Win64",
      "configurationType": "Debug",
      "inheritEnvironments": [ "msvc_x64_x64" ],
      "buildRoot": "${projectDir}\\out\\build\\${name}",
      "installRoot": "${projectDir}\\out\\install\\${name}",
      "cmakeCommandArgs": "-T \"fortran=ifx\"",
      "buildCommandArgs": "",
      "ctestCommandArgs": "",
      "variables": [
        {
          "name": "CMAKE_Fortran_FLAGS",
          "value": "/fpp",
          "type": "STRING"
        }
      ]
    }
  ]
}

I couldn’t get the Ninja generator to work at all, so used the VS generator. The cmakeCommandArgs -T fortran=ifx seems to allow CMake to generate. (I have the environment variable FC=ifx, but that didn’t help.) Adding the compiler flag /fpp was needed as the preprocessor wasn’t operating on .F90 files.

The generation output is:

1> CMake generation started for configuration: 'x64-Debug'.
1> Command line: "C:\WINDOWS\system32\cmd.exe" /c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe"  -G "Visual Studio 17 2022" -A x64  -DCMAKE_CONFIGURATION_TYPES:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\tn\source\repos\stdlib\out\install\x64-Debug" -DCMAKE_Fortran_FLAGS:STRING="/fpp"  -T "fortran=ifx" "C:\Users\tn\source\repos\stdlib" 2>&1"
1> Working directory: C:\Users\tn\source\repos\stdlib\out\build\x64-Debug
1> [CMake] -- Selecting Windows SDK version 10.0.26100.0 to target Windows 10.0.26200.
1> [CMake] -- The Fortran compiler identification is IntelLLVM 2025.3.2 with MSVC-like command-line
1> [CMake] -- The C compiler identification is MSVC 19.44.35222.0
1> [CMake] -- Detecting Fortran compiler ABI info
1> [CMake] -- Detecting Fortran compiler ABI info - done
1> [CMake] -- Determine Intel Fortran Compiler Implicit Link Path
1> [CMake] -- Determine Intel Fortran Compiler Implicit Link Path - done
1> [CMake] -- Check for working Fortran compiler: C:/Program Files (x86)/Intel/oneAPI/compiler/2025.3/bin/ifx.exe - skipped
1> [CMake] -- Detecting C compiler ABI info
1> [CMake] -- Detecting C compiler ABI info - done
1> [CMake] -- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/bin/Hostx64/x64/cl.exe - skipped
1> [CMake] -- Detecting C compile features
1> [CMake] -- Detecting C compile features - done
1> [CMake] -- Performing Test WITH_CBOOL
1> [CMake] -- Performing Test WITH_CBOOL - Success
1> [CMake] -- Performing Test WITH_QP
1> [CMake] -- Performing Test WITH_QP - Success
1> [CMake] -- Performing Test WITH_XDP
1> [CMake] -- Performing Test WITH_XDP - Failed
1> [CMake] -- Performing Test f18errorstop
1> [CMake] -- Performing Test f18errorstop - Failed
1> [CMake] -- Performing Test f03rank
1> [CMake] -- Performing Test f03rank - Success
1> [CMake] -- Performing Test f03real128
1> [CMake] -- Performing Test f03real128 - Success
1> [CMake] -- Enable stdlib module ANSI
1> [CMake] -- Enable stdlib module BITSETS
1> [CMake] -- Enable stdlib module HASHMAPS
1> [CMake] -- Enable stdlib module IO
1> [CMake] -- Enable stdlib module LINALG_ITERATIVE
1> [CMake] -- Enable stdlib module LOGGER
1> [CMake] -- Enable stdlib module QUADRATURE
1> [CMake] -- Enable stdlib module SPECIALMATRICES
1> [CMake] -- Enable stdlib module STRINGLIST
1> [CMake] -- Enable stdlib module STATS
1> [CMake] -- Enable stdlib module SYSTEM
1> [CMake] -- Searching for external BLAS/LAPACK
1> [CMake] -- Detected Intel MKL environment
1> [CMake] -- Looking for Fortran sgemm
1> [CMake] -- Looking for Fortran sgemm - not found
1> [CMake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
1> [CMake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
1> [CMake] -- Looking for pthread_create in pthreads
1> [CMake] -- Looking for pthread_create in pthreads - not found
1> [CMake] -- Looking for pthread_create in pthread
1> [CMake] -- Looking for pthread_create in pthread - not found
1> [CMake] -- Found Threads: TRUE
1> [CMake] -- Looking for Fortran sgemm
1> [CMake] -- Looking for Fortran sgemm - found
1> [CMake] -- Found BLAS: C:/Program Files (x86)/Intel/oneAPI/mkl/latest/lib/mkl_intel_lp64_dll.lib;C:/Program Files (x86)/Intel/oneAPI/compiler/latest/lib/libiomp5md.lib;C:/Program Files (x86)/Intel/oneAPI/mkl/latest/lib/mkl_intel_thread_dll.lib;C:/Program Files (x86)/Intel/oneAPI/mkl/latest/lib/mkl_core_dll.lib
1> [CMake] -- Looking for Fortran cheev
1> [CMake] -- Looking for Fortran cheev - found
1> [CMake] -- Found LAPACK: C:/Program Files (x86)/Intel/oneAPI/mkl/latest/lib/mkl_intel_lp64_dll.lib;C:/Program Files (x86)/Intel/oneAPI/compiler/latest/lib/libiomp5md.lib;C:/Program Files (x86)/Intel/oneAPI/mkl/latest/lib/mkl_intel_thread_dll.lib;C:/Program Files (x86)/Intel/oneAPI/mkl/latest/lib/mkl_core_dll.lib
1> [CMake] -- Found external BLAS: C:/Program Files (x86)/Intel/oneAPI/mkl/latest/lib/mkl_intel_lp64_dll.lib;C:/Program Files (x86)/Intel/oneAPI/compiler/latest/lib/libiomp5md.lib;C:/Program Files (x86)/Intel/oneAPI/mkl/latest/lib/mkl_intel_thread_dll.lib;C:/Program Files (x86)/Intel/oneAPI/mkl/latest/lib/mkl_core_dll.lib
1> [CMake] -- Found external LAPACK: C:/Program Files (x86)/Intel/oneAPI/mkl/latest/lib/mkl_intel_lp64_dll.lib;C:/Program Files (x86)/Intel/oneAPI/compiler/latest/lib/libiomp5md.lib;C:/Program Files (x86)/Intel/oneAPI/mkl/latest/lib/mkl_intel_thread_dll.lib;C:/Program Files (x86)/Intel/oneAPI/mkl/latest/lib/mkl_core_dll.lib
1> [CMake] -- Using standard 32-bit integer interface
1> [CMake] -- test-drive: Find installed package
1> [CMake] -- Retrieving test-drive from https://github.com/fortran-lang/test-drive
1> [CMake] CMake Deprecation Warning at out/build/x64-Debug/_deps/test-drive-src/CMakeLists.txt:14 (cmake_minimum_required):
1> [CMake]   Compatibility with CMake < 3.10 will be removed from a future version of
1> [CMake]   CMake.
1> [CMake] 
1> [CMake]   Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
1> [CMake]   to tell CMake that the project requires at least <min> but has been updated
1> [CMake]   to work with policies introduced by <max> or earlier.
1> [CMake] 
1> [CMake] 
1> [CMake] -- The CXX compiler identification is MSVC 19.44.35222.0
1> [CMake] -- Detecting CXX compiler ABI info
1> [CMake] -- Detecting CXX compiler ABI info - done
1> [CMake] -- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/bin/Hostx64/x64/cl.exe - skipped
1> [CMake] -- Detecting CXX compile features
1> [CMake] -- Detecting CXX compile features - done
1> [CMake] -- pkg-config: no .pc file found for BLAS, using linker flags: -lmkl_intel_lp64_dll;-liomp5md;-lmkl_intel_thread_dll;-lmkl_core_dll
1> [CMake] -- pkg-config: no .pc file found for LAPACK, using linker flags: -lmkl_intel_lp64_dll;-liomp5md;-lmkl_intel_thread_dll;-lmkl_core_dll
1> [CMake] -- Configuring done (196.0s)
1> [CMake] -- Generating done (5.4s)
1> [CMake] -- Build files have been written to: C:/Users/tn/source/repos/stdlib/out/build/x64-Debug
1> Extracted CMake variables.
1> Extracted source files and headers.
1> Extracted code model.
1> Extracted toolchain configurations.
1> Extracted includes paths.
1> CMake generation finished.

It appears to download test-drive on every generation.

On building there are about 9K errors, mostly because it did not find compiled modules for STDLIB_OPTVAL and STDLIB_KINDS. Repeating building gets most modules compiled but still some errors. There are 29 from not finding a stdlib_system .mod file when compiling source files and a series of subsidiary errors for bad symbols.

Error	#7002	Error in opening the compiled module file.  Check INCLUDE paths.   [STDLIB_SYSTEM]	C:\Users\tn\source\repos\stdlib\out\build\x64-Debug\stdlib	C:\Users\tn\source\repos\stdlib\test\system\test_subprocess.f90	

Looking in C:\Users\tn\source\repos\stdlib\out\build\x64-Debug\src\system shows two .c source files, but no .f90 source files. There are no files in the /mod_files/fortran_stdlib_system/ directory, but there is a /Debug/fortran_stdlib_system.lib file of 14764 bytes.

This is my first time working with CMake and I don’t know what the next steps might be to get stdlib to build. Any suggestions would be greatly appreciated.

Tim

2 Likes

OK, here’s an update. With MSVS 2022, this CMakeSettings.json file in the root directory gives a full build:

{
  "configurations": [
    {
      "name": "x64-Debug",
      "generator": "Ninja",
      "configurationType": "Debug",
      "inheritEnvironments": [ "msvc_x64_x64" ],
      "buildRoot": "${projectDir}\\out\\build\\${name}",
      "installRoot": "${projectDir}\\out\\install\\${name}",
      "buildCommandArgs": "",
      "ctestCommandArgs": "",
      "variables": [
        {
          "name": "CMAKE_Fortran_FLAGS",
          "value": "/fpp /MP /libs:dll /threads /dbglibs",
          "type": "STRING"
        },
        {
          "name": "CMAKE_C_FLAGS",
          "value": "/D_CRT_DECLARE_NONSTDC_NAMES /D_CRT_SECURE_NO_WARNINGS",
          "type": "STRING"
        }
      ],
      "cmakeCommandArgs": "-DCMAKE_Fortran_COMPILER=ifx "
    }
  ]
}

A MSVS generator can’t be used. stdlib_system contains both C and Fortran source files. The MSVS generator will not create a project file for two languages.

The ifx compiler does not recognize .F90 files as needing preprocessing, so the /fpp flag is needed.

Parallel compile can be done with the /MP flag.

Linking the C and Fortran .obj files in stdlib_system had errors from static/dynamic libraries being mixed. Those additional linking flags fixed that.

I’ve found it easiest to start the Intel oneAPI Command Prompt for Intel 64 and Visual Studio 2022 (in the Windows Start menu under Intel-oneAPI) then enter devenv to start MSVS. This sets all the environment variables.

One of the CMake scripts looks for the test-drive dependency in the stdlib/subprojects/test-drive/ folder, and if not found invokes Git to download a new copy. Which it puts into a \stdlib\out\build\x64-Debug_deps\test-drive-src directory, which it doesn’t find on the next build. Manually moving test-drive to stdlib/subprojects/test-drive/ fixed this.

I think that’s about it.

Cheers,

Tim

Looks to me like you’re on the right track, start VS from a Intel OneAPI prompt is how I typically work. You can just drive CMake from the OneAPI terminal as well. Stdlib require fypp, which is a Python based preprocessor, but I’m not aware of it requiring fypp based preprocessing, but I could be wrong there. In your OneAPI terminal, also make sure you can call python, as fypp needs it.

There is nothing per say wrong with CMakeSettings.json, but everyone is generally moving to CMakePresets.json. This is what my build preset looks like:

`{

“name”: “x64-release”,

“displayName”: “x64 Release”,

“description”: “Target Windows (64-bit) with the Visual Studio development environment. (RelWithDebInfo)”,

“inherits”: “x64-debug”,

“cacheVariables”: {

“CMAKE_BUILD_TYPE”: “RelWithDebInfo”,

“CMAKE_Fortran_FLAGS_RELWITHDEBINFO”: “/O3 /fp:fast /arch:AVX2 /Qopenmp”,

“CMAKE_VERBOSE_MAKEFILE”: “Off”,

“BUILD_TESTING”: “Off”,

“CMAKE_INCLUDE_PATH”: “C:/Work/Fortran/fypp-main/bin”

}

},`

Note that it turns of build testing, and explicitly tells Cmake where to find fypp. Including a CMakePresets.json would be a good addition to the Stdlib project if anyone wanted to tackle that.