[CMake] FW: building a mixed language programm with CMake

Denis Scherbakov denis_scherbakov at yahoo.com
Wed Jun 10 05:38:58 EDT 2009


> Thanks, that helped, but I still have troubles to set the
> options right:
> Compiling my code "manually", it takes the
> following commands:
> 
> gfortran -c hello.f90
> g++ -lgfortran hello.o test.cxx -o test

Actually this should look like:
gfortran -c hello.f90
g++ -c test.cxx
g++ -lgfortran hello.o test.o -o test
 
> Well, that´s my CMakeLists.txt for now:
> 
> cmake_minimum_required(VERSION 2.4)
> project(TEST Fortran)
> 
> SET(TEST_SRCS test.cxx)
> SET(OBJECTS hello.f90)

You need to work only with sources. Forget about object files.
Here is your CMakeLists.txt:

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(TEST Fortran)

SET(TEST_SRCS test.cxx hello.f90)
 
ADD_EXECUTABLE(test  ${TEST_SRCS})
TARGET_LINK_LIBRARIES(test  gfortran)


# NOT NEDDED: SET_TARGET_PROPERTIES(hi PROPERTIES LINKER_LANGUAGE C)
# NOT NEEDED: CMAKE_EXE_LINKER_FLAGS: -lgfortran -o
# Only if you have one more fortran compiler: CMAKE_Fortran_COMPILER: /usr/bin/gfortran
# NOT NEEDED: CMAKE_Fortran_FLAGS: -c

> which looks fine, but if my executable is build, where does
> it go? I set the EXECUTABLE_OUTPUT_PATH to the directory
> I´m working in,
> but the executable "hi" does not show up..

Compiled executable now is in build directory. In your case it should
be in current directory.
 
Please, reply to all, so CMake mailing list gets also included.

Denis



      


More information about the CMake mailing list