c++ - How to embed path to resource file / CMake (on linux) -


i creating c++ class has constructor this:

myclass(const std::string& config_file); 

i.e. configuration file should passed constructor when instantiating object. part of project create default configuration file used in ~90% of cases, , people able use class as:

myclass myinstance(default_config_file); 

i.e. want symbol 'default_config_file' point path of configuration file have created part of project. problem have no clue people install library. there (cmake ??) trick/best practices here?

i guess like

set( default_config_file ${cmake_install_prefix}/share/app/default_config.json) 

but things not work in build directory?!

joakim

after set command have shown, can add in cmakelists.txt line this:

add_definitions(-ddefault_config_file=${default_config_file}) 

or

add_definitions(-d`default_config_file=${default_config_file}`) 

(you should experiment happens if path contains spaces, general)

this should give default_config_file used @ compile time.

some useful links:
add_definition documentation
cmake: when use add_definitions instead of set_target_properties(target properties compile_definitions definitions)
spacing in -d option in cmake


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -