Disclaimer: There are several jam flavors. The answer applies to Perforce Jam and some of its compatible descendants.
As you've already mentioned yourself, invoking jam from cmake can be done with add_custom_target
/add_custom_command
, so that answers the first part of your question.
Since jam rules (or rather actions) can invoke arbitrary commands, the other direction is certainly possible as well. cmake
itself is usually not the tool you invoke for building a target. So, depending on your generator, you would actually want to call make
, ninja
,...
In your question you're not very concrete regarding you migration approach. Assuming you start out with a jam build system with multiple library and executable targets that span a dependency graph, and you want to migrate the build system component by component. If you start bottom up with a library without dependencies (whose sources hopefully live in their own subdirectory), you would replace the rule invocation that builds the library -- e.g. Library libfoo : foo.c bar.c ;
-- by a rule invocation that calls e.g. make
-- like Make libfoo$(SUFLIB) ;
. The rule could be defined (e.g. in Jamrules
) as:
rule Make
{
# tell jam where the target will be created
MakeLocate $(1) : $(LOCATE_TARGET) ;
# always invoke the actions, since we don't let jam check the target's dependencies
Always $(1) ;
# we need the source dir in the actions
SOURCE_DIR on $(1) = $(SUBDIR) ;
}
actions Make
{
# get absolute source dir path
sourceDir=`cd $(SOURCE_DIR) && pwd`
# cd into the output directory
cd $(LOCATE)
# generate Makefile, if not done yet
if [ ! -e Makefile ]; then
cmake -G "Unix Makefiles" $(sourceDir) ;
fi
# make the target
make `basename $(1)`
}
If you need other information from jam to be passed to cmake (like the build type or certain build options), define respective on-target variables (like SOURCE_DIR
in the example) to have them available in the actions.