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

[build] fix when openssl is static build fail #3097

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lilinxiong
Copy link

In actual usage, I experienced a problem where I set(OpenSSL_DIR /path/lib/cmake/OpenSSL) and then integrated the SRT project into my own by using add_subdirectory. The first CMake configuration would succeed, but the second configuration attempt would fail.

The details are as follows:

set(OpenSSL_DIR ${THIRD_PARTY_DIR}/binaries/openssl-android/${ANDROID_ABI}/lib/cmake/OpenSSL)
message("OpenSSL_DIR:${OpenSSL_DIR}")
find_package(OpenSSL REQUIRED CONFIG)

if (OpenSSL_FOUND)
    message("OpenSSL_FOUND = ${OpenSSL_FOUND}")
    message("OPENSSL_INCLUDE_DIR = ${OPENSSL_INCLUDE_DIR}")
    message("OPENSSL_LIBRARY_DIR = ${OPENSSL_LIBRARY_DIR}")
    message("OPENSSL_LIBRARIES = ${OPENSSL_LIBRARIES}")
endif ()

message("add_subdirectory: srt:${SRT_DIR} ......")
set(ENABLE_APPS OFF)
set(ENABLE_SHARED OFF)
set(USE_OPENSSL_PC OFF)
set(OPENSSL_USE_STATIC_LIBS ON)
add_subdirectory(${SRT_DIR} ./srt-bin)

message("add_subdirectory: srt:${SRT_DIR} done!")

It seems to be ok, but when I do the first cmake config, and the second cmake config with caching, I get different results.

In the above message, OPENSSL_INCLUDE_DIR has a value the first time, and is empty the second time.

After cmake config and troubleshooting again and again, I finally found that: CMakeLists.txt#L175-OPENSSL_USE_STATIC_LIBS will cause cmake config to fail.

The reason is that there will be the same variables in OpenSSLConfig.cmake.

....
if(OPENSSL_USE_STATIC_LIBS)
  set(_ossl_use_static_libs True)
elseif(DEFINED OPENSSL_USE_STATIC_LIBS)
  # We know OPENSSL_USE_STATIC_LIBS is defined and False
  if(_ossl_use_static_libs)
    # OPENSSL_USE_STATIC_LIBS is explicitly false, indicating that shared libraries are
    # required.  However, _ossl_use_static_libs indicates that no shared libraries are
    # available.  The best course of action is to simply return and leave it to CMake to
    # use another OpenSSL config.
    unset(_ossl_use_static_libs)
    unset(CMAKE_IMPORT_FILE_VERSION)
    return()
  endif()
endif()
....

Because there is no cache when cmake config is run for the first time, it works fine, but the second time, there is a cache, which causes failure.

We should not define the same variables as those in config.cmake generated by make install, we should name them differently.

@ethouris
Copy link
Collaborator

ethouris commented Jan 6, 2025

Ok, let me ask directly: the OPENSSL_ prefix of the variable is the cause of the problem?

@lilinxiong
Copy link
Author

Ok, let me ask directly: the OPENSSL_ prefix of the variable is the cause of the problem?

Yes!

@ethouris ethouris added this to the v1.5.5 milestone Jan 6, 2025
@ethouris ethouris added Type: Maintenance Work required to maintain or clean up the code [build] Area: Changes in build files labels Jan 6, 2025
@maxsharabayko
Copy link
Collaborator

Given the build option is being renamed anyway, might be worth considering #2914 for it then.
I am also not yet sure if this change can go to a patch version v1.5.5 instead of v1.6.0. The API/ABI is not being changed, but the build option name is... Might provide some inconvenience.
Maybe makes sense to keep the old name as an alias and mark it duplicated for 1.5.5, and then remove in 1.6.0?

@lilinxiong
Copy link
Author

Given the build option is being renamed anyway, might be worth considering #2914 for it then. I am also not yet sure if this change can go to a patch version v1.5.5 instead of v1.6.0. The API/ABI is not being changed, but the build option name is... Might provide some inconvenience. Maybe makes sense to keep the old name as an alias and mark it duplicated for 1.5.5, and then remove in 1.6.0?

Hmm, it is indeed a good idea, I totally agree. If other developers encounter the same problem as me during this period, they can make temporary modifications so that it can be compiled.

@ethouris
Copy link
Collaborator

You can simply check if OPENSSL_USE_STATIC_LIBS is defined as 1 and if so, forcefully set this option to TRUE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[build] Area: Changes in build files Type: Maintenance Work required to maintain or clean up the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants