Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing make from cmake

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!

like image 789
oSz Avatar asked May 23 '26 14:05

oSz


1 Answers

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?

like image 171
Fraser Avatar answered May 25 '26 04:05

Fraser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!