Issue
I can't find how to declare function like macros in CMake.
I need a macro function like:
#define MYFUNC(foo) QString( foo + "_suffix" )
to be defined by my CMakeLists.txt file. I tried:
add_definitions("-DMYFUNC(foo)=QString\(foo+\"_suffix\"\)")
and
add_definitions("-DMYFUNC\(foo\)=QString\(foo+\"_suffix\"\)")
but none works, compiler (VS2015) always reports MYFUNC
is undefined...
Solution
From the Visual Studio documentation on /D:
The /D option doesn't support function-like macro definitions. To insert definitions that can't be defined on the command line, consider the /FI (Name forced include file) compiler option.
For completeness, GCC does support defining function macros from the commandline:
If you wish to define a function-like macro on the command line, write its argument list with surrounding parentheses before the equals sign (if any). Parentheses are meaningful to most shells, so you should quote the option. With sh and csh, -D'name(args…)=definition' works.
Answered By - Botje Answer Checked By - Pedro (WPSolving Volunteer)