Compiling a mixed language C ++, C and Fortran with Cmake

Using g++ , gcc and gfortran on GNU / Linux, I wrote a simple script to compile and link several source code files written in C ++, C, and Fortran. Here is the full content 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-Qo 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 overwrite the script with Cmake. How can I handle compilation in a mixed language?

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

Perhaps there is 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 
+4
source share
1 answer

You need to enable Fortran for the project as follows:

project (q-test C CXX Fortran)

Alternatively, you can use find_package (Boost) instead of hard coding the include path.

+6
source

Source: https://habr.com/ru/post/1447076/


All Articles