Enable external makefile with CMake

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

But maybe I should give a little context. I am trying to integrate PETSc (and SLEPc) into my code. Here is an example from an example using SLEPc (although PETSc is almost 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, this requires the inclusion of a specific makefile, which includes a bunch of other makefiles. This is a little strange, because it seems that it would be easier to just have an include directory, but apparently there is more than what I understand. Anyway, my first solution was to simply include the makefile that he wants and see if that works.

+7
source share
2 answers

I believe that this requirement does not correspond to the CMake design model in general, since Makefiles were created during the generation phase, and one of the basic principles of CMake is to make it a β€œstrong” cross platform, so the best idea might be:

  • Rewrite external build system in CMake script
  • Include CMake Scripts in Your Project

If the effort is huge, you can try using add_custom_target / add_custom_command to execute some commands outside the field to configure the generated files, but it will also require considerable effort - just read the manual and look for more options.

+1
source

There is an include method as part of CMake. If you correctly set the policy area (which did not work until I believe 2.8), it should handle duplicate use of the PROJECT method and give you the desired results. I have not tried this to be sure, but it is worth it.

0
source

All Articles