hanickadot / compile-time-regular-expressions

Compile Time Regular Expression in C++
https://twitter.com/hankadusikova
Apache License 2.0
3.32k stars 183 forks source link

Improve the quality of the CMake build scripts #230

Open friendlyanon opened 2 years ago

friendlyanon commented 2 years ago

This commit does a couple changes:

friendlyanon commented 2 years ago

Hmm, I thought about the pkgconfig code and it's actually not quite right as it is now either.

The problem with generating a pkgconfig file via CMake is that it does not fit the model of CMake. The prefix variable has to be absolute in the .pc file, however CMake deals with paths relative to the prefix. The final prefix can change at all times, via CMAKE_INSTALL_PREFIX, --prefix parameter during install time, at CPack time and the resulting deb/rpm files can be extracted anywhere as well. If one needs a pkgconfig file for packaging purposes, both deb and rpm CPack generators allow the user to add post-install scripts that can generate it if necessary.

As a clarification: the case where the user is installing with cmake --install or the install target both work fine, but packaging is where things break due to the prefix variable needing to be absolute in the .pc file.

alexios-angel commented 2 years ago

It seems that when you run

cmake .
make test

Screenshot from 2021-11-14 18-18-00

friendlyanon commented 2 years ago

You are correct. The project doesn't use the normal test mechanisms for whatever reason.

https://github.com/hanickadot/compile-time-regular-expressions/blob/b51d3290865615487cbef75c7c9dba36b9e70c6a/tests/CMakeLists.txt#L1-L10

Note the lack of add_test calls. I think that could be added to this PR as well, since that fits the topic.
I will rebase the first commit and add the appropriate changes there.

friendlyanon commented 2 years ago

I cleaned up things around the CPack config and pkgconfig.

The CPack config with the project specific defaults is configured to the CPack(Source)Config-ctre.cmake file in the root binary directory. These files include() the CMake generated ones and overwrite some values with set() calls. Using these files can be done with cpack --config ....

The .pc file now uses the configure time CMAKE_INSTALL_PREFIX variable to get its prefix value. This makes it possible to anticipate ahead of time where the generated package files will be installed to. There is a warning emitted during the very first configuration if the pkgconfig option is enabled without CMAKE_INSTALL_PREFIX also being set. If the project is installed with cmake --install ... --prefix ... however, then the .pc file will contain the wrong prefix. This sould probably be documented in https://github.com/hanickadot/compile-time-regular-expressions/pull/231 cc @angeletakis

alexios-angel commented 2 years ago

@friendlyanon Will do 💯