open-quantum-safe / liboqs

C library for prototyping and experimenting with quantum-resistant cryptography
https://openquantumsafe.org/
Other
1.76k stars 431 forks source link

CMake ProjectConfig.cmake #763

Closed grassnick closed 3 years ago

grassnick commented 4 years ago

Hi! I am integrating liboqs into another project where I am heavily relying on CMake's *Config.cmake files via find_package(), whenever that's possible for my dependencies.

Since liboqs has switched to CMake for building, I am wondering if you are planning to support mentioned configuration files. These would also greatly benefit the packaging for various GNU/Linux Distributions, where liboqs could be installed via the global package manager.

References:

Is this feature on your schedule?

xvzcf commented 4 years ago

As the project is still at an experimental stage (see this), we currently have no plans of adding liboqs to Linux package managers. That being said, adding a ProjectConfig.cmake for other purposes is certainly something I intend to look into.

xvzcf commented 4 years ago

Could you try checking out this commit and seeing if find_package() works for you?

grassnick commented 3 years ago

Thank you for your effort @xvzcf! The cmake configuration files where created and installed without requiring any change of the build scripts. However, two problems occured:


1: I wasn't able to find the module via find_package

find_package considered the following locations for the Config module:

    /usr/local/oqsConfig.cmake
    /usr/local/oqs-config.cmake
    /usr/oqsConfig.cmake
    /usr/oqs-config.cmake
    /usr/lib64/cmake/oqs/oqsConfig.cmake
    /usr/lib64/cmake/oqs/oqs-config.cmake
    /usr/lib/cmake/oqs/oqsConfig.cmake
    /usr/lib/cmake/oqs/oqs-config.cmake
    /oqsConfig.cmake
    /oqs-config.cmake
    /lib64/cmake/oqs/oqsConfig.cmake
    /lib64/cmake/oqs/oqs-config.cmake
    /lib/cmake/oqs/oqsConfig.cmake
    /lib/cmake/oqs/oqs-config.cmake
    /opt/oqsConfig.cmake
    /opt/oqs-config.cmake

  The file was not found.

CMake Error at CMakeLists.txt:4 (find_package):
  By not providing "Findoqs.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "oqs", but
  CMake did not find one.

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

    oqsConfig.cmake
    oqs-config.cmake

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

The configuration file was deployed in /usr/lib/cmake/oqs/liboqsConfig.cmake

The command fails analogously, when searching for liboqs. According to the documentation, the correct pattern has to be of the form of <prefix>/(lib/<arch>|lib*|share)/cmake/<name>*/

Changing the DESTINATION property of the config export to ${CMAKE_INSTALL_LIBDIR}/cmake/liboqs fixes the problem.


2: The installation destination for the public header files was changed I am not sure, if this was done on purpose, but I can not build the example executable stated in the wiki.

Reverting the change fixed the issue.


This is the minimum example CMakeLists.txt I used:

cmake_minimum_required(VERSION 3.15)
project(oqstest)

find_package(liboqs REQUIRED LIBOQS)

set(SOURCES main.c)

add_executable(oqstest ${SOURCES})

target_link_libraries(oqstest PUBLIC OQS::oqs)

main.c is https://github.com/open-quantum-safe/liboqs/wiki/Minimal-example-of-a-post-quantum-KEM


And the patch to get it to work:

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 8d4cfc6e..49e60349 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -89,8 +89,8 @@ install(TARGETS oqs EXPORT liboqsConfig

 install(EXPORT liboqsConfig
         NAMESPACE OQS::
-        DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/oqs
+        DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/liboqs
 )

 install(FILES ${PUBLIC_HEADERS}
-        DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/liboqs)
+        DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/oqs)
xvzcf commented 3 years ago

Closed by https://github.com/open-quantum-safe/liboqs/pull/840