mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.47k stars 1.59k forks source link

Meson equivalent to CMake's GenerateExportHeader `generate_export_header`? #11892

Open SamuelMarks opened 1 year ago

SamuelMarks commented 1 year ago

Relevant:

What's the equivalent of this in Meson?

xclaesse commented 1 year ago

That would be that PR https://github.com/mesonbuild/meson/pull/10199

eli-schwartz commented 1 year ago

Neither of those two issues are related to the cmake module in question.

But also, the cmake module in question takes several parameters to select the exact macro names used, and then it templates those into a statically determinable *.h file whose only inputs are:

Nothing is project-specific, and both checks in question can be better done via preprocessor macros. It's actually far more common for projects to do it that way:

In practice you don't care about SunPro C.

Incidentally, as I recall cmake gets the "using non-Windows compilers and building statically" case incorrect.

SamuelMarks commented 1 year ago

@eli-schwartz I suppose I could manually write out that header file with all the different targets I care about, which in my case is: Windows:

Linux, macOS, *BSD, SunOS:

My main fear is that I don't cover enough platforms so that when CMake gets a contrib, e.g., for LCC, I don't automatically gain support for their visibility syntax.

eli-schwartz commented 1 year ago

I would not worry about that since the cmake module is approximately as stable as a thing that never changes.

Also because unix compilers have more or less converged on the GNU syntax (e.g. sunpro supports both now) and all Windows compilers support the MSVC syntax for compatibility (and because if you're going to compile code with a Windows compiler and then include its headers from an MSVC cl.exe project, you must support whatever cl.exe supports).

eli-schwartz commented 1 year ago

Example code: https://gitlab.freedesktop.org/freetype/freetype/-/blob/master/include/freetype/config/public-macros.h#L65 https://github.com/fribidi/fribidi/blob/b54871c339dabb7434718da3fed2fa63320997e5/lib/fribidi-common.h#L44-L61

SamuelMarks commented 1 year ago

Ok it's a little verbose but I created this by merging the generated header from MSVC and gcc (Linux), and your SunPro C hint: https://github.com/SamuelMarks/cmocka/blob/msvc2005/pregen/cmocka_export.h

Not sure if it'd still be a good idea for meson to support this…