Repository: ORNL/DataFed (language: python)

Issue:
Joshua s brown libcurl openssl



Discussion / hints:

Fix patch:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 827d2feec..60081cdac 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -158,8 +158,7 @@ endif()
 if( BUILD_CORE_SERVER )
   include(./cmake/JSON.cmake)
   include(./cmake/JSONSchema.cmake)
-  #find_package(OpenSSL "${LOCAL_OPENSSL_VERSION}" REQUIRED )
-  #find_package(CURL "${LOCAL_CURL_VERSION}" REQUIRED )
+  include(./cmake/zlib.cmake)
   include(./cmake/OpenSSL.cmake)
   include(./cmake/CURL.cmake)
 endif()
diff --git a/cmake/CURL.cmake b/cmake/CURL.cmake
index d26f222a0..e9bfc8546 100644
--- a/cmake/CURL.cmake
+++ b/cmake/CURL.cmake
@@ -1,8 +1,8 @@
-function(find_libcurl_library)
+function(find_curl_library)
 
   set(CURL_INCLUDE_DIR "${DEPENDENCY_INSTALL_PATH}/include" PARENT_SCOPE)
   set(CURL_LIBRARIES "${DEPENDENCY_INSTALL_PATH}/lib/libcurl.a" PARENT_SCOPE)
 
 endfunction()
 
-find_libcurl_library()
+find_curl_library()
diff --git a/cmake/OpenSSL.cmake b/cmake/OpenSSL.cmake
index b280baabf..ef15d5c94 100644
--- a/cmake/OpenSSL.cmake
+++ b/cmake/OpenSSL.cmake
@@ -1,21 +1,31 @@
-
 function(find_openssl_library)
 
-  set(OPENSSL_ROOT_DIR "${DEPENDENCY_INSTALL_PATH}")
-  set(OPENSSL_USE_STATIC_LIBS TRUE)
+  if(EXISTS "${DEPENDENCY_INSTALL_PATH}/lib/libssl.a")
+    set(OPENSSL_FOUND "TRUE" PARENT_SCOPE)
+    set(OPENSSL_INCLUDE_DIR "${DEPENDENCY_INSTALL_PATH}/include" PARENT_SCOPE)
+    set(OPENSSL_CRYPTO_LIBRARY "${DEPENDENCY_INSTALL_PATH}/lib/libcrypto.a" PARENT_SCOPE)
+    set(OPENSSL_CRYPTO_LIBRARIES "${DEPENDENCY_INSTALL_PATH}/lib/libcrypto.a" PARENT_SCOPE)
+    set(OPENSSL_SSL_LIBRARY "${DEPENDENCY_INSTALL_PATH}/lib/libssl.a" PARENT_SCOPE)
+    set(OPENSSL_SSL_LIBRARIES "${DEPENDENCY_INSTALL_PATH}/lib/libssl.a" PARENT_SCOPE)
+    set(OPENSSL_LIBRARIES "${DEPENDENCY_INSTALL_PATH}/lib/libssl.a ${DEPENDENCY_INSTALL_PATH}/lib/libcrypto.a" PARENT_SCOPE)
+    set(OPENSSL_VERSION "1.1.1w" PARENT_SCOPE)
+  else()
+    set(OPENSSL_ROOT_DIR "${DEPENDENCY_INSTALL_PATH}")
+    set(OPENSSL_USE_STATIC_LIBS TRUE)
 
-  find_package(OpenSSL REQUIRED)
+    find_package(OpenSSL REQUIRED)
 
-  message("OPENSSL_INCLUDE_DIR = ${OPENSSL_INCLUDE_DIR}\nOPENSSL_LIBRARIES = ${OPENSSL_LIBRARIES}")
+    message("OPENSSL_INCLUDE_DIR = ${OPENSSL_INCLUDE_DIR}\nOPENSSL_LIBRARIES = ${OPENSSL_LIBRARIES}")
 
-  set(OPENSSL_FOUND "${OPENSSL_FOUND}" PARENT_SCOPE)
-  set(OPENSSL_INCLUDE_DIR "${OPENSSL_INCLUDE_DIR}" PARENT_SCOPE)
-  set(OPENSSL_CRYPTO_LIBRARY "${OPENSSL_CRYPTO_LIBRARY}" PARENT_SCOPE)
-  set(OPENSSL_CRYPTO_LIBRARIES "${OPENSSL_CRYPTO_LIBRARIES}" PARENT_SCOPE)
-  set(OPENSSL_SSL_LIBRARY "${OPENSSL_SSL_LIBRARY}" PARENT_SCOPE)
-  set(OPENSSL_SSL_LIBRARIES "${OPENSSL_SSL_LIBRARIES}" PARENT_SCOPE)
-  set(OPENSSL_LIBRARIES "${OPENSSL_LIBRARIES}" PARENT_SCOPE)
-  set(OPENSSL_VERSION "${OPENSSL_VERSION}" PARENT_SCOPE)
+    set(OPENSSL_FOUND "${OPENSSL_FOUND}" PARENT_SCOPE)
+    set(OPENSSL_INCLUDE_DIR "${OPENSSL_INCLUDE_DIR}" PARENT_SCOPE)
+    set(OPENSSL_CRYPTO_LIBRARY "${OPENSSL_CRYPTO_LIBRARY}" PARENT_SCOPE)
+    set(OPENSSL_CRYPTO_LIBRARIES "${OPENSSL_CRYPTO_LIBRARIES}" PARENT_SCOPE)
+    set(OPENSSL_SSL_LIBRARY "${OPENSSL_SSL_LIBRARY}" PARENT_SCOPE)
+    set(OPENSSL_SSL_LIBRARIES "${OPENSSL_SSL_LIBRARIES}" PARENT_SCOPE)
+    set(OPENSSL_LIBRARIES "${OPENSSL_LIBRARIES}" PARENT_SCOPE)
+    set(OPENSSL_VERSION "${OPENSSL_VERSION}" PARENT_SCOPE)
+  endif()
 
 endfunction()
 
diff --git a/core/server/CMakeLists.txt b/core/server/CMakeLists.txt
index 27025b95f..470781054 100644
--- a/core/server/CMakeLists.txt
+++ b/core/server/CMakeLists.txt
@@ -13,8 +13,9 @@ set_target_properties(datafed-core-lib PROPERTIES POSITION_INDEPENDENT_CODE ON)
 
 # Must be public for unit tests to import them
 target_include_directories( datafed-core-lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} )
-target_link_libraries( datafed-core-lib ${DEPENDENCY_INSTALL_PATH}/lib/libssl.so ${DEPENDENCY_INSTALL_PATH}/lib/libcrypto.so common datafed-protobuf protobuf::libprotobuf
-  Threads::Threads ${CURL_LIBRARIES} ${Boost_LIBRARIES} libzmq-static nlohmann_json_schema_validator )
+target_link_libraries( datafed-core-lib  common datafed-protobuf protobuf::libprotobuf
+  Threads::Threads ${CURL_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${Boost_LIBRARIES}
+  libzmq-static nlohmann_json_schema_validator )
 
 add_executable( datafed-core ${Main})
 target_link_libraries( datafed-core datafed-core-lib )
diff --git a/scripts/dependency_install_functions.sh b/scripts/dependency_install_functions.sh
index 6eea4a6f3..535bf7a34 100644
--- a/scripts/dependency_install_functions.sh
+++ b/scripts/dependency_install_functions.sh
@@ -35,7 +35,11 @@ if [ ! -e "$DATAFED_DEPENDENCIES_INSTALL_PATH" ] || [ ! -d "$DATAFED_DEPENDENCIE
     fi
 fi
 
-LD_LIBRARY_PATH="$DATAFED_DEPENDENCIES_INSTALL_PATH/lib:$LD_LIBRARY_PATH"
+if [[ -n "$LD_LIBRARY_PATH" ]]; then
+  LD_LIBRARY_PATH="$DATAFED_DEPENDENCIES_INSTALL_PATH/lib:$LD_LIBRARY_PATH"
+else
+  LD_LIBRARY_PATH="$DATAFED_DEPENDENCIES_INSTALL_PATH/lib"
+fi
 
 install_cmake() {
   if [ ! -e "${DATAFED_DEPENDENCIES_INSTALL_PATH}/.cmake_installed-${DATAFED_CMAKE_VERSION}" ]; then
@@ -384,6 +388,32 @@ install_libcurl() {
   fi
 }
 
+install_zlib() {
+  if [ ! -e "${DATAFED_DEPENDENCIES_INSTALL_PATH}/.zlib_installed-${DATAFED_ZLIB_VERSION}" ]; then
+    local original_dir=$(pwd)
+    if [ -d "${PROJECT_ROOT}/external/zlib" ]
+    then
+      "$SUDO_CMD" rm -rf "${PROJECT_ROOT}/external/zlib"
+    fi
+    wget "${DATAFED_ZLIB_URL}"
+    mkdir -p "${PROJECT_ROOT}/external/zlib"
+    tar -xf "zlib-${DATAFED_ZLIB_VERSION}.tar.gz" -C "${PROJECT_ROOT}/external/zlib"
+    cd "${PROJECT_ROOT}/external/zlib/zlib-${DATAFED_ZLIB_VERSION}"
+    PKG_CONFIG_PATH="${DATAFED_DEPENDENCIES_INSTALL_PATH}/lib/pkgconfig" ./configure --prefix="${DATAFED_DEPENDENCIES_INSTALL_PATH}"
+    make
+
+    if [ -w "${DATAFED_DEPENDENCIES_INSTALL_PATH}" ]; then
+      make install
+    else
+      "$SUDO_CMD" make install 
+    fi
+
+    # Mark libcurl as installed
+    touch "${DATAFED_DEPENDENCIES_INSTALL_PATH}/.zlib_installed-${DATAFED_ZLIB_VERSION}"
+    cd "$original_dir"
+  fi
+}
+
 install_dep_by_name() {
   case "$1" in
     "cmake")
@@ -413,6 +443,9 @@ install_dep_by_name() {
     "libcurl")
       install_libcurl
       ;;
+    "zlib")
+      install_zlib
+      ;;
   esac
   cd ~
 }
diff --git a/scripts/dependency_versions.sh b/scripts/dependency_versions.sh
index 6f8d6d54d..57d62f8ff 100644
--- a/scripts/dependency_versions.sh
+++ b/scripts/dependency_versions.sh
@@ -25,3 +25,5 @@ DATAFED_LIBCURL_URL="https://github.com/curl/curl/releases/download/curl-7_88_1/
 DATAFED_OPENSSL="1.1.1"
 DATAFED_OPENSSL_COMMIT="e04bd34"
 DATAFED_BOOST="1.71.0"
+DATAFED_ZLIB_VERSION="1.3.1"
+DATAFED_ZLIB_URL="https://zlib.net/zlib-1.3.1.tar.gz"


Test patch:
diff --git a/core/server/tests/unit/CMakeLists.txt b/core/server/tests/unit/CMakeLists.txt
index 6151c9d4c..5490a680e 100644
--- a/core/server/tests/unit/CMakeLists.txt
+++ b/core/server/tests/unit/CMakeLists.txt
@@ -6,7 +6,7 @@ foreach(PROG
 
   file(GLOB ${PROG}_SOURCES ${PROG}*.cpp)
   add_executable(unit_${PROG} ${${PROG}_SOURCES})
-  target_link_libraries(unit_${PROG} Boost::unit_test_framework datafed-core-lib)
+  target_link_libraries(unit_${PROG} Boost::unit_test_framework datafed-core-lib ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES})
   target_compile_definitions(unit_${PROG} PRIVATE BOOST_TEST_DYN_LINK)
   add_test(unit_${PROG} unit_${PROG})