Reputation: 1283
I have a project that includes a git submodule. A submodule file Class.h
I want to use is the following:
#pragma once
class Class
{
public:
int f() const
{
#ifdef MY_MACRO
return 11111;
#else
return 88;
#endif
}
};
And my calling code is:
#include "Class.h"
#include <iostream>
int main()
{
Class c;
std::cout << c.f() << '\n';
return 0;
}
I added submodule to my project by git submodule add
and adding a reference to project to this submodule in Visual Studio (2022). Now, the solution contains my project and the submodule. I cannot define macro in submodule project as it will affect other projects. So, how can I pass macro to submodule just for this single project?
Update: A little clarification: I know how to add a macro to my project - usually in VS I add it through project' settings - C/C++ -> Preprocessor -> Preprocessor definitions
(with respect to configuration). For example, right now I have this field set to MY_MACRO;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
. However VS ignores these parameters when it compiles the submodule' project (and I think, it's reasonably). I need to pass this MY_MACRO
to compiler when it builds the submodule's project without affecting submodule's repo. I don't want to create different configurations for submodule's project just for defining macrosses as if I have more macrosses I will need to create a lot of configurations - for each combination, I don't think it's a good idea.
Upvotes: 0
Views: 104
Reputation: 1283
Thanks to user7860670 for providing link to this thread - Can I set a solution-wide macro from VS a project property sheet?. This problem indeed may be solved by properties sheets. Actually by using properties sheet in this way you can override any parameter of the sub-project.
Upvotes: 0