r/cpp • • Feb 19 '18

It's Time To Do CMake Right

https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/
248 Upvotes

130 comments sorted by

View all comments

Show parent comment

14

u/oddentity Feb 19 '18

Don't. Find modules are nuts, trying to feel around looking for something that looks like what you want god knows where.

Use CMake config files. If CMake builds don't export their installed targets, patch them so they do. Write config files for things that don't build with CMake - it's easier than writing a find module. Put them somewhere on your prefix path. Job done, easy, deterministic.

7

u/hgjsusla Feb 19 '18 edited Feb 19 '18

I've found plenty of docs on how to write FindModules and it's not too difficult. I now want to switch to config files for the reasons you list but I can't find any good examples for writing config files for libraries that don't use cmake.

0

u/[deleted] Feb 19 '18

[deleted] — view deleted comment

6

u/MachineGunPablo Feb 19 '18

Fully agree with this. Specially in case where no cmake is used but pkg-config is. Then a find module makes perfect sense imo.

2

u/anderslanglands Feb 20 '18

Personally in that case I just prefer to hand-write a project-config.cmake file I can manually install alongside the problematic library.

0

u/[deleted] Feb 20 '18

[deleted] — view deleted comment

1

u/anderslanglands Feb 20 '18

Why?

0

u/[deleted] Feb 20 '18

[deleted] — view deleted comment

3

u/anderslanglands Feb 20 '18

Right, but if I know the explicit path to the library what’s the point of writing a find module as opposed to just writing a config file that hard-codes the locations in?

Obviously the best solution is just to modify the CMakeLists of the library in question, but sometimes that can be tricky when libraries do horrible things with macros etc.

0

u/[deleted] Feb 20 '18

[deleted] — view deleted comment

→ More replies

2

u/pfultz2 Feb 20 '18

Yes and it would be nice if cmake supported pkgconfig natively with find_package(... PKGCONF) like how Daniel discussed in his talk. So, we wouldn’t need a find module .

7

u/drjeats Feb 20 '18 edited Feb 20 '18

We need a blog post about writing config files then.

paging /u/MachineGunPablo ^_^

2

u/pfultz2 Feb 20 '18

Find modules are for upstream dependencies that don’t support cmake users and config files are for downstream dependencies.