2

I am trying to interrogate the inclusion path of a series of addsubdirectories():

-projectA
    -projectB
        -projectC

In this setup, projectA is adding ProjectB as a subdirectory which in turn adds ProjectC as a subdirectory. I want to let projectC know about the hierarchy. I can achieve this by recursive calls

get_directory_property(parent DIRECTORY ${cur_dir} PARENT_DIRECTORY)

which will return nothing when it reaches projectA. That almost does it. It would be nice however, if I could read the ${PROJECT_NAME} from these directories and return A-B-C instead of projectA-projectB-projectC.

So my question is: Is there any way of reading the variables from a directory that is already parsed?

Note that in this case, although projectC would inherit variables from its parent, but the standard cache variables are replaced in the child projects, which is why I can't use them.

Maths noob
  • 1,684
  • 20
  • 42
  • Could [`LISTFILE_STACK`](https://cmake.org/cmake/help/v3.3/prop_dir/LISTFILE_STACK.html) be of any use here? Or you could have your own `my_add_subdirectory()` building the stack in custom directory properties from `PROJECT_NAME`. And did I understand correctly that all (sub-)folders have a `project()` command? – Florian Apr 19 '16 at 10:26
  • yeah all have project(). I am however reaching to the conclusion that the same way installed projects can have config files, I can have one generated with `configure_file` and place it in the source folder to act as a header or project file. so that having located the directory, I would just include its project file. I think its much cleaner than anything else I could do. – Maths noob Apr 19 '16 at 10:33
  • Ok, but how to setup this is most probably another question (see e.g. mine [here](http://stackoverflow.com/questions/31512485/cmake-how-to-setup-source-library-and-cmakelists-txt-dependencies)). Just going by the main question you have asked here, yes you can read [`VARIABLES`](https://cmake.org/cmake/help/v3.3/prop_dir/VARIABLES.html) property for a specific already parsed directory. – Florian Apr 19 '16 at 10:42
  • That would only give you a list of variables. But thanks! I had another look and turns out "DEFINITIONS" would do it. – Maths noob Apr 19 '16 at 15:30

1 Answers1

1

you can do:

get_directory_property(output DIRECTORY dir/path DEFINITION PROJECT_NAME)

or any normal variable:

get_directory_property(output DIRECTORY dir/path DEFINITION myVariable)
Maths noob
  • 1,684
  • 20
  • 42