Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrapping cmake build with makefile

I have a project with existing makefile based build system, where I want to add existing cmake based component.

What is best way to integrated cmake configure step? As a $(shell ) call evaluating some variable? That runs configure on each invocation...

How to integrate building itself? Just (MAKE) -C cmake-build-dir [targets]?

like image 432
kwesolowski Avatar asked Sep 06 '25 02:09

kwesolowski


1 Answers

The goal of CMake is to generate a Makefile, so I would go with something like this:

CMAKE_BUILD_DIR := some_dir
CMAKE_SOURCE_DIR := some_src_dir

$(CMAKE_BUILD_DIR)/Makefile: $(CMAKE_SOURCE_DIR)/CMakeLists.txt
    cmake -S $(<D) -B $(@D)

.PHONY: $(CMAKE_BUILD_DIR)/built_executable_or_library  # to allow CMake's make check the build
$(CMAKE_BUILD_DIR)/built_executable_or_library: $(CMAKE_BUILD_DIR)/Makefile
    $(MAKE) -C $(@D) $(@F)

This should call CMake configure step when the Makefile does not exist and run make directly to build whatever you need (probably you would need to tailor called targets to your needs). CMake's generated Makefiles check the generated build system itself, so it will be reconfigured as needed.

like image 173
raspy Avatar answered Sep 09 '25 01:09

raspy