Browse Source

[cmake] Add ssl.hdll and openal.hdll to mac/linux builds (#596)

tobil4sk 2 years ago
parent
commit
75f365843f
5 changed files with 176 additions and 42 deletions
  1. 2 0
      CMakeLists.txt
  2. 5 9
      libs/CMakeLists.txt
  3. 22 18
      libs/openal/CMakeLists.txt
  4. 30 15
      libs/ssl/CMakeLists.txt
  5. 117 0
      other/cmake/FindMbedTLS.cmake

+ 2 - 0
CMakeLists.txt

@@ -84,12 +84,14 @@ file(GLOB pcre_srcs
     include/pcre/pcre2_valid_utf.c
     include/pcre/pcre2_xclass.c
 )
+
 file(GLOB std_srcs
     src/std/array.c
     src/std/buffer.c
     src/std/bytes.c
     src/std/cast.c
     src/std/date.c
+    src/std/debug.c
     src/std/error.c
     src/std/file.c
     src/std/fun.c

+ 5 - 9
libs/CMakeLists.txt

@@ -23,11 +23,9 @@ endif()
 
 # add_subdirectory(mesa)
 
-if(WIN32)
-    option(WITH_OPENAL "Build openal.hdll." ON)
-    if(WITH_OPENAL)
-        add_subdirectory(openal)
-    endif()
+option(WITH_OPENAL "Build openal.hdll." ON)
+if(WITH_OPENAL)
+    add_subdirectory(openal)
 endif()
 
 option(WITH_SDL "Build sdl.hdll." ON)
@@ -40,11 +38,9 @@ if(WITH_SQLITE)
     add_subdirectory(sqlite)
 endif()
 
-if(WIN32)
-    option(WITH_SSL "Build ssl.hdll." ON)
-    if(WITH_SSL)
+option(WITH_SSL "Build ssl.hdll." ON)
+if(WITH_SSL)
     add_subdirectory(ssl)
-    endif()
 endif()
 
 option(WITH_UI "Build ui.hdll." ON)

+ 22 - 18
libs/openal/CMakeLists.txt

@@ -4,28 +4,32 @@ if(WIN32)
     endif()
 
     if(CMAKE_SIZEOF_VOID_P EQUAL 8)
-        find_library(OpenAL_LIBRARY OpenAL32 PATHS ${INCLUDES_BASE_DIR}/openal/libs/Win64)
+        find_library(OPENAL_LIBRARY OpenAL32 PATHS ${INCLUDES_BASE_DIR}/openal/libs/Win64)
     else()
-        find_library(OpenAL_LIBRARY OpenAL32 PATHS ${INCLUDES_BASE_DIR}/openal/libs/Win32)
+        find_library(OPENAL_LIBRARY OpenAL32 PATHS ${INCLUDES_BASE_DIR}/openal/libs/Win32)
     endif()
 
-    add_library(openal.hdll SHARED openal.c)
+    set(OPENAL_INCLUDE_DIR ${INCLUDES_BASE_DIR}/openal/include)
+else()
+    find_package(OpenAL REQUIRED)
+endif()
 
-    set_as_hdll(openal)
+add_library(openal.hdll SHARED openal.c)
 
-    target_include_directories(openal.hdll
-        PRIVATE
-        ${INCLUDES_BASE_DIR}/openal/include
-    )
+set_as_hdll(openal)
 
-    target_link_libraries(openal.hdll
-        libhl
-        ${OpenAL_LIBRARY}
-    )
+target_link_libraries(openal.hdll
+    libhl
+    ${OPENAL_LIBRARY}
+)
 
-    install(
-        TARGETS
-            openal.hdll
-        DESTINATION ${HDLL_DESTINATION}
-    )
-endif()
+target_include_directories(openal.hdll
+    PRIVATE
+    ${OPENAL_INCLUDE_DIR}
+)
+
+install(
+    TARGETS
+        openal.hdll
+    DESTINATION ${HDLL_DESTINATION}
+)

+ 30 - 15
libs/ssl/CMakeLists.txt

@@ -1,4 +1,7 @@
-if(WIN32)
+if (WIN32)
+    set(MBEDTLS_INCLUDE_DIRS ${INCLUDES_BASE_DIR}/mbedtls/include)
+    set(MBEDTLS_LIBRARIES crypt32)
+
     add_library(ssl.hdll SHARED
         ${INCLUDES_BASE_DIR}/mbedtls/library/aes.c
         ${INCLUDES_BASE_DIR}/mbedtls/library/aesni.c
@@ -72,22 +75,34 @@ if(WIN32)
         ${INCLUDES_BASE_DIR}/mbedtls/library/xtea.c
         ssl.c
     )
+else()
+    find_package(MbedTLS REQUIRED)
 
-    set_as_hdll(ssl)
-
-    target_include_directories(ssl.hdll
-        PRIVATE
-        ${INCLUDES_BASE_DIR}/mbedtls/include
+    add_library(ssl.hdll SHARED
+        ssl.c
     )
+endif()
 
-    target_link_libraries(ssl.hdll
-        libhl
-        crypt32
-    )
+set_as_hdll(ssl)
 
-    install(
-        TARGETS
-            ssl.hdll
-        DESTINATION ${HDLL_DESTINATION}
-    )
+target_include_directories(ssl.hdll
+    PRIVATE
+    ${MBEDTLS_INCLUDE_DIRS}
+)
+
+target_link_libraries(ssl.hdll
+    libhl
+    ${MBEDTLS_LIBRARIES}
+)
+
+if(APPLE)
+	find_library(SECURITY_LIBRARY Security REQUIRED)
+	find_library(COREFOUNDATION_LIBRARY CoreFoundation REQUIRED)
+	target_link_libraries(ssl.hdll ${COREFOUNDATION_LIBRARY} ${SECURITY_LIBRARY})
 endif()
+
+install(
+    TARGETS
+        ssl.hdll
+    DESTINATION ${HDLL_DESTINATION}
+)

+ 117 - 0
other/cmake/FindMbedTLS.cmake

@@ -0,0 +1,117 @@
+############################################################################
+# FindMdebTLS.txt
+# Copyright (C) 2015  Belledonne Communications, Grenoble France
+#
+############################################################################
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+#
+############################################################################
+#
+# - Find the mbedTLS include file and library
+#
+#  MBEDTLS_FOUND - system has mbedTLS
+#  MBEDTLS_INCLUDE_DIRS - the mbedTLS include directory
+#  MBEDTLS_LIBRARIES - The libraries needed to use mbedTLS
+
+include(CMakePushCheckState)
+include(CheckIncludeFile)
+include(CheckCSourceCompiles)
+include(CheckSymbolExists)
+
+
+find_path(MBEDTLS_INCLUDE_DIRS
+	NAMES mbedtls/ssl.h
+	PATH_SUFFIXES include
+)
+
+# find the three mbedtls library
+find_library(MBEDTLS_LIBRARY
+	NAMES mbedtls
+)
+
+find_library(MBEDX509_LIBRARY
+	NAMES mbedx509
+)
+
+find_library(MBEDCRYPTO_LIBRARY
+	NAMES mbedcrypto
+)
+
+cmake_push_check_state(RESET)
+set(CMAKE_REQUIRED_INCLUDES ${MBEDTLS_INCLUDE_DIRS} ${CMAKE_REQUIRED_INCLUDES_${BUILD_TYPE}})
+list(APPEND CMAKE_REQUIRED_LIBRARIES ${MBEDTLS_LIBRARY} ${MBEDX509_LIBRARY} ${MBEDCRYPTO_LIBRARY})
+
+# check we have a mbedTLS version 2 or above(all functions are prefixed mbedtls_)
+if(MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY)
+	check_symbol_exists(mbedtls_ssl_init "mbedtls/ssl.h" MBEDTLS_V2)
+	if(NOT MBEDTLS_V2)
+		message ("MESSAGE: NO MBEDTLS_V2")
+		message ("MESSAGE: MBEDTLS_LIBRARY=" ${MBEDTLS_LIBRARY})
+		message ("MESSAGE: MBEDX509_LIBRARY=" ${MBEDX509_LIBRARY})
+		message ("MESSAGE: MBEDCRYPTO_LIBRARY=" ${MBEDCRYPTO_LIBRARY})
+		set (MBEDTLS_VERSION_1 On)
+	else()
+		# Are we mbdetls 2 or 3?
+		# from version 3 and on, version number is given in include/mbedtls/build_info.h.
+		# This file does not exists before version 3
+		if (EXISTS "${MBEDTLS_INCLUDE_DIRS}/mbedtls/build_info.h")
+			set (MBEDTLS_VERSION_3 On)
+		else()
+			set (MBEDTLS_VERSION_2 On)
+		endif()
+	endif()
+
+endif()
+
+check_symbol_exists(mbedtls_ssl_conf_dtls_srtp_protection_profiles "mbedtls/ssl.h" DTLS_SRTP_AVAILABLE)
+
+# Define the imported target for the three mbedtls libraries
+foreach(targetname "mbedtls" "mbedx509" "mbedcrypto")
+	string(TOUPPER ${targetname} varprefix)
+	add_library(${targetname} SHARED IMPORTED)
+	if (WIN32)
+		set_target_properties(${targetname} PROPERTIES
+			INTERFACE_INCLUDE_DIRECTORIES "${${varprefix}_INCLUDE_DIRS}"
+			IMPORTED_IMPLIB "${${varprefix}_LIBRARY}"
+		)
+	else()
+		set_target_properties(${targetname} PROPERTIES
+			INTERFACE_INCLUDE_DIRECTORIES "${${varprefix}_INCLUDE_DIRS}"
+			IMPORTED_LOCATION "${${varprefix}_LIBRARY}"
+		)
+	endif()
+endforeach()
+unset(varprefix)
+
+# MBEDTLS_LIBRARIES only needs to contain the name of the targets
+set (MBEDTLS_LIBRARIES
+	mbedtls
+	mbedx509
+	mbedcrypto
+)
+
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(MbedTLS
+	DEFAULT_MSG
+	MBEDTLS_INCLUDE_DIRS MBEDTLS_LIBRARIES
+)
+
+cmake_pop_check_state()
+
+
+
+mark_as_advanced(MBEDTLS_INCLUDE_DIRS MBEDTLS_LIBRARIES DTLS_SRTP_AVAILABLE)