Use modern OpenSSL cmake syntax (if available), and larger cmake cleanup
diff --git a/lib/c_glib/CMakeLists.txt b/lib/c_glib/CMakeLists.txt
index 2bee9e4..218f7dd 100644
--- a/lib/c_glib/CMakeLists.txt
+++ b/lib/c_glib/CMakeLists.txt
@@ -24,7 +24,7 @@
 include_directories(src)
 
 # SYSLIBS contains libraries that need to be linked to all lib targets
-set(SYSLIBS ${GLIB_LIBRARIES} ${GLIB_GOBJECT_LIBRARIES})
+list(APPEND SYSLIBS ${GLIB_LIBRARIES} ${GLIB_GOBJECT_LIBRARIES})
 
 # Create the thrift C glib library
 set(thrift_c_glib_SOURCES
@@ -67,31 +67,40 @@
     src/thrift/c_glib/transport/thrift_transport.c
     src/thrift/c_glib/transport/thrift_transport_factory.c
     src/thrift/c_glib/transport/thrift_zlib_transport.c
-    src/thrift/c_glib/transport/thrift_zlib_transport_factory.c   
+    src/thrift/c_glib/transport/thrift_zlib_transport_factory.c
 )
 
 # If OpenSSL is not found just ignore the OpenSSL stuff
-if(WITH_OPENSSL)
+if(OPENSSL_FOUND AND WITH_OPENSSL)
     list(APPEND thrift_c_glib_SOURCES
 	    src/thrift/c_glib/transport/thrift_ssl_socket.c
     )
-    include_directories(SYSTEM "${OPENSSL_INCLUDE_DIR}")
-    list(APPEND SYSLIBS "${OPENSSL_LIBRARIES}")
+    if(TARGET OpenSSL::SSL OR TARGET OpenSSL::Crypto)
+        if(TARGET OpenSSL::SSL)
+            list(APPEND SYSLIBS OpenSSL::SSL)
+        endif()
+        if(TARGET OpenSSL::Crypto)
+            list(APPEND SYSLIBS OpenSSL::Crypto)
+        endif()
+    else()
+        include_directories(SYSTEM "${OPENSSL_INCLUDE_DIR}")
+        list(APPEND SYSLIBS "${OPENSSL_LIBRARIES}")
+    endif()
 endif()
 
 
-# Contains the thrift specific ADD_LIBRARY_THRIFT and TARGET_LINK_LIBRARIES_THRIFT
+# Contains the thrift specific ADD_LIBRARY_THRIFT macro
 include(ThriftMacros)
 
 ADD_LIBRARY_THRIFT(thrift_c_glib ${thrift_c_glib_SOURCES})
-TARGET_LINK_LIBRARIES_THRIFT(thrift_c_glib PUBLIC ${SYSLIBS})
+target_link_libraries(thrift_c_glib PUBLIC ${SYSLIBS})
 
 # If Zlib is not found just ignore the Zlib stuff
 if(WITH_ZLIB)
     include_directories(SYSTEM ${ZLIB_INCLUDE_DIRS})
     ADD_LIBRARY_THRIFT(thrift_c_glib_zlib ${thrift_c_glib_zlib_SOURCES})
-    TARGET_LINK_LIBRARIES_THRIFT(thrift_c_glib_zlib ${SYSLIBS} ${ZLIB_LIBRARIES})
-    TARGET_LINK_LIBRARIES_THRIFT_AGAINST_THRIFT_LIBRARY(thrift_c_glib_zlib thrift_c_glib)
+    target_link_libraries(thrift_c_glib_zlib ${SYSLIBS} ${ZLIB_LIBRARIES})
+    target_link_libraries(thrift_c_glib_zlib thrift_c_glib)
 endif()
 
 # Install the headers
diff --git a/lib/c_glib/test/CMakeLists.txt b/lib/c_glib/test/CMakeLists.txt
index c46014d..85c6dd0 100644
--- a/lib/c_glib/test/CMakeLists.txt
+++ b/lib/c_glib/test/CMakeLists.txt
@@ -52,48 +52,48 @@
 )
 
 add_library(testgenc STATIC ${testgenc_SOURCES})
-LINK_AGAINST_THRIFT_LIBRARY(testgenc thrift_c_glib)
+target_link_libraries(testgenc thrift_c_glib)
 
 
 add_executable(testserialization testserialization.c)
 target_link_libraries(testserialization testgenc)
-LINK_AGAINST_THRIFT_LIBRARY(testserialization thrift_c_glib)
+target_link_libraries(testserialization thrift_c_glib)
 add_test(NAME testserialization COMMAND testserialization)
 
 add_executable(testapplicationexception testapplicationexception.c)
-LINK_AGAINST_THRIFT_LIBRARY(testapplicationexception thrift_c_glib)
+target_link_libraries(testapplicationexception thrift_c_glib)
 add_test(NAME testapplicationexception COMMAND testapplicationexception)
 
 add_executable(testtransportsocket testtransportsocket.c)
-LINK_AGAINST_THRIFT_LIBRARY(testtransportsocket thrift_c_glib)
+target_link_libraries(testtransportsocket thrift_c_glib)
 add_test(NAME testtransportsocket COMMAND testtransportsocket)
 
 add_executable(testbinaryprotocol testbinaryprotocol.c)
-LINK_AGAINST_THRIFT_LIBRARY(testbinaryprotocol thrift_c_glib)
+target_link_libraries(testbinaryprotocol thrift_c_glib)
 add_test(NAME testbinaryprotocol COMMAND testbinaryprotocol)
 
 add_executable(testcompactprotocol testcompactprotocol.c)
-LINK_AGAINST_THRIFT_LIBRARY(testcompactprotocol thrift_c_glib)
+target_link_libraries(testcompactprotocol thrift_c_glib)
 add_test(NAME testcompactprotocol COMMAND testcompactprotocol)
 
 add_executable(testbufferedtransport testbufferedtransport.c)
-LINK_AGAINST_THRIFT_LIBRARY(testbufferedtransport thrift_c_glib)
+target_link_libraries(testbufferedtransport thrift_c_glib)
 add_test(NAME testbufferedtransport COMMAND testbufferedtransport)
 
 add_executable(testframedtransport testframedtransport.c)
-LINK_AGAINST_THRIFT_LIBRARY(testframedtransport thrift_c_glib)
+target_link_libraries(testframedtransport thrift_c_glib)
 add_test(NAME testframedtransport COMMAND testframedtransport)
 
 add_executable(testfdtransport testfdtransport.c)
-LINK_AGAINST_THRIFT_LIBRARY(testfdtransport thrift_c_glib)
+target_link_libraries(testfdtransport thrift_c_glib)
 add_test(NAME testfdtransport COMMAND testfdtransport)
 
 add_executable(testmemorybuffer testmemorybuffer.c)
-LINK_AGAINST_THRIFT_LIBRARY(testmemorybuffer thrift_c_glib)
+target_link_libraries(testmemorybuffer thrift_c_glib)
 add_test(NAME testmemorybuffer COMMAND testmemorybuffer)
 
 add_executable(testsimpleserver testsimpleserver.c)
-LINK_AGAINST_THRIFT_LIBRARY(testsimpleserver thrift_c_glib)
+target_link_libraries(testsimpleserver thrift_c_glib)
 add_test(NAME testsimpleserver COMMAND testsimpleserver)
 
 add_executable(testdebugproto testdebugproto.c)
@@ -132,7 +132,7 @@
   include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}")
   add_executable(testzlibtransport testzlibtransport.c)
   target_link_libraries(testzlibtransport testgenc ${ZLIB_LIBRARIES})
-  LINK_AGAINST_THRIFT_LIBRARY(testzlibtransport thrift_c_glib_zlib)
+  target_link_libraries(testzlibtransport thrift_c_glib_zlib)
   add_test(NAME testzlibtransport COMMAND testzlibtransport)
 endif(WITH_ZLIB)
 
@@ -162,7 +162,7 @@
     )
 
     add_library(testgenc_cpp STATIC ${testgenc_cpp_SOURCES})
-    LINK_AGAINST_THRIFT_LIBRARY(testgenc_cpp thrift)
+    target_link_libraries(testgenc_cpp thrift)
 
     #HACK: testthrifttestclient.cpp includes ThriftTest.h without gen-*/ prefixes
     # so we include it here