3

I started learning about cmake and make recently and I ran into a problem I am unable to solve.
I have two projects, a small test application that uses cmake in the IDE CLion and a librarie that uses make, I can't change the build systems for either. I would like to build the one that uses make, from the cmake project. The make file for the library works fine on it's own.

This is the project layout:

project/CMakeLists.txt
project/libvz/Makefile
project/libvz/main.cpp

I have tried the following:

CMakeLists.txt:

cmake_minimum_required(VERSION 3.0.0)
project(builder)

add_custom_target("libvz"
                  "/usr/bin/make -f ${CMAKE_CURRENT_SOURCE_DIR}/libvz/Makefile")

In this case I get the error: "/bin/sh: /usr/bin/make -f /home/szil/project/libvz/Makefile: No such file or directory"

I also tried to build using the ExternalProject_Add and ExternalProject_Add_Step commands, but neither worked for me.

Any help is appreciated, Thx!

oSz
  • 63
  • 1
  • 7
  • Did you check https://stackoverflow.com/questions/5971921/building-a-library-using-autotools-from-cmake ? – malat Jan 10 '22 at 10:01

1 Answers1

5

You probably just need to avoid wrapping the entire make command in a set of quotation marks. By doing this, CMake is looking for an executable called "/usr/bin/make -f ...".

add_custom_target(libvz
                  /usr/bin/make -f "${CMAKE_CURRENT_SOURCE_DIR}/libvz/Makefile")

On the face of it, ExternalProject_Add sounds like a better tool for this job - maybe it wasn't working for the same reason as this?

Fraser
  • 74,704
  • 20
  • 238
  • 215