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

Add support for local statically linked openssl #175

Closed
maxweisel opened this issue Apr 2, 2020 · 5 comments
Closed

Add support for local statically linked openssl #175

maxweisel opened this issue Apr 2, 2020 · 5 comments

Comments

@maxweisel
Copy link
Contributor

At the moment CMakeLists.txt uses find_package() to find OpenSSL. Which works great if it's installed on your system. However, in my project, I already compile and link against a static library copy of openssl, so I'd like to just use those symbols for IXWebSocket.

find_package(OpenSSL) does support searching for static libraries, but this has to be done at cmake generate time which means even if my cmake project builds openssl, the static library needs to be present before I can even run make which is before I'd be able to compile openssl myself and so find_package(OpenSSL) will always fail.

I'd love to be able to specify something like OPENSSL_INCLUDE myself. I'm compiling a static library version of ixwebsocket, so I don't even really need the project to do any linking for me. All it really needs are the headers for the openssl library I'm using in my project.

I'm happy to implement this and open a PR, I figured I'd file a github issue in case you had any opinions on how you'd like to integrate this into the project.

Max

@maxweisel
Copy link
Contributor Author

I'm thinking I might just switch from add_subdirectory to ExternalProject_Add. This would allow me to save all IXWebSocket cmake configuration until build time. I'll experiment with that, but I think add_subdirectory is most likely still the correct way for me be using ixwebsocket in a cmake project, so I'd love to be able to continue with that direction if possible.

Max

@bsergean
Copy link
Collaborator

bsergean commented Apr 2, 2020 via email

@bsergean
Copy link
Collaborator

bsergean commented Apr 2, 2020 via email

@maxweisel
Copy link
Contributor Author

afaik curl uses autoconf / make, which supports specifying an openssl path with --with-ssl: https://curl.haxx.se/docs/install.html. I believe their CMake implementation was more for people who wanted to easily include it in their own repo, but it's not a complete reimplementation of their main build system.

I think the simple approach would be to look for a variable like STATIC_OPENSSL_INCLUDE if it's not present, default back to the find_package() approach.

Another small change that would help would be to split the ixwebsocket and CLI targets into separate CMakeList.txt files that are all included in a root CMakeLists.txt via add_subdirectory(). Then you can use find_package() in the CLI where you need to link against system openssl, and IXWebSocket will only need to reference headers. It also means I could use add_subdirectory() on just the library instead of the whole project.

Max

@bsergean
Copy link
Collaborator

It turns out that this should already be possible.

  1. set OPENSSL_FOUND to 1.

  2. Manually set those values:

  • OPENSSL_DEFINITIONS
  • OPENSSL_INCLUDE_DIR
  • OPENSSL_LIBRARIES

the block that deals with openssl has a way not to trigger find_package

    # This OPENSSL_FOUND check is to help find a cmake manually configured OpenSSL
    if (NOT OPENSSL_FOUND)
      find_package(OpenSSL REQUIRED)
    endif()
    message(STATUS "OpenSSL: " ${OPENSSL_VERSION})

    add_definitions(${OPENSSL_DEFINITIONS})
    target_include_directories(ixwebsocket PUBLIC ${OPENSSL_INCLUDE_DIR})
    target_link_libraries(ixwebsocket ${OPENSSL_LIBRARIES})

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

No branches or pull requests

2 participants