[CMake] making executible in mixed C/fortran project

Michael Hertling mhertling at online.de
Fri Nov 12 08:17:50 EST 2010


On 11/12/2010 02:46 PM, luxInteg wrote:
> Greetings,
> 
> I am learning cmake
> 
> I am building an executable  which needs to   first compile a C program  and 
> then recompiling the object file   with another file in fortran.
> 
> 
> Here is  an excerpt from a unix makefile I am attempt to port to cmake as part 
> of my cmake turotial.
> 
> fileC.o: fileC.c
> 	$(C) -DDINT -c fileC.c
> 
> fileD:  fileD.f fileC.o ../lib/libF.a
> 	$(F77) $(F77FLAGS) -o fileD fileD.f fileC.o    ../lib/libF.a $(F77LIB)
> 
> 
> 
> I  think I have learnt enough cmake to do most of the above  EXCEPT I am 
> unsure how on compile an object file  (in this case  fileC.o
> with a fortran compiler (if I have translated the makefile correctly)
>  Does one  rename   the file or whatever?
> Guidance on how to do this would be appreciated

You might try

ADD_LIBRARY(C STATIC fileC.c)

in junction with

TARGET_LINK_LIBRARIES(fileD C ...)

since you shouldn't directly refer to object files with CMake.

Regards,

Michael


More information about the CMake mailing list