How to define custom build variables in Xcode - c++

In Xcode 10, I'm creating a C++ project that uses the HEADER_SEARCH_PATH to define a list of header include paths. One of the paths contains an environment variable, e.g. ${CUSTOM_INCLUDE_ROOT}/boost_1_xx_0/include, where ${CUSTOM_INCLCUDE_ROOT} is supposedly an environment variable to be set on each dev's local environment to give a root include path - the reason is that this root dir is of user's own choice, so different users can decide on different root dir.
However, in Xcode 10 build settings, it doesn't seem that Xcode is automatically expanding ${CUSTOM_INCLUDE_ROOT} - causing the expanded header to look like: /boost_1_xx_0/include, and of course that causes compiler errors for #include <boost/something.hpp>
So, the question is: how does Xcode build settings reference environment variables, or is this possible at all?
Or a related question would be: if referencing environment variables in build settings is not possible, is it possible to define new custom variable such as ${CUSTOM_INCLUDE_ROOT} to be /home/username/globalInclude inside xcode?

Related

How to add an include directory based on environment variable in RHIDE without expansion?

The REDHAWK IDE insists on expanding environment variables when creating the Makefile.am.ide file. For example, assume that $SRC_ROOT is /srcpath and I add an include path in the Path and Symbols window of the C/C++ section of my project as below:
${env_var:SRC_ROOT}/include
the generated Makefile.am.ide file contains:
rehawk_INCLUDES_auto = -I/srcpath/include
when what I really want is:
rehawk_INCLUDES_auto = -I$(SRC_ROOT)/include
This is important because this file is used by other team members that have different values for $SRC_ROOT. Currently we have to put the include path in Makefile.am, but then the IDE doesn't see the header files in the directory and sees errors for the code referred to in the missing headers.
Is there anyway to get RHIDE, to not expand the environment variables when it generates Makefile.am.ide?
Not exactly what you are looking for but you can always disable the auto-updates of the Makefile.am.ide by disabling the REDHAWK C++ auto-inclusion builder. This is in the projects properties in the Builders section.
This will allow you to add to Eclipse's Paths and Symbols section without the auto-inclusion builder picking it up and adding it to your Makefile.am.ide.
If you do choose to disable this builder you will then need to manage the addition of new source files on your own.
Youssef's answer is not a bad one, but I've come up with a different way to work around the problem. In Makefile.am, override the redhawk_INCLUDES_auto value to be what I what it to be:
include $(srcdir)/Makefile.am.ide
#Override the value from Makefile.am.ide that may be wrong!
override redhawk_INCLUDES_auto = -I$(SRC_ROOT)/include
This requires one to update any custom include directories in both the IDE and the Makefile.am file, but managing the source files is still automatic.
It still has the issue that the Makefile.am.ide file's contents will be different for other developers which complicates version control. So I don't consider this be a complete answer to the problem.

path relative to cpp not working directory

I am working on some C++ code, that mainly provides a class for two other projects that share it but also includes a small program so that it can be used from the command line if needed. The class has to load some resources, that are written to several files in a resources folder. The path to these files is of course hard coded into the program, since I don't want any client using the class having to worry about loading those resources, other than calling an init method. When I compile the project on its own, with the hardcoded fopen("resources/myresource.dat") it works as expected, but when it is included in another project, the whole thing is typically placed into a separate subdirectory with only the header included as #include "subdir/myclass.h". In this case the hardcoded paths are invalid as the working directory is one folder higher.
How can I make sure the path to the resources folder is always valid, regardless of the path of the include?
How can I make sure the path to the resources folder is always valid, regardless of the path of the include?
It's not anyhow related to the include's path.
What you actually need is an installation routine, that provides you with a environment variable like $MYAPP_RESOURCE_PATH and having that expanded instead of your hardcoded path "resources/myresource.dat".
You can retrieve the environment variable's value with the getenv() function.

Global include path on Windows on VS2013

I should add a global include path to my system (i.e. it's Google Test so I need to include "C:\gtest\include")
I appended it to the PATH environment variable and restarted VS2013. However, VS2013 still complains about the missing .h files.
What's wrong with this IDE?!?
First, you definitely don't want the PATH environment variable. You do want the INCLUDE environment variable.
Second, use a statement like SET INCLUDE=C:\gtest\include;%INCLUDE% to set it.
Third, that's only going to work in a command window that you're running command line builds in.
Fourth, so try setting it on your machine using This PC's properties "Advanced System Settings" Environment Variables dialog. Remember to restart your VS2013 after setting it so it picks up the new env vars.
Fifth, why not do a SET (with no arguments) after you've set your non-working INCLUDE variable and paste the result into your question so we can all see what your environment variables look like - then we might be able to help you better.
Sixth, it's going to end up being your misunderstanding of how things work. That's clear since you think the PATH env var has something to do with VC++ searching for include files. So why the gratuitous "What's wrong with this IDE?!?" slam? It's not winning you any friends.
Seventh, see the MSDN article Setting the Path and Environment Variables for Command-Line Builds for tips. It came right up when I googled for "visual studio include environment variable", and it has help for you.

Use eclipse build variables to create project include directories, in C++

I have a C++ project in Eclipse which the base part of all include directories is different depending on a chosen platform. For example, including include/cTable directory:
/a/b/c/platform1/include/cTable/
/a/b/c/platform2/include/cTable/
/a/b/c/platform3/include/cTable/
So, what i want to do is to create next build variables (window->preferences->C++->build->build variables):
PLATFORMNAME_PLAT1 = "platform1"
PLATFORMNAME_PLAT2 = "platform2"
PLATFORMNAME_PLAT3 = "platform3"
PLATFORM_SELECTED = ${PLATFORMNAME_PLAT1}
INCLUDE_DIR = "/a/b/c/${PLATFORM_SELECTED}/include/"
Then, using the project properties, C++ general->paths and symbols->includes, add include directories that way:
${INCLUDE_DIR}/cTable
${INCLUDE_DIR}/cRow
${INCLUDE_DIR}/cComponentBase
${INCLUDE_DIR}/cTimers
That way, when changing the platform, i only have to edit the PLATFORM_SELECTED build variable, setting it to the PLATFORMNAME i want, even without remembering the platform directory name.
The problem is that the INCLUDE_DIR variable is not expanded and i have lot of errors like "invalid project path: include path not found (/a/b/c/include/cTable)". I think that the problem is the type of the build variables. INCLUDE_DIR has Path type, but i've tested using both path and string types for the other without any success. I would like to ask if someone can point me to a good approach for the creation of these build variables.
I dont use eclipse for compiling, but just for code editing, so what i want is to use the code completion and syntax highlighting.

Change Eclipse Dynamic Variable to build a single c++ class

I would like to change the dynamic variable ${selected_resource_loc} such that I get rid of the extension (and can add another one).
The purpose is to build the current selected file, but therefore I don't need the .cc-file in my command but the .o-file with the same name.
Detailed description:
I have a customized make command (lets say make) and would like to execute make selectedFileName.o, where the current selected file in eclipse is selectedFileName.cc. (I put the command as build command in project properties -> C/C++ Build.) With variable ${selected_resource_loc} in behaviour tab I get make selectedFileName.cc.
I solved my problem by writing a skript where I modify the ${selected_resource_loc} and included it via external tools in eclipse.