Search code examples
c++buildpathscons

Good Practice: How to define path to external libraries for compilation


I am fairly unused to compilation and building projects so pardon me if my approach to compilation and build seems a bit odd. Any tip is welcome.

I am currently working on a 3D geometry C++ project (Which is a dll). This project uses external dll's such as BOOST. So when building the project I have to define the directories in which the .dll, .lib and .h/.hpp files are.

Currently I am using scons to build the project and define those paths straight in the SConstruct file.

However those paths are later reused for other build operations. (In the present case compiling the C++ code in MEX for matlab but that's not really the point here).

Thus I currently have to define the same path in different places which is inefficient. In addition the project has to be easy to set up for another user. So having to change and update path in many different files is something I would like to avoid.

From where I stand I see two alternatives:

  • First I could ask the user to define environment variables and read them from inside my various build scripts. However I am not really satisfied with this solution for it asks the user for additional manipulation and, as far as I've understand, I lose the cross-platform portability that scons offers. (I know it might still possible but requires some extra steps and I'd like to keep things as simlpe as possible)

  • Second I could define all my path in a single .txt (or something similar) file at the root of my project and read it from my various build scripts. However this makes the process sensitive to typos and parsing errors which is not really to my taste.

So my question is the following: Is there a better way or good practice to have the user input the paths necessary for compilation that satisfies the following:

  1. Has the user only input once every path
  2. Is done within the project folder through a file or something else
  3. Is as foolproof as possible
  4. Does not require too much additional download/installing (I don't really want to have the user install a brand new software for this. However I'm fine with something like a simple light .exe that I can add in my project files)

Solution

  • SCons's Variables are likely your best choice here.

    See: https://scons.org/doc/production/HTML/scons-user.html#sect-command-line-variables

    It allows reading defaults from a file:

    vars = Variables('custom.py')
    

    You'd have to craft some logic to save any variables specified on the command line.