Take the 2-minute tour ×

Lets say I have in a main cpp file a set of directive allowing to instanciate my binaries that implement an template algorithm with a given type using typedef and preprocessor directive for the choice of the type before compilation:

 #ifdef MS1
     typedef  MSVariableInterface1 InterfacorType;
       #ifdef MS2
           typedef  MSVariableInterface2 InterfacorType;

int main()
 {...        //use InterfacorType as the type for template

I would like my cmakelists to automatically compile the code with the different template instanciation knowing the different possible values for the preprocessor variables. Do you know how can I do that ?

Moreover I guess that this is not the correct way to deal with the problem, have you another suggestion to "unroll" the different instanciations of a (optionaly multi) template code given the set of type that can take each template. Such a solution will allow me to create a single binary to deal with all cases (with arguments allowing to choose the instanciation of interest) instead of creating a binary per instanciation. Thanks!

share|improve this question
Not related to the question, but this code would be clearer if it was written with #if defined(MS1) ... #elif defined(MS2) ... #endif. No need for the nesting. –  Pete Becker Dec 6 '12 at 15:39

1 Answer 1

You can enable them using add_definitions:

share|improve this answer

Your Answer


