Portable Projects
From Texas Instruments Embedded Processors Wiki
Contents |
Introduction
This topic describes in detail how to modify your project to facilitate having multiple users working on the same project at the same time. If you are interested in how to package up and send a project (including all source files) to another user, please refer to the Sharing Projects topic.
Portable Projects in CCSv4
Project Creation
CCS projects are created inside the workspace directory by default. However, it is possible to create a CCS project outside of the workspace directory (e.g. in a source controlled directory). First dialog that appears after selecting File->New->CCS Project has a check box “Use Default location”, un checking this box allows you to specify the directory where project files should reside. Additional directory with project name will not be created if non-default location is used as user is specifying exact directory for the project in this case. Follow rest of wizard steps to create a project.
Adding Source Files
CCS provides two modes of adding source files to projects. Users can add files directly to project directory or link files to a project.
Source files in the project
- Adding files can be achieved by selecting “Add Files” from project context menu. Another way is to copy files directly into project directory. CCS projects automatically include all files that appear in directory where project exists, including all subdirectories. Thus an easy way of adding multiple files is to select all folders/files that currently contain sources and copy them into project directory. Alternatively, create a project at the root of directory that already contains all sources. This approach would work well when majority of sources are organized in some root directory (there maybe many subfolders that have sources but there is a single root). The downside of this approach is that all files in a directory and subdirectories are automatically included in project build. User needs to explicitly exclude files that should not be compiled. This may not be the best approach if many projects share the same sources.
Linking Files
- Linking files to a project creates a link reference that refers to a file in the file system. (similar to soft links on unix / linux systems). Files may be linked to a project by selecting "Link files to project" from projects context menu. In this case actual source files exist outside the root folder of the project. This could be used to control which source files are shown in a project and/or refer to source files that should not exist in a project (e.g. when a source directory tree is complex or portion of source code is delivered as standalone package). Normal user follow requires users to specify absolute path to linked file. This is ok if the project is not shared among different users. However, it breaks if project is moved around or if source directories move around on different user’s machines. (e.g. standalone software package is installed in a different directory on another user’s machine) This can be handled by specifying Linked resource path variables. They are kind of environment variables that CCS will use to resolve linked resources. To specify a new linked resource path variable open Window->Preferences. In top left corner in "type filter text" edit box enter "linked resources", this will filter out all other options. Click on New and select a meaningful name for path variable and specify the folder where the root of your sources is located.
Automated definition of Linked Path Variables
- CCS v4 provides additional support to help with automatic definition of linked resource path variables. User creating a project may additionally create a macros.ini file that defines linked resource path variables. During project import specified variables will be automatically added to workspace settings. End user importing a project does not need to perform additional steps to build the project. Linked resource path variables defined in macros.ini file accept relative paths. This may be used to have references to common source code that exists outside projects directory structure. macros.ini needs to be placed at the root of project directory. macros.ini file has following syntax:
- PROJECT1_PATH_VARIABLE=../../MyCommonLib
- PROJECT1_PATH_VARIABLE2=C:/ThirdPartyLibLocation/
- It is recommended that linked resource path variables be a combination of project name and user defined name to minimize chances of two different projects using the same linked resources path variable. Linked resource path variables are global to workspace thus it is possible to have two different projects use the same path variable. This may be undesirable where projects are independent and have different sources.
Adding a single linked file
- Last step is to add linked resources using newly defined path variable. If adding a single or two files, then easiest is to use GUI menus. Click on File->New->File, highlight the desired project, click on Advanced, then check "Link to file in the file system" click on "Variables..." and select path variable that you added in previous step and click on "Extend..." navigate to your source file and click ok and then finish.
Adding many linked Files
- If you have many files to add an easier way is to right click on the project select "Link files to project", navigate to where sources are, in the dialog perform multi-select and click Open. This will add all selected files using absolute path to resolve linked files. To make this project portable we now need to replace in project file the absolute portion of the path with path variable that was defined previously. Linked files that are part of the project are listed in .project file, which exists in the root directory of the project. Project View in CCS filters these files out by default. This filter can be turned off by clicking on a triangle button pointing down in project views menu bar, click on Filters... and disable ".*" filter. You can now double click on .project file to open it in CCS editor. Alternatively, you can use your favourite text editor by navigating to the file using windows explorer. Replace absolute portion of path for all linked sources with path variable. Save .project file, close and re-open the project (options are available on context menu). Verify that file location has linked resource as its location. (right click on any linked file and select properties; type: should be set to Linked file and Location: should contain path variable).
- User’s that use these type of projects would need to define path variables in Preferences to properly resolve files. Files that can not be resolved have a warning icon overlaid on top of file icon.
Specifying compiler/linker options
Last step to make project portable is to use macros to specify paths for including header files or libraries. Every project automatically defines a number of different macros that can be used in build options. To see a list of existing macros right click on project and select properties, navigate to C/C++ Build node, Macros tab contains all automatically defined macros. There are build configuration i.e. Debug/Release and Project generic macros. Using project specific macros is a bit easier as they will be automatically re-adjusted for different users, when project is imported into CCS. User may also define their own macros similarly to how linked resource path variables are defined. These macros need to be defined in global preferences (Window->Preferences->C/++->Managed Build category). Any user defined macros will need to be defined by different users once a project is imported. (similar to how linked resource path variables would need to be defined by each user).
Portable Projects in CCSv5
In CCSv5, there is now the capability to store path variables within the scope of a project rather than at the workspace level. The path to linked source files can then be made relative to these variables and everything is self-contained within the project thus making it easier to share the project with others. This eliminates the need for a macros.ini file as was required with CCSv4. The process of creating linked path variables and adding linked files to the project is simpler than in CCSv4, and is described below.
Adding Source Files
When adding source files to a project in CCSv5, you have the option of either copying the files into the project folder or linking/referencing them from their location outside the project folder. Prior to linking files, the Linked Resource path variables need to be set up for the project.
To create a Linked Resource path variable:
- Right click on the project's name
- Select "Properties -> Resource -> Linked Resources"
- Here you can view, add or edit the path variables for the project.
- Use the "New" button to create a new Linked Resource variable
- Path variables are usually set to a top level folder that contains sub-folders for source files, linker command files etc.
- When creating a new portable project, set the top level path variable relative to the location of the project
- Path variables are stored at the project scope, not at the global scope as was in CCSv4, which avoids name collisions between multiple projects.
- When a CCSv4 project with macros.ini file is imported into CCSv5, the path variables are automatically processed. In the below screenshot, the macros indicated with a red square were processed from the macro.ini file and automatically added to the project properties when the project was imported.
To add/link files to a project:
- In the Project Explorer view, right click on a project name and choose "Add Files"
- Choose files that you would like to add and click "Open"
- A dialog will pop up asking if you want to "Copy files" or "Link files"
- If you choose "Copy files" then the file will be copied to the project directory
- If you choose "Link to files" then you can choose whether to create a link relative to PROJECT_LOC (which resolves to the root folder of the current project) or to a path variable you created
You can also drag/drop files and folders into a CCSv5 project. The above dialog will also be presented during drag/drop allowing you to choose whether to copy or link files. You can configure the action to be taken on drag/drop in the Window->Preferences->General->Workspace->Linked Resource menu or by clicking on the Configure Drag and Drop Settings in the above dialog.
Specifying compiler/linker options
While Linked Resource variables are used for linked files, Build variables are used in the project build options when specifying paths for including header files or libraries. Every project automatically defines a number of different build variables. To see a list of existing build variables, right click on project go to Properties-> C/C++ Build->Build Variables, and click on Show system variables. You may also create your own build variables similarly to how linked resource path variables are defined. To create a new build Variable use the "Add‟ button.
The build variable can then be used in the project build options.
Leave a CommentComments
Comments on Portable Projects
Contents |
Pensive.mb said ...
Kishor.j said ...
Define file macros.ini in Project root path and you can set relative path in this file. It automatically gets imported when project is imported
--Kishor.j 07:01, 24 November 2010 (CST)
Drowley7474 said ...
I'm doing all of the above and I think I understand it. I'm adding a macros.ini file I believe in the correct place for the project (same directory position as the ".project" file). Then when I do what is under the heading above "Adding a single linked file" and then click on "Variables" the variable I added in macros.ini does not show up (I even restarted the PC). Should it? The way I read the above it should show up so I'm wondering if I'm doing something wrong or if I need to edit the .projects file by hand to add the relative path from the macros.ini file?
--Drowley7474 08:34, 21 June 2011 (CDT)
Drowley7474 said ...
I'm commenting on my own comment. I found sort of a subtle difference here.
The comment below applied to a workspace in "..\My Document\workspace6713" and the variable didn't show up as described. I've found that CCS really seems to like ..\My Documents\workspace so I created ..\My Documents\workspace\workspace6713 and using the macros.ini file in that condition and then I could see the Varible I added in macros.ini. And when I go and look at the linked file in ".projects" it adds the relative path as I expect.
--Drowley7474 09:16, 21 June 2011 (CDT)
Drowley7474 said ...
Changing the story again. I don't think the problem was it didn't like ..\My Documents\workspace6713. The problem appears to be the macros.ini file is only read when a workspace is "File->import"ed. So I added macros.ini and the workspace had been imported. So to get a workspace to recognize macros.ini changes; right click on the project in the project viewer and say DELETE (and keep the source code!!!). Then, if you haven't already, edit macros.ini. Then do File->import and it will use the changes to the macros.ini. At least that seems to work for me.
--Drowley7474 11:34, 21 June 2011 (CDT)


Is there a way I can use only one variable to specify the linked resource and the compiler linker options.
The path variable only takes an absolute path, I tried specifying the include path in terms of his absolute path variable but it gave me errors of not being able to resolved it
--Pensive.mb 18:16, 13 April 2009 (UTC)