[CMake] Mixing C and Fortran in Visual Studio with Intel Visual Fortran

KEVIN.SISCO at Shell.Com KEVIN.SISCO at Shell.Com
Thu Jan 25 17:05:31 EST 2007


I'm having trouble using CMake in a project with mixed Fortran and C code 
and I'm hoping someone here can help.  I am using Visual Studio 2005 and 
Intel Visual Fortran 9.1.  Sorry for the length of this post.

1) The test for the Fortran compiler is failing indicating a broken compiler.   
 It breaks during the link stage with the following error:

Microsoft (R) Visual Studio Version 8.0.50727.42.
Copyright (C) Microsoft Corp 1984-2005. All rights reserved.
------ Build started: Project: cmTryCompileExec, Configuration: Debug Win32 ------
Building Fortran object testFortranCompiler.obj
Linking Fortran target cmTryCompileExec.exe
Fatal error cannot open "ifconsol"
ifort: error: problem during multi-file optimization compilation (code 1)
Project : error PRJ0019: A tool returned an error code from "Linking Fortran tar
get cmTryCompileExec.exe"
Build log was saved at ...
\cmTryCompileExec.dir\Debug\BuildLog.htm"
cmTryCompileExec - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========

Searching the net revealed that this problem is caused by a missing or 
invalid "LIB" environment variable.   The LIB environment variable points 
to the location of the Intel libraries.   LIB is set in my environment and 
the link does in fact work outside of cmake generated projects.  Is it
possible that cmake is somehow resetting this environment variable?

Even though the generator complains the Fortran compiler is broken I 
can still generate projects using CMakeSetup.exe which leads to 
my next set of problems.

2) The generated project is trying to compile my .c files with the fortran 
compiler.  For example:

Building Fortran object lock.obj
Intel(R) Fortran Compiler for 32-bit applications, Version 9.1    Build 20060323Z Package ID: W_FC_P_9.1.023 
Copyright (C) 1985-2006 Intel Corporation.  All rights reserved.
ifort: Command line warning: unrecognized source type '..\lock.c'; object file assumed
ifort: Command line warning: no action performed for specified object file(s)

How do I specify that the .c file should get compiled with cl.exe?

3) Most of my Fortran files get built but it puts the .obj files in the 
"wrong" directory.   It is creating them in ${CMAKE_CURRENT_BINARY_DIR} 
instead of the ${CMAKE_CURRENT_BINARY_DIR}\<project>.dir\Debug directory.

How do I specify that the object files go in the directory with the .c objects?

Thanks for any help,
Kevin

Here is the CMakeLists.txt file I'm using:

# =========

ENABLE_LANGUAGE(Fortran)

#
# source files
#
SET(FORTRAN_SOURCES
  <list of .f files>
)

SET(C_SOURCES
   <list of .c files>
)

SET(SOURCE_FILES ${FORTRAN_SOURCES} ${C_SOURCES})

#
# add the fortran source files to the Source Files folder
#
SOURCE_GROUP("Source Files" REGULAR_EXPRESSION "\\.(F|f)" FILES ${SOURCE_FILES})

#
# make the header file list
#
FILE(GLOB C_HEADER_FILES ${Project_SOURCE_DIR}/lib/include/sio/*.h)
FILE(GLOB FORTRAN_HEADER_FILES ${Project_SOURCE_DIR}/lib/include/sio/*.inc)
SET(HEADER_FILES ${C_HEADER_FILES} ${FORTRAN_HEADER_FILES})
SOURCE_GROUP("Header Files" REGULAR_EXPRESSION "\\.(H|h|inc)" FILES ${HEADER_FILES})
SET(SOURCE_FILES ${SOURCE_FILES} ${HEADER_FILES})

#
# library name
#
ADD_LIBRARY(libmixed SHARED ${SOURCE_FILES})

IF (WIN32)
   SET(CMAKE_Fortran_FLAGS ${CMAKE_Fortran_FLAGS} /fpp ) 
   SET(CMAKE_Fortran_FLAGS ${CMAKE_Fortran_FLAGS} /traceback)
   SET(CMAKE_Fortran_FLAGS ${CMAKE_Fortran_FLAGS} /check:bounds)
   SET(CMAKE_Fortran_FLAGS ${CMAKE_Fortran_FLAGS} /threads)
   SET(CMAKE_Fortran_FLAGS ${CMAKE_Fortran_FLAGS} /MDd)   
   SET(CMAKE_Fortran_FLAGS ${CMAKE_Fortran_FLAGS} /extfor:F)
   SET(CMAKE_Fortran_FLAGS ${CMAKE_Fortran_FLAGS} /Qvc8)
   SET(CMAKE_Fortran_FLAGS ${CMAKE_Fortran_FLAGS} /assume:underscore)
ENDIF (WIN32)

# =========

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/cmake/attachments/20070125/204f0570/attachment.html


More information about the CMake mailing list