- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We use cmake to create our Linux builds and a Visual Studio 2022 solution for Windows. I was experimenting with cmake on Windows (3.26.4-msvc4, the one installed with VS 2022) and noticed that it is picking up an older version of ifort 2021.7 instead of ifx 2024.1, which is what the Linux build uses. Any ideas how to convince cmake to use the correct compiler?
This is the output from cmake -B:
-- CMAKE_GENERATOR is Visual Studio 17 2022
-- ONEAPI_COMPILER_VER = latest
-- INTELMKL is C:\Program Files (x86)\Intel\oneAPI\mkl\latest
-- INTELCOMPILER is C:\Program Files (x86)\Intel\oneAPI\compiler\latest
-- CMAKE_Fortran_COMPILER is ifx
-- Fortran_VENDOR is Intel
-- CMAKE_BUILD_TYPE is Debug
-- CMAKE_Fortran_COMPILER_VERSION is 2021.7.0.20220726
-- Setting build flags for Intel Fortran
This is the start of the CMakeLists.txt (I believe the find_package statement is responsible for setting the compiler version):
cmake_minimum_required(VERSION 3.9.0)
# Version 3.26 needed to support LLVM LTO in ifx, but requiring it as a minimum causes a link error (?)
# This targets Linux only at present, use Visual Studio for Windows
# There used to be support for GNU Fortran under MSYS2/mingw64 - WSL made this redundant
# By default, uses Intel Fortran Compiler (ifx)
# The Intel compilers also assume you have Intel MKL installed
# You can also use GNU Fortran (gfortran); this currently assumes MKL is not installed, so uses OpenBLAS and LAPACK instead.
set (CMAKE_CXX_STANDARD 11)
# Only support "Unix Makefiles", the default on Linux, at present.
# On Windows, the default generator is "Visual Studio 17 2022".
message(STATUS "CMAKE_GENERATOR is ${CMAKE_GENERATOR}")
# Where is MKL?
if (DEFINED ENV{MKLROOT})
set (INTELMKL "$ENV{MKLROOT}")
endif()
# Where are the Intel compilers?
if (DEFINED ENV{CMPLR_ROOT})
set (INTELCOMPILER "$ENV{CMPLR_ROOT}")
cmake_path(GET INTELCOMPILER FILENAME ONEAPI_COMPILER_VER)
message(STATUS "ONEAPI_COMPILER_VER = ${ONEAPI_COMPILER_VER}")
endif()
if (NOT DEFINED INTELMKL)
message(STATUS "INTELMKL is not installed")
else()
message(STATUS "INTELMKL is ${INTELMKL}")
endif()
if (NOT DEFINED INTELCOMPILER)
message(STATUS "Intel compilers are not installed")
else()
message(STATUS "INTELCOMPILER is ${INTELCOMPILER}")
endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out/lib)
file(MAKE_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
file(MAKE_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if (NOT DEFINED CMAKE_Fortran_COMPILER)
if (DEFINED INTELCOMPILER)
# Default to IFX - ifort is deprecated in OneAPI 2024.4 and version reporting is unreliable, so we no longer use it
set (CMAKE_Fortran_COMPILER ifx)
else()
# Default to GNU Fortran if there is no Intel compiler available
set (CMAKE_Fortran_COMPILER gfortran)
endif()
endif()
message(STATUS "CMAKE_Fortran_COMPILER is ${CMAKE_Fortran_COMPILER}")
if (CMAKE_GENERATOR STREQUAL "Visual Studio 17 2022")
set (Target_OS "Windows")
else()
set (Target_OS "Linux")
endif()
if (Target_OS STREQUAL Windows)
set (CMAKE_CUDA_COMPILER "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.7/bin/nvcc.exe")
else()
set (CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc)
endif()
set (CMAKE_CUDA_STANDARD 14)
project (sim Fortran C CXX CUDA)
find_package(OpenMP REQUIRED)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am making some progress - it looks like you need cmake 3.29. From the release notes:
Visual Studio Generators now support selecting between the Intel oneAPI Fortran compiler (ifx) and the Intel classic Fortran compiler (ifort) using a fortran= field in CMAKE_GENERATOR_TOOLSET.
cmake is still picking up the earliest installed version of the compiler, but as I have removed older versions, this is now ifx 2024.0 (which is what we use for production).
Once I mapped some Linux compile flags to their Windows equivalents and set some dependencies for SHARED (DLL) libraries I got the Debug build type to build OK.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just to clarify, I do have OneAPI 2024.1 installed on Windows, but I also have 2024.0, 2023.2.0, 2023.1.0, 2023.0.0 & 2023.2.0 installed.
On Linux, I just have OneAPI 2024.0 and 2024.1.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am making some progress - it looks like you need cmake 3.29. From the release notes:
Visual Studio Generators now support selecting between the Intel oneAPI Fortran compiler (ifx) and the Intel classic Fortran compiler (ifort) using a fortran= field in CMAKE_GENERATOR_TOOLSET.
cmake is still picking up the earliest installed version of the compiler, but as I have removed older versions, this is now ifx 2024.0 (which is what we use for production).
Once I mapped some Linux compile flags to their Windows equivalents and set some dependencies for SHARED (DLL) libraries I got the Debug build type to build OK.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page