Nicholas Kinar
Nicholas Kinar

Reputation: 1470

Mixed language C++, C and Fortran compilation with Cmake

Using g++, gcc and gfortran on GNU/Linux, I've written a simple script to compile and link together a number of source code files written in C++, C and Fortran. Here are the complete contents of the script. This script has been tested, and works well.

g++ -c test-Q.cpp -I./boost/boost_1_52_0/ -g
 gcc -c paul2.c -g
 gcc -c paul2_L1.c -g
 gcc -c paul6.c -g
 gcc -c paul6_L1.c -g 
 gcc -c fit_slope.c -g
 gfortran -c getqpf.F -g
 g++ -o test-Q test-Q.o paul2.o paul2_L1.o paul6.o paul6_L1.o fit_slope.o getqpf.o -g -lgfortran

To make this more cross-platform, I would like to re-write the script using Cmake. How might I handle mixed-language compilation?

The following test script listed below does not work, and will only selectively compile some of the files.

Is there perhaps another cross-platform build process that might be better suited for this type of compilation?

cmake_minimum_required (VERSION 2.6)
project (q-test)

include_directories(/media/RESEARCH/SAS2-version2/test-Q/boost/boost_1_52_0)

add_executable( q-test
test-Q.cpp
paul2.c
paul2_L1.c 
paul6.c 
paul6_L1.c 
fit_slope.c
getqpf.F
) # end

Upvotes: 4

Views: 3268

Answers (1)

Bill Hoffman
Bill Hoffman

Reputation: 1762

You need to enable Fortran for the project like this:

project (q-test C CXX Fortran)

Also, you might want to use find_package(Boost) instead of hard coding an include path.

Upvotes: 6

Related Questions