Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using CMake with ifort compiler

I am using CMake 2.8.7 on a Linux machine with Intel 11.0 compilers. I am trying to use CMake for the first time as I would like to build this project on both Windows and Linux machines.

I though of using a simple approach first and used a standard Hello World example: My src/HelloWorld.f90:

!Test helloworld in Fortran using Cmake
program hello
    print *, "Hello World!"
end program hello

My main CMakeLists.txt:

# States that CMake required version must be greater than 2.8.7
cmake_minimum_required(VERSION 2.8.7)
enable_language (Fortran)
project(helloworld Fortran)
add_subdirectory(src)
SET_TARGET_PROPERTIES(helloworld PROPERTIES LINKER_LANGUAGE FORTRAN)

My src/CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.7)

# Include the directory itself as a path to include directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)

# For a large number of source files you can create it in a simpler way
# using file() function:
file(GLOB helloworld_SOURCES *.f90)

I still get an error which says CMAKE_FORTRAN_LINK_EXECUTABLE variable missing. I looked at Abinader's CMake tutorial#1, but haven't had success so far.

any suggestions?? Thanks in advance !

like image 386
cuda_hpc80 Avatar asked Apr 16 '26 07:04

cuda_hpc80


1 Answers

Not a direct answer, as I've never used fortran with cmake, but I can see a few issues here.

First of all: where is your target helloworld defined? project is not a target.

Secondly: where do you use helloworld_SOURCES variable?

Try a more regular way. In your src/CMakeLists.txt add line at the end of file with:

add_executable(helloworld ${helloworld_SOURCES})

Also remove SET_TARGET_PROPERTIES(helloworld PROPERTIES LINKER_LANGUAGE FORTRAN) from main one as it should not be necessary.

Last advice: try not to use file(GLOB ). It is better to define list of all files manualy.

like image 57
Michał Walenciak Avatar answered Apr 23 '26 21:04

Michał Walenciak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!