THRIFT-5076 Improve CMake OpenSSL usage
Client: c_glib
Patch: Kevin Wojniak
This closes #1994
diff --git a/build/cmake/DefineOptions.cmake b/build/cmake/DefineOptions.cmake
index f85d2c6..8357160 100644
--- a/build/cmake/DefineOptions.cmake
+++ b/build/cmake/DefineOptions.cmake
@@ -73,9 +73,6 @@
find_package(Qt5 QUIET COMPONENTS Core Network)
CMAKE_DEPENDENT_OPTION(WITH_QT5 "Build with Qt5 support" ON
"Qt5_FOUND" OFF)
- find_package(OpenSSL QUIET)
- CMAKE_DEPENDENT_OPTION(WITH_OPENSSL "Build with OpenSSL support" ON
- "OPENSSL_FOUND" OFF)
endif()
CMAKE_DEPENDENT_OPTION(BUILD_CPP "Build C++ library" ON
"BUILD_LIBRARIES;WITH_CPP" OFF)
@@ -88,6 +85,13 @@
CMAKE_DEPENDENT_OPTION(BUILD_C_GLIB "Build C (GLib) library" ON
"BUILD_LIBRARIES;WITH_C_GLIB;GLIB_FOUND" OFF)
+# OpenSSL
+if(WITH_CPP OR WITH_C_GLIB)
+ find_package(OpenSSL QUIET)
+ CMAKE_DEPENDENT_OPTION(WITH_OPENSSL "Build with OpenSSL support" ON
+ "OPENSSL_FOUND" OFF)
+endif()
+
# Java
option(WITH_JAVA "Build Java Thrift library" ON)
if(ANDROID)
@@ -170,6 +174,11 @@
MESSAGE_DEP(WITH_AS3 "Disabled by WITH_AS3=OFF")
MESSAGE_DEP(HAVE_COMPC "Adobe Flex compc was not found - did you set env var FLEX_HOME?")
message(STATUS)
+message(STATUS " Build with OpenSSL: ${WITH_OPENSSL}")
+if(WITH_OPENSSL)
+ message(STATUS " Version: ${OPENSSL_VERSION}")
+endif()
+message(STATUS)
message(STATUS " Build C++ library: ${BUILD_CPP}")
MESSAGE_DEP(WITH_CPP "Disabled by WITH_CPP=OFF")
if (BUILD_CPP)
diff --git a/lib/c_glib/CMakeLists.txt b/lib/c_glib/CMakeLists.txt
index 3e4a154..d9dc217 100644
--- a/lib/c_glib/CMakeLists.txt
+++ b/lib/c_glib/CMakeLists.txt
@@ -59,9 +59,8 @@
)
# If OpenSSL is not found just ignore the OpenSSL stuff
-find_package(OpenSSL)
-if(OPENSSL_FOUND AND WITH_OPENSSL)
- list( APPEND thrift_c_glib_SOURCES
+if(WITH_OPENSSL)
+ list(APPEND thrift_c_glib_SOURCES
src/thrift/c_glib/transport/thrift_ssl_socket.c
)
include_directories(SYSTEM "${OPENSSL_INCLUDE_DIR}")
diff --git a/test/c_glib/CMakeLists.txt b/test/c_glib/CMakeLists.txt
index 9817315..7a7daad 100644
--- a/test/c_glib/CMakeLists.txt
+++ b/test/c_glib/CMakeLists.txt
@@ -28,6 +28,7 @@
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
include_directories("${CMAKE_CURRENT_BINARY_DIR}/gen-c_glib")
include_directories("${PROJECT_SOURCE_DIR}/lib/c_glib/src")
+include_directories(SYSTEM "${OPENSSL_INCLUDE_DIR}")
set(crosstestgencglib_SOURCES
gen-c_glib/t_test_second_service.c
@@ -44,7 +45,7 @@
target_link_libraries(test_server crosstestgencglib)
add_executable(test_client src/test_client.c)
-target_link_libraries(test_client crosstestgencglib)
+target_link_libraries(test_client crosstestgencglib "${OPENSSL_LIBRARIES}")
#
# Common thrift code generation rules