I modified the call to
find_package()
so that it now contains the path to the directory
That would probably also work, but usually such paths are provided in CMAKE_PREFIX_PATH
variable, because that way you won’t need to hardcode them in your project.
aren’t those files only needed if one is compiling the library from source?
No, those files (LibraryNameConfig.cmake
and such) are produced after one has built and installed the library (if its project is set up properly). They are used for these find_package(LibraryName CONFIG)
statements in other projects which would like to use that library. The Protobuf package that you have downloaded indeed does not have them, as people who built and packed it did not bother with making a CMake package (that’s their right, nothing wrong with it). So you can’t use find_package(LibraryName CONFIG)
form, you would use find_package(LibraryName)
instead, but that is also unlikely to work, because I suspect there is no pre-made module for finding Protobuf in your environment. Here’s a documentation page about finding packages, just in case.
Having built Protobuf from sources yourself you’d probably get the same result.
So what you can do is (optionally) write your own FindProtobuf.cmake
module, in which you would set the required variables, such as library path and name, include directories and so on, or just hardcode those values in your project. And then you’ll need to set those in target_include_directories()
and target_link_libraries()
.