I am using a CMake build system for my project.
I want my program executable to know the Project Directory at all times, I thought i could set an environment variable and use:
getenv("MYPROJDIR")
But i don't want to create a persistent variable across the system, and i don't want to manually create a temporary variable everytime before executing my program.
Is there a way to set some variable in build time so that my source knows the project directory, and can access input files relative to that directory regardless of the location where it is executed from.
I could use a define with the -D switch or:
add_definitions(-DMYPROJDIR=${PROJECT_SOURCE_DIR})
but i have heard people say not to use macros unless absolutely necessary.
Overall i need this funtionality:
const string defaultinput = MYPROJDIR + "src/someinputdata.dat"
ifstream myfile(defaultinput)