Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meson equivalent to CMake's GenerateExportHeader generate_export_header? #11892

Open
SamuelMarks opened this issue Jun 19, 2023 · 6 comments
Open

Comments

@SamuelMarks
Copy link

Relevant:

What's the equivalent of this in Meson?

@xclaesse
Copy link
Member

That would be that PR #10199

@eli-schwartz
Copy link
Member

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:

  • the cmake system name, if Windows
  • the compiler used, if it supports -fvisibility=hidden

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:

  • #if defined _WIN32 || defined __CYGWIN__ then:
    • if defined MYLIB_STATIC, do nothing
    • elif defined MYLIB_FOR_BUILD, define __declspec(dllexport)
    • else define __declspec(dllimport)
  • #elif defined __GNUC__ && __GNUC__ >= 4
    • define __attribute__((visibility("default")))
  • #elif defined __SUNPRO_C
    • define __global

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
Copy link
Author

@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:

  • MSVC (2005+, x86 and x64 targets)
  • OpenWatcom's DOS target
  • Cygwin
  • MinGW (x86 and x64 targets)
  • clang

Linux, macOS, *BSD, SunOS:

  • gcc
  • clang

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
Copy link
Member

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).

@SamuelMarks
Copy link
Author

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…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants