CMake cross platform use of generate_export_headers and inline template functions

44 views Asked by At

Background

Generate export headers generates dllimport/export, and equivalent explicit exports/imports for GCC. However, unlike MSVC, GCC and Clang support visibility modifiers on template functions. This apparently has actual real world consequences. And following Craig Scott, he heavily implies that one should be using export for inline as well, this is cooberated via https://cmake.org/cmake/help/latest/module/GenerateExportHeader.html where both recommend the use of the variables

set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)

at the top of the CMakeLists.txt file. The problem is that MSVC appears to not support DLL export/import semantics on template functions and classes.

Question

So how do I square the circle on these two incompatible requirements? Best practices is recommending setting inlines to hidden, and while that only effects GCC and CLang, that means that exports are needed to make those symbols visible right? But because that isn't supported with MSVC, I can't use those exports on those symbols right in a cross platform way right?

0

There are 0 answers