Reputation: 16802
I am reverse engineering someone's code and I came across a line like so in the CMake file
FIND_PATH(OPENSSL_INCLUDE_DIR openssl/ssl.h
/usr/local/opt/openssl/include
/usr/opt/openssl/include
/usr/local/include/openssl
/usr/include/openssl
/usr/local/include
/usr/include
)
INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
FIND_LIBRARY(LIB_CRYPTO crypto PATHS
/usr/local/opt/openssl/lib
/usr/opt/openssl/lib
/usr/local/lib
/usr/local/openssl/lib
/usr/lib
/usr/lib/openssl
)
I come from a make background, so I would use something like LDFLAGS=$(shell pkg-config --cflags --libs openssl
but I would never know what header file is being included.
It seems impractical/unfeasible to know every header file included in, for example, a large dlib project which links opencv and cuda libraries, so my question is this:
When/Why would you actually reference the header file by name?
Upvotes: 1
Views: 285
Reputation: 54737
CMake needs to support platforms where pkg-config
is not available.
You are correct that the find mechanism is somewhat primitive. That is why CMake also offers more sophisticated options like config-file packages or even pkg-config
support. The problem with all these approaches is that they require some king of external support. Package config scripts must be provided by the dependency you are trying to find and pkg-config
must be available and configured properly on the platform you are trying to build on.
The various find_*
commands have no such prerequisites. They simply try to find a file or directory the filesystem. That's what makes them the most powerful commands in a way, because you can always accept a hint provided by the user where to find the files (which the people in your example code did not do btw, so shame on them) and then the find can work its magic. But it's also the most inconvenient, as it's easy to mess up and tedious to use in practice.
So keep in mind that CMake's primary goal is to be portable. Don't shy away from whatever mechanisms your platform offers to make configuring the build more convenient, but also don't lock out people that are less fortunate and have to work on platforms where those mechanisms are not available.
Upvotes: 1