Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include external makefile with CMake

Tags:

makefile

cmake

I want to include a makefile from an outside library in my own software's makefile. The simplest would be to figure out the CMake code for the Makefile equivalent of include ${dir}/makefile .

But maybe I should give a little context. I'm trying to integrate PETSc (and SLEPc) into my code. Here is some code from an example using SLEPc (although PETSc is pretty much the same):

hello: hello.o chkopts
        -${CLINKER} -o hello hello.o ${SLEPC_LIB}
        ${RM} hello.o

include ${SLEPC_DIR}/conf/slepc_common

As you can see, it requires an include of a specific makefile that includes a bunch of other makefiles. This is a little weird because it seems like it would've been simpler to just have an include directory, but apparently there's more to it than I understand. Anyway, my first solution was to simply include the makefile it wants and see if that works.

like image 557
hadsed Avatar asked Jul 30 '12 15:07

hadsed


1 Answers

I believe this requirement doesn't fit CMake's design model at all as the Makefiles were generated during the generation phase and one of CMake's core principle is to make it cross platform, so the better idea might be:

  1. Rewrite the external build system in CMake scripts
  2. Include the CMake scripts in your project

If the effort is huge, you can try with add_custom_target/add_custom_command to do some out of box commands to tweak generated files, but those would also import considerable efforts - just read the manual and seek more opportunities.

like image 168
Fei Avatar answered Oct 25 '22 03:10

Fei