CLion uses Apache's Velocity Template Language (VTL) to create templates for C++ and C files. On CLion's help (https://www.jetbrains.com/help/clion/file-template-variables.html) a bunch of variables that can be used are listed.
I was wondering however, if it would be possible to use the directory where a C++ file is created as a variable in one of my templates? I'm asking this because I like to structure my source files in a java/package-type fashion.
All files in the "Utils" directory are part of the "Utils" namespace, all packages in the "Ui" Directory are part of the "Ui" namespace etc...
So I was wondering if there's any way for me to obtain the parent directory of a file so I can use it in a template? (Maybe by setting a variable in my CMakeLists.txt
?)
Here's an example of what I'd like to achieve
#parse("C File Header.h")
#[[#ifndef]]# ${INCLUDE_GUARD}
#[[#define]]# ${INCLUDE_GUARD}
${NAMESPACES_OPEN}
namespace ${CWD}
class ${NAME}
{
};
${NAMESPACES_CLOSE}
#[[#endif]]# //${INCLUDE_GUARD}
where ${CWD}
represents the folder the file is in.
The ${NAMESPACE_OPEN}
and ${NAMESPACE_CLOSE}
directives seem to be purely symbolic for CLion, their websites lists it as "indicates the beginning/end of a namespace block created during refactoring."