tags:

views:

5054

answers:

4

I'd like to add ~/include to my include path for all projects while using Xcode, something like setting the environment variable CPLUS_INCLUDE_PATH in Linux. (See here for the related Linux question.)

Is this possible in Xcode? I tried setting the above environment variable, but it doesn't seem to work. (And if it is possible, I'd like to also set related paths, like LIBRARY_PATH and LD_LIBRARY_PATH.)

A: 

Add the HEADER_SEARCH_PATHS build setting to your Xcode project. This setting takes a space separated list of paths and if the path ends in a double star (**), it will search subdirectories recursively. So to answer for your example, set HEADER_SEARCH_PATHS to:

~/include

If you had a number of paths to include, you would set it to something like:

~/include ~/my_other_includes/** /usr/local/special_frameworks/**
Jason Coco
I want a *global* setting, so that I don't have to add the same path for every Xcode project.
Jesse Beder
Ok, you didn't actually state that originally. As Jesse said, you can set build settings in your environment as well and I guess that's working for you.
Jason Coco
A: 

According to Apple's Docs, be able to provide a default for any build setting using an environmental variable.

In this case, you'd want to set HEADER_SEARCH_PATHS. For some reason I don't understand, this doesn't work. It works fine for other build settings (for example, OTHER_CFLAGS), but not for HEADER_SEARCH_PATHS. You can see what the variable name for any setting is by opening the research assistant in the build settings window (book button on the bottom left.)

One var that does work is USER_HEADER_SEARCH_PATHS, which is just like what you want, but only works for paths in double quotes (not in angle brackets.)

So

#include "bar.h"

would work, but

#include <bar.h>

wouldn't.

The build settings plist referenced from the above article on environmental vars should end up looking something like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
<plist version="1.0">
<dict>
    <key>USER_HEADER_SEARCH_PATHS</key>
    <string>~/test</string>
</dict>
</plist>

Hope that helps.

Jesse Rusak
A: 

Build settings are not environment variables, and environment variables are not build settings. Setting an environment variable will not affect Xcode builds.

USER_HEADER_SEARCH_PATHS is a build setting, and putting a list of paths into it will achieve what you want. If you set the value in a target's inspector, it will take effect for only that target (and only for the Build Configurations you designate). If you set it in the Project inspector, it will take effect in all targets in the project, unless a target overrides it with its own setting.

For paths that are specific to your machine, you should probably define a Source Tree in the Xcode Preferences, such as LOCAL_INCLUDE = ~/include . Then define USER_HEADER_SEARCH_PATHS = $(LOCAL_INCLUDE) in the project. This way, other people can open your project and build it by setting their Source Tree to the particular location of the local includes on their machine, without having to change the project file.

cdespinosa
Setting environmental variables *does* affect build settings. It quite clearly says so in Apple's docs, and it works.
Jesse Rusak
A: 

Just select a .c or .m file in your "Groups & Files Tab" and choose "get Info" through RMB, then under "build" you can add additional Compiler Flags like -I for additional include searchpath.

parceval