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 1 commit 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.

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

Successfully merging this pull request may close these issues.

1 participant