# Exclude varying files from build

This topic is 1669 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey guys,

I've been fooling around creating an engine just for fun and learning purposes and I decided to focus a bit on cross platform and working with both OpenGL and DirectX.

Now this is working fine so far, I can run the engine with either OpenGL or DirectX, I am however not very pleased with how I achieved this, or at least, I think there must be a way more elegant way of getting this to work properly. Let me explain:

For OpenGL and DirectX to work, I obviously need to have the headers/libraries for these, but I don't want to include the GL headers when compiling for DirectX and vice versa. The way I do this is to simply use #defines and check against these, but it seems very ugly. This is how it looks in general:

#ifdef OpenGL

class GraphicsOpenGL : Graphics
{
// bunch of functions
}

#endif

//////////////////////////////////////////////

#ifdef DirectX

class GraphicsDirectX : Graphics
{
// bunch of functions
}

#endif


The #ifdef is also in the implementation, but just to get my point across.

What other (better?) way is there to exclude certain files that can vary with a build? I can't help but feel this is ugly, but it's also the most common solution I found while searching for this.

I am not really that far in, just context creation and screen clearing, so a total overhaul wouldn't be a problem. Any tips and/or solutions are welcome

##### Share on other sites
Assuming you are using visual studio, you can create separate configurations for your DX and OpenGL builds. If you now have a "Debug" and "Release" configuration, you can set it up to have for example "DebugDX", "DebugOGL", "ReleaseDX" and "ReleaseOGL" instead.

In each of the configurations, you can right click on any file and select "Excluded from build", and it will be excluded for that configuration.

##### Share on other sites

Look into build configuration, there are tools like jam, cmake, premake, etc...  They will allow you to generate your project base on configuration settings.  For instance in your source, you could have a folder for OpenGL and Directx implementations, then base on the configuration your project would build different files.  This is to control which files to build, you still need to work with macros to handle platform specific includes and implementations.

##### Share on other sites

Assuming you are using visual studio, you can create separate configurations for your DX and OpenGL builds. If you now have a "Debug" and "Release" configuration, you can set it up to have for example "DebugDX", "DebugOGL", "ReleaseDX" and "ReleaseOGL" instead.

In each of the configurations, you can right click on any file and select "Excluded from build", and it will be excluded for that configuration.

Yeah this might be an option, this might end up getting a lot of different configurations should I, for some reason, decide to throw in cross platform stuff. Then again, I think I won't be able to use visual studio on Linux/mac systems anyway. It's something for the far future anyway and still just for learning.Thanks for this suggestion!

Look into build configuration, there are tools like jam, cmake, premake, etc...  They will allow you to generate your project base on configuration settings.  For instance in your source, you could have a folder for OpenGL and Directx implementations, then base on the configuration your project would build different files.  This is to control which files to build, you still need to work with macros to handle platform specific includes and implementations.

I should definitely look into those programs, however for this purpose I think it's too much of a hassle when building the actual implementation wouldn't it? Wouldn't that mean that for every test I want to do, I would have to build it with cmake (or similar) and compile that specific configuration?

I was also thinking of perhaps making a plugin kind of system, like Ogre3D has. Creating a DLL of either and plug it in. How would this work with cross platform (win, linux, mac) in mind? I very little experience with linux and near to nothing with macs. Do they work differently?