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]?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With