0

I am creating a C++ class which has a constructor like this:

MyClass(const std::string& config_file);

I.e. a configuration file should be passed to the constructor when instantiating an object. As part of the project I create a default configuration file which will probably be used in ~90% of the cases, and I would like people to be able use my class as:

MyClass myInstance(DEFAULT_CONFIG_FILE);

i.e. I want the symbol 'DEFAULT_CONFIG_FILE' to point to the path of configuration file I have created as part of the project. But the problem is that I have no clue where people actually install the library. Is there (CMake ??) trick/best practices here?

I guess could do something like

set( DEFAULT_CONFIG_FILE ${CMAKE_INSTALL_PREFIX}/share/app/default_config.json)

But then things will not work in the build directory?!

Joakim

user422005
  • 1,989
  • 16
  • 34
  • If I understood correctly, you want to define the value of `DEFAULT_CONFIG_FILE` at compile time? – heuristicus Jul 31 '13 at 10:07
  • I think this is basically a definement (as it can be passed by make something=value) – urzeit Jul 31 '13 at 10:46
  • @heuristicus: Well ideally at install time, but I do not want a full recompile when installing? – user422005 Jul 31 '13 at 12:08
  • Does this answer your question? [Define preprocessor macro through CMake?](https://stackoverflow.com/questions/9017573/define-preprocessor-macro-through-cmake) – Antonio Aug 24 '21 at 13:06

0 Answers0