Question

Is there a way to get the location of the Jamroot file, for use as a constant in another Jamfile in the project?

Right now, I have this kludge in my Jamroot:

constant HOME : [ os.environ HOME ] ;
constant MYPROJECT_ROOT : $(HOME)/src/myproject ;

And then later I might do something like this in another Jamfile, to allow me to include headers with paths from the root of the project.

<include>$(MYPROJECT_ROOT)

It's especially unsatisfactory because it means that if I share this project with others, they have to either keep it in exactly the same location relative to their $HOME or they have to update the Jamroot.

I'm interested in the smart way to do this specific include (instead of my ignorant beginner way of using constants). But I'd also be interested in solving the problem the way I asked -- by getting the Jamroot location into a constant -- because this might be useful in other ways too.

Was it helpful?

Solution

Use the path-constant rule.

path-constant MYPROJECT_ROOT : . ;

Then in sub-projects, you can get the directory of the Jamroot with $(MYPROJECT_ROOT).

Note that usually people name this variable TOP instead of MYPROJECT_ROOT, but that's just a convention.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top