Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to find crypto++ package using cmake? #249

Closed
redboltz opened this issue Aug 29, 2016 · 15 comments
Closed

How to find crypto++ package using cmake? #249

redboltz opened this issue Aug 29, 2016 · 15 comments

Comments

@redboltz
Copy link

I read crypto++ wiki https://cryptopp.com/wiki/CMake#Using_the_library_in_other_projects

I tried to add the following code in my cmake project:

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

However, I got the following error message:

  By not providing "FindCryptoPP.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "CryptoPP",
  but CMake did not find one.

  Could not find a package configuration file provided by "CryptoPP" with any
  of the following names:

    CryptoPPConfig.cmake
    cryptopp-config.cmake

  Add the installation prefix of "CryptoPP" to CMAKE_PREFIX_PATH or set
  "CryptoPP_DIR" to a directory containing one of the above files.  If
  "CryptoPP" provides a separate development package or SDK, be sure it has
  been installed.

It seems that "FindCryptoPP.cmake" not found. Does the file provide by cmake or crypto++?
I'm using cmake 3.6.1 and crypto++ 5.6.3.

@redboltz
Copy link
Author

I looked over "Starting from Crypto++ 5.7 ...". Is the functionality find_package(CryptoPP REQUIRED) is not provided yet? or provided on the master branch?

@noloader
Copy link
Collaborator

noloader commented Sep 2, 2016

@redboltz,

I'm using cmake 3.6.1 and crypto+ ....

Is the functionality find_package(CryptoPP REQUIRED) is not provided yet? or provided on the master branch?

We added Cmake support recently. Varying levels of support have been provided since it was initially added. I'm guessing if find_package(CryptoPP REQUIRED) is available, then its available in Master at the moment.

Here's more of the back story... Some users wanted Cmake, so we added the Cmake configuration file to the library distribution with the explicit understanding the community has to maintain it (because the project's build system is Make based). I believe this occurred at 5.6.3 release. As issues are uncovered, I forward them to the Cmake folks, and they come back with a patch. I tried adding Cmake testing to my regime, but there were so many problems I kind of gave up on it.

We are gearing up for a 5.6.4 release. Whatever is in Master will be included in 5.6.4. But I can't really attest to how robust Cmake support is since all my testing uses the Makefile. Eventually the Cmake gear will get enough community patches where it mostly works under most use cases.

And if you have a patch, then please make a Pull Request. I ask that you test the PR on Ubuntu 12.04 before you submit it since we are trying to ensure things "mostly work" under modern platforms. Since 12.04 is LTS and support is in effect, its something we should expect.

@redboltz
Copy link
Author

redboltz commented Sep 2, 2016

@noloader , thank you for the response. Let me clarify the situation. It seems that you answered about building cryptopp itself using cmake. Is that right?

If it is so, I'm asking the different topic. That is how to find cryptopp using cmake from other cmake projects, such as my project. As far as I know, it doesn't require cryptopp can be build using cmake. It requires FindCryptoPP.cmake. I checked the master branch of cryptopp, the file not found.

I found FindCryptoPP.cmake at the following location:

https://bitbucket.org/sergiu/cryptopp-cmake/src/d410d9d875f2036365ae49885e3d631c56e62d75/FindCryptoPP.cmake

It works well for me. The trivial problem is CRYPTOPP_INCLUDE_DIRS should be CRYPTOPP_INCLUDE_DIR in the line 14. It is a part of comments.

The file FindXxxx.cmake is usually located on cmake/moduled directory.

Here is an example:
https://github.com/SOCI/soci/tree/master/cmake/modules

@noloader
Copy link
Collaborator

noloader commented Sep 3, 2016

Let me clarify the situation. It seems that you answered about building cryptopp itself using cmake. Is that right? ... If it is so, I'm asking the different topic....

Oh, My bad. That shows you how little I know about Cmake.

Send me your email address; mine is noloader, gmail address. I'll spin up an off-list thread with the Cmake folks so you can hash out the details. Once you guys figure out if/what is needed, then we can merge a PR.

@mouse07410
Copy link
Collaborator

mouse07410 commented Sep 4, 2016

Currently it is possible to build Crypto++ itself using Cmake. That does not require FindCryptoPP.cmake.

FindCryptoPP.cmake file allows other Cmake-based applications to find and link with Crypto++. We are not including it at the moment. Adding it is under consideration, and you could help by debugging the one that Sergiu provided. If/when it is debugged, and if Sergiu does not mind (and is OK with Crypto++ license), this file could be added to the Crypto++ distro. As an alternative, we could refer to it in the README or Wiki.

@redboltz
Copy link
Author

redboltz commented Sep 5, 2016

Thank you all, I will debug FindCryptoPP.cmake. I will also contact to Sergiu.

@noloader
Copy link
Collaborator

noloader commented Sep 6, 2016

@mouse07410,

Is this something that Cmake should install in its install recipe? That is, suppose I run:

cd cryptopp
cmake

After cmake runs and generates the Makefile(s), does the install recipe have a line to copy FindCryptoPP.cmake to the proper place if FindCryptoPP.cmake is present? If not, is there an option to have Cmake handle it?

Or should we ask on Stack Overflow?


Related, from CMake:How To Find Libraries on their wiki (I'm just starting to read it):

... Let's take the very popular bzip2 library. There is a module named FindBZip2.cmake. Once you call this module with find_package(BZip2), cmake will automatically fill in the values of various variables, which you can then use in your CMake script....

Should we be working with the Cmake project by providing them with a FindCryptoPP.cmake? They can distribute it, and we won't have to worry about it.

Also, should our Cmake file be called CryptoPP.cmake instead of cryptopp-config.cmake? Is there a naming standard we should be following?

@mouse07410
Copy link
Collaborator

Is this something that Cmake should install in its install recipe?

I believe it should.

After cmake runs and generates the Makefile(s), does the install recipe have a line to copy FindCryptoPP.cmake to the proper place if FindCryptoPP.cmake is present? If not, is there an option to have Cmake handle it? Or should we ask on Stack Overflow?

I don't know the answer to any of the above. :-(

Should we be working with the Cmake project by providing them with a FindCryptoPP.cmake? They can distribute it, and we won't have to worry about it.

I think it is definitely worth a try. The worst they can say is "No, you worry about your module yourselves", and it's not likely.

Also, should our Cmake file be called CryptoPP.cmake instead of cryptopp-config.cmake? Is there a naming standard we should be following?

I haven't seen a .cmake file so far. All the Cmake projects I dealt with had a file CMakeLists.txt that describes the project and tells Cmake what and how to build. Often they'd include utils.cmake that provides project-specific functions Cmake may need to call in the process of building Makefiles, etc.

@noloader
Copy link
Collaborator

noloader commented Sep 10, 2016

I reached out to a Cmake subject matter expert for the FindCryptopp.cmake task.

On Sat, Sep 10, 2016 at 7:32 AM, noloader wrote:
> Hi XXXXX,
>
> The topic of FindCryptopp.cmake came up recently at
> https://github.com/weidai11/cryptopp/issues/249. I think a separate
> user experienced
> https://stackoverflow.com/questions/39407666/cmakefile-build-error.
>
> We believe these are side effects of Crypto++ distributing a
> CMakeList.txt and cryptopp-config.cmake files. We want to squash these
> user problems or nip them in the bud, so to speak.
>
> How do we do about getting a getting FindCryptopp.cmake added to
> Cmake distribution?
>
> -----
>
> I read http://cmake.org/Wiki/CMake:How_To_Find_Libraries, but it does
> not discuss the procedure.
>
> I tired subscribing to cmake-dev to ask, but the confirmation email
> never arrived.
>
> -----
>
> Thanks in advance,

@noloader
Copy link
Collaborator

Florian got back with us. Below is the reply. It does not look like we do anything special.

Normally you don't add CMake enabled libraries to CMake itself. The
scripts there tend to age very fast.
...

And I'm not sure if the developer's list is open again for subscription?
They had some spamming problems lately and shut-down the registering
process temporarily.

@FloriansGit
Copy link
Contributor

FloriansGit commented Sep 20, 2016

Sorry for tapping into this so late in the discussion. I had a quick look at Sergiu's work and it's mainly based of having the CRYPTOPPROOT environment variable set. If that's not set - and Crypto++ can't be found in any of the standard locations - it won't work.

Regarding what does Crypto++ provide so far: the find_package() as described in https://cryptopp.com/wiki/CMake#Using_the_library_in_other_projects should work, but only if you have build and installed the library before.

I don't think we need to add more CMake code in form of find scripts here, we may just need to extend the https://cryptopp.com/wiki/CMake#Using_the_library_in_other_projects chapter a little.

How about e.g. adding some code snippet that would pull the code directly from GitHub and would add it directly to any CMake project which wants to use it?

@FloriansGit
Copy link
Contributor

FloriansGit commented Sep 22, 2016

I don't have edit rights in the Wiki (the validation emails seem not able to reach me), so here is an example I wanted to suggest;

cmake_minimum_required(VERSION 2.8)
project(UsingCryptopp)

find_package(Git REQUIRED)

if (NOT EXISTS "${CMAKE_SOURCE_DIR}/cryptopp")
    execute_process(
        COMMAND "${GIT_EXECUTABLE}" clone https://github.com/weidai11/cryptopp.git
        WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
    )
endif()

set(CMAKE_SKIP_INSTALL_RULES TRUE)
add_subdirectory(cryptopp)

add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} cryptopp-static)

@pip010
Copy link

pip010 commented Aug 14, 2018

any progress on cmake find_package ? as it stands this library is useless .... sharing .sln files in 2018 !?

@noloader
Copy link
Collaborator

noloader commented Aug 14, 2018

@pip010,

We had too many issues with CMake so we removed it from the sources. We did not have the time to work all the problems.

CMake is now being hosted at Crypto++ | CMake. CMake for Crypto++ is now a community effort.

I don't know if the feature works or not.

You might try Botan or OpenSSL if Crypto++ does not meet your needs.

@pbeTrifork
Copy link

One "workaround" could be to use conan as a dependency manager for your C/C++ libraries.
It works fine with Crypto++ and CMake and it is in the official repositories at Conan Center Index

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants