I'm writing a Cross-compiling Toolchain file for VxWorks. Since it's an unknown system to cmake a also have write platform files (those in ../Modules/Platform
).
Beside my toolchain file I have written these platform files so far:
- VxWorks.cmake (VxWorks OS settings)
- VxWorks-gcc.cmake (WindRiver (Gnu) compiler settings)
- VxWorks-gcc-[CPU].cmake (CPU specific settings, is the processor as specified in the toolchain file)
Everything works fine with my files at the moment.
But some of the default platform files contain a include guard / include blocker like this one:
if(__WINDOWS_GNU)
return()
endif()
set(__WINDOWS_GNU 1)
(from: Modules/Platform/Windows-GNU.cmake
)
So i'm wondering: Do I have to insert such a guard too? And when it's a good idea to insert them?
It is possible to use include guards but with some limitations as mentioned here:
In my case I have
IncludeGuard.cmake
file with the following content:In common cmake files I use the following snippet at the beggining:
Macro
cmake_include_guard
usereturn()
to stop further content processing.CMake modules can include each other, so it can lead to diamond problem. If you are lucky, you've got double work for setting some variables, but if you will need some complex stuff, things may get worse.
Example:
FindB.cmake
FindA.cmake
CMakeLists.txt
Now run cmake .
Just use guards at beginning of the module (let variable describe path to prevent collision)
FindB.cmake