I have an autotools C project that needs to use another library that is built with CMake. Is their an equivalent to AC_CONFIG_SUBDIRS that will work with CMake?
I take it that you want to configure and build the CMake-based project as part of configuring and building the Autotools-based host project. This is possible, and there are several viable ways to do it, but I'm not aware of anything wholly pre-packaged like AC_CONFIG_SUBDIRS
is for Autotools-based subprojects.
Autoconf provides a group of macros by which you can specify custom commands for configure
or the generated config.status
script to run. You could use one of these -- probably AC_CONFIG_COMMANDS
, but maybe AC_CONFIG_COMMANDS_POST
-- to run cmake
(and any wanted preparatory steps) in the subproject. Personally, I like this option best.
AC_CONFIG_SUBDIRS
instructs configure
to run configure
scripts in the specified subsirectories, but those other configure
scripts don't need to be Autotools-generated. You could conceivably write a custom wrapper script named "configure
" in the subproject directory for the parent configure
to run, but which itself performs an appropriate call to cmake
. AC_CONFIG_SUBDIRS
in the top-level configuration should then run that script at the right time.
I think Autoconf already provides sufficient support for what you seem to want, but if you think otherwise then you always have the option of writing whatever shell code you want into configure
via configure.ac
. You might find it worthwhile to write a custom macro for that, especially if you have multiple CMake subprojects, but that's not obligatory. Note that such commands are distinguished from those specified via AC_CONFIG_COMMANDS
& co. by the timing of their execution.
Presumably you'll be relying on recursive make
during the build and installation steps. It shouldn't be hard to make that work, whether you're using an Automake-based Makefile.in
or a hand-rolled one at the top level.
Use a SUBDIRS
variable in your top-level Makefile.am
to direct make
to recurse into the CMake project's subdirectory, just as you would do into any other project's. Write a simple Makefile there that recurses into a build
subdirectory (which you will have had to ensure is created and configured by configure
). This should not collide with the subproject because it presupposes that a separate build directory is used. The glue makefile can adapt targets and make
variables to the expectations of the subproject's build system.
The Automake documentation describes all the recursive targets that the top-level Autotools makefile might try to build recursively, and the glue makefile should provide all of them -- though there may be many that need only a dummy (but not empty) recipe.
Makefile.in
If, on the other hand, you're using a hand-rolled top-level Makefile
template then you have full control over your recursive make
invocations. You could still use a glue makefile in the subproject in this case, but it's probably easier and cleaner to just adapt directly to the expected CMake-generated makefile.