approvals / ApprovalTests.cpp

Native ApprovalTests for C++ on Linux, Mac and Windows
https://approvaltestscpp.readthedocs.io/en/latest/
Apache License 2.0
316 stars 51 forks source link

Allow users to detect Approval Test version in CMake #91

Closed claremacrae closed 3 years ago

claremacrae commented 4 years ago

This arose out of #40

How about using CMake to generate the version number? https://cmake.org/cmake/help/latest/guide/tutorial/index.html#adding-a-version-number-and-configured-header-file

Originally posted by @dheater in https://github.com/approvals/ApprovalTests.cpp/issues/40#issuecomment-569137963

jwillikers commented 4 years ago

For header-only libraries, I generate a version header this way. Unlike the example, I prefer to use constexpr instead of macros for type-safety.

claremacrae commented 4 years ago

Thanks @jwillikers

Can I check that I understand...

We now have this:

https://github.com/approvals/ApprovalTests.cpp/blob/d997f56343ac70db621fd36593fa55b87b4eb975/build/prepare_release.py#L62-L81

That generates a #define in each release...

Are you suggesting to change that to something constexpr - if so, I hadn't see that before, but I like that idea...

If not that, I'm unsure how your comment relates to CMake... can you expand on it, please?

jwillikers commented 4 years ago

I whipped up an example because I think that will explain things perfectly. 👨‍🏫

Example: https://github.com/jwillikers/cmake_configure_version_header

Standards before C++17 would use char[] instead of std::string_view.

claremacrae commented 4 years ago

Thanks @jwillikers - that example is really clear... And I see how this would be useful...

Not everyone who uses this project uses it with CMake, so I would stick with our current structure - but I see that constexpr is a nicer - type-safe - way of setting the various version numbers...

I'll set up a separate issue to convert the #define approach in to constexpr instead...

isidore commented 3 years ago

closing as not really needed