How to make a CMake package?

2019-05-10 23:05发布

I'm attempting to make a CMake package for Crypto++ inclusion in CMake projects, this will end up in the noloader/cryptopp-cmake repo if it gets done.

The ultimate goal is to come up with a working cross-platform FindCryptoPP.cmake file which can be dropped in the Crypto++ source directory to do things like:

find_package(CryptoPP REQUIRED)
target_link_libraries(libbiocoin cryptopp-static)

Or:

find_package(CryptoPP REQUIRED)
target_link_libraries(libbiocoin cryptopp-shared)

In a finished application and have it "just work."

My current best solution within a CMake application is to build Crypto++ for the platform, stick the resulting archive or library in a lib directory, reference that within the CMakeLists.txt and pull it in that way, but of course that requires packaging a binary distribution of the compiled Crypto++ for every platform targeted by the application, which would be nasty to maintain and generally bad even if it weren't crypto code.

标签: cmake
1条回答
地球回转人心会变
2楼-- · 2019-05-10 23:36

It's better to provide a CMake configuration file. find_package will look for a configuration file if no FindFoo.cmake find script is provided. One advantage over a find script is that you won't end with different, maybe conflicting versions of the find script.

See https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html, especially the section Create Layout.

查看更多
登录 后发表回答