Port your engine to each platform. There's nothing special about it. If you have some code that is Windows-only, then either add some #ifdef logic in the file or add a second file (so you'd have FooWindows.cpp
and FooLinux.cpp
or whatever) that implements that feature on the other OS(es) you care about.
The one-click publish stuff that an engine like Unity has is allowed because Unity itself is never modified by the end-user. You're just writing scripts and data, so the engine has pre-built binaries for all the platforms and the publish button just bundles those binaries together with the data.
Other engines rely on build systems and cross-compilers to create the compiled game when needed, just like you would do with any non-game cross-platform application.
For things like HTML5, there are tools like emscripten that can compile a C++ application to run in JavaScript. You basically just need to make another port of your engine for emscripten (since it can't use any arbitrary C++ library/feature).
You don't have to rewrite your whole game, but you're definitely going to have to do a lot of development, coding, and porting work for each new platform you want to support.