Using Relative Include Paths with Keil 8051 tools and Silicon Labs 8-bit IDE
09/265/2016 | 04:46 PM
Question
I want to convert all of my Silicon Labs 8-bit IDE projects from using absolute include paths to relative paths so that these projects can be pulled down from a repository by different users to wherever they want on their drive and still have the project compile correctly. How can I do this?
Answer
It is possible to include the necessary file paths in the build commands for projects in which all header files are located in directories that are relative to the directory containing the project ".wsp" file (and where this relative structure will be maintained no matter where a user pulls down the repository). This will be the case when the ".wsp" file is located in the project root directory and all necessary header files are located in this root directory or sub-directories of the root.
In the example case I am using to illustrate this technique, the project ".wsp" file is located in a particular directory, and the needed .h files are located in a sub-directory that is two levels down from the ".wsp" file. In the IDE, if you click Project -> Tool Chain Integration -> Compiler Tab, you must add the command line directive:
INCDIR(<relative path from .wsp file to .h include directory>)
In this case, all the header files needed to be included are in the ".\extra_layer_to_test_relative paths\inc" directory. In the case that there were also header files in the root directory (".\") and in the ".\extra_layer_to_test_relative paths" directory, the needed compiler directive would be:
On occasion, users have reported an unusual situation in which some combinations of header files that themselves include other header files in a different part of the directory structure fail to compile, with the compiler warning that the file in the lower level of the directory path could not be opened. For instance, in this example say that a header file located in the ".\extra_layer_to_test_relative paths\inc" directory includes a file located in the ".\" directory. If the subsequent file could not be found by the compiler, it may be necessary to add the relative path "..\.." to the path list:
Using Relative Include Paths with Keil 8051 tools and Silicon Labs 8-bit IDE