ustream-ssl: add support for using a fd instead of ustream as backing
[project/ustream-ssl.git] / CMakeLists.txt
index bd8ce3fda7fd3dca2056492735fe22d15e2e680b..2e591ee76b4a2c9d8642ae9620266c43fa245eda 100644 (file)
@@ -1,27 +1,59 @@
 cmake_minimum_required(VERSION 2.6)
 
 PROJECT(ustream-ssl C)
-ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3 -Wmissing-declarations)
 
-SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
+ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3)
+IF(CMAKE_C_COMPILER_VERSION VERSION_GREATER 6)
+        ADD_DEFINITIONS(-Wextra -Werror=implicit-function-declaration)
+        ADD_DEFINITIONS(-Wformat -Werror=format-security -Werror=format-nonliteral)
+ENDIF()
+ADD_DEFINITIONS(-Wno-unused-parameter -Wmissing-declarations)
 
-#INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include/cyassl)
-#LINK_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/lib)
-IF(APPLE)
-  INCLUDE_DIRECTORIES(/opt/local/include)
-  LINK_DIRECTORIES(/opt/local/lib)
+SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
+IF (NOT APPLE)
+  SET(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined")
 ENDIF()
 
-IF (CYASSL)
-  SET(SSL_LIB cyassl)
+IF(MBEDTLS)
+  ADD_DEFINITIONS(-DHAVE_MBEDTLS)
+  SET(SSL_SRC ustream-mbedtls.c)
+  FIND_LIBRARY(mbedtls_library mbedtls)
+  FIND_LIBRARY(mbedx509_library mbedx509)
+  FIND_LIBRARY(mbedcrypto_library mbedcrypto)
+  SET(SSL_LIB ${mbedtls_library} ${mbedx509_library} ${mbedcrypto_library} m)
+ELSEIF(WOLFSSL)
+  ADD_DEFINITIONS(-DHAVE_WOLFSSL)
+  FIND_LIBRARY(wolfssl_library wolfssl)
+  SET(SSL_SRC ustream-io-wolfssl.c ustream-openssl.c)
+  SET(SSL_LIB ${wolfssl_library} m)
+  SET(CMAKE_REQUIRED_LIBRARIES "${wolfssl_library} -lm")
 ELSE()
+  SET(SSL_SRC ustream-io-openssl.c ustream-openssl.c)
   SET(SSL_LIB crypto ssl)
 ENDIF()
 
-ADD_LIBRARY(ustream-ssl SHARED ustream-ssl.c ustream-io.c)
-TARGET_LINK_LIBRARIES(ustream-ssl ubox ${SSL_LIB})
+FIND_PATH(ubox_include_dir libubox/ustream.h)
+INCLUDE_DIRECTORIES(${ubox_include_dir})
+FIND_LIBRARY(ubox_library NAMES ubox)
+
+ADD_LIBRARY(ustream-ssl SHARED ustream-ssl.c ${SSL_SRC})
+TARGET_LINK_LIBRARIES(ustream-ssl ${ubox_library} ${SSL_LIB})
 
-ADD_EXECUTABLE(ustream-example ustream-example.c)
-TARGET_LINK_LIBRARIES(ustream-example ustream-ssl)
+ADD_EXECUTABLE(ustream-example-server ustream-example-server.c)
+TARGET_LINK_LIBRARIES(ustream-example-server ustream-ssl)
 
-SET(CMAKE_INSTALL_PREFIX /usr)
+ADD_EXECUTABLE(ustream-example-client ustream-example-client.c)
+TARGET_LINK_LIBRARIES(ustream-example-client ustream-ssl)
+
+TARGET_COMPILE_DEFINITIONS(ustream-ssl PRIVATE $<$<CONFIG:Debug>:DEBUG>)
+
+INSTALL(FILES ustream-ssl.h
+       DESTINATION include/libubox
+)
+INSTALL(TARGETS ustream-ssl
+       LIBRARY DESTINATION lib
+)
+
+IF(ABIVERSION)
+       SET_TARGET_PROPERTIES(ustream-ssl PROPERTIES VERSION ${ABIVERSION})
+ENDIF()