I’m integrating a Makefile’s functionality into CMake. The Makefile builds and installs a target. The install copies from a target’s install directory into the toolchain sysroot thus making it available for dependent targets. When building all targets, the install is performed for the dependency chain automatically.
I’m trying have this same functionality with CMake. Except ‘cmake --install’/‘make install’/‘ninja install’ performs a build of dependencies but doesn’t install them before the dependent target build starts. This causes a build failure because dependent files are not found.
I’m using ExternalProject to build open source packages. It performs all of the necessary steps to for ‘cmake --install’/‘make install’/‘ninja install’ to function.
Here is the install function for each open source package:
For example, openssl depends upon zlib. The openssl/CMakeLists.txt has this line:
add_dependencies(${PROJECT_NAME} zlib)
This causes zlib to be built before openssl by ‘ninja install’. But zlib isn’t installed.
This forces me to perform builds and installs manually which isn’t following the functionality of the original Makefile:
cmake --build . --target zlib
cmake --install . --component zlib
cmake --build . --target openssl
cmake --install . --component openssl
Is there something I’m missing or is this a limitation with CMake?
I don’t understand this response. I’m am working with targets not files or directories.
In this case, the problem is the ‘–install’ option doesn’t perform an install on dependencies.
Building ExternalProjects in a specific order and manage dependencies between them is called a superbuild. Only ExternalProjects builds are done there.
You can only integrate ExternalProjects in a normal build if you do not rely on installed items at configure time. I guess that building openssl also configures it. You sometimes can work around this a bit by specifying the install target as build target in ExternalProject with a custom BUILD_COMMAND (or both commands if the install does not depend on build).
The other option is to tightly integrate the build using FetchContent which can bring its own set of problems.
It is in any case easier to have a tool that properly builds a sysroot that you can rely on instead of using cmake as a hammer to handle the screw.