'C++/C: Migration from Make to Cmake (Windows and Linux): Platform specific implementations

I'm currently migrating a project of 2 million C++/C code lines from Makefiles to using Cmake. Most things are pretty straight forward, but I can't seem to find the best practice to achieve the following:

Many low level (legacy) components in my kernel library use compiler guards to differentiate between the Linux and Windows implementations in the following form:

#ifdef WINDOWS
// #include ...
#else
// #include ...
#endif

and/or:

void lowLevelFunction()
{
#ifdef WINDOWS
    // Windows implementation
    return;
#else
    // Linux implementation
    return;
#endif
}

Is there a best practice to do this on Cmake or to somehow delegate?

Thank you



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source