Skip to content

Commit

Permalink
[cmake-build] initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
azzbcc committed Oct 27, 2021
1 parent 4152840 commit a0434e8
Show file tree
Hide file tree
Showing 36 changed files with 2,127 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@ test-driver
utils/sip-date
utils/sip-dig
utils/sip-options

#cmake
.idea
*build*
95 changes: 95 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
cmake_minimum_required(VERSION 3.15)
project(sofia-sip C)

# parse project version
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.spec SPEC_VERSION_LINE REGEX "^Version: +")
string(REGEX REPLACE ".+ +(.+)" "\\1" PROJECT_VERSION ${SPEC_VERSION_LINE})
set(PACKAGE_NAME "${PROJECT_NAME}")
set(PACKAGE_VERSION "${PROJECT_VERSION}")
set(VERSION "${PROJECT_VERSION}")
message(STATUS "${PROJECT_NAME}: ${PROJECT_VERSION}")

# project default make options
option(ENABLE_NTH "HTTP-related modules nth and http (enabled)" ON)
option(ENABLE_STUN "enable stun module (enabled)" ON)
option(ENABLE_NTLM "enable NTLM support (disabled)" OFF)
option(ENABLE_MEMLEAK_LOG "enable logging of possible memory leaks (disabled)" OFF)
option(ENABLE_TAG_CAST "cast tag values with inlined functions (enabled)" ON)
option(ENABLE_TESTS "enable ctest framework" OFF)

SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(glib)
include(inline)
include(openssl)
include(pthread)
include(size_compat)
include(sofia)
include(FindUnixCommands)

# find pkg-config command
find_package(PkgConfig REQUIRED)

# Whether hava check library
pkg_check_modules(CHECK check>=0.9.4)
if (CHECK_FOUND)
set(HAVE_CHECK 1)
endif (CHECK_FOUND)

# Check whether enable NTLM
if (ENABLE_NTLM)
set(HAVE_NTLM 1)
set(HAVE_SOFIA_NTLM 1)
endif (ENABLE_NTLM)

# Check whether enable memory leak log
if (ENABLE_MEMLEAK_LOG)
set(HAVE_MEMLEAK_LOG 1)
endif (ENABLE_MEMLEAK_LOG)

# Check whether enable stun
if (ENABLE_STUN)
set(HAVE_STUN 1)
set(HAVE_SOFIA_STUN 1)
if (NOT HAVE_OPENSSL)
message(WARNING "** TLS support for STUN disabled as OpenSSL headers and/or libraries were not found **")
endif (NOT HAVE_OPENSSL)
endif (ENABLE_STUN)

# Check whether enable nth
if (ENABLE_NTH)
set(HAVE_NTH 1)
endif (ENABLE_NTH)

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/config.h
)

include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/s2check
${CMAKE_CURRENT_SOURCE_DIR}/tests
${CMAKE_CURRENT_BINARY_DIR}
)

# whether enable tests
if (ENABLE_TESTS)
include(CTest)
endif (ENABLE_TESTS)
if (NOT ENABLE_TESTS AND ENABLE_MODULE_TEST)
string(TOUPPER "enable_${ENABLE_MODULE_TEST}_TESTS" _var)
set(${_var} 1)
if (ENABLE_TPORT_TESTS)
set(ENABLE_MSG_TESTS 1)
endif ()
include(CTest)
endif (NOT ENABLE_TESTS AND ENABLE_MODULE_TEST)

add_compile_options(-fPIC)
file(TOUCH ${CMAKE_CURRENT_BINARY_DIR}/dummy.c)
add_library(empty OBJECT ${CMAKE_CURRENT_BINARY_DIR}/dummy.c)

add_subdirectory(libsofia-sip-ua)
add_subdirectory(libsofia-sip-ua-glib)
add_subdirectory(s2check)
add_subdirectory(tests)
add_subdirectory(utils)
10 changes: 10 additions & 0 deletions cmake/awk.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if (__AWK_INCLUDED)
return()
endif (__AWK_INCLUDED)
set(__AWK_INCLUDED TRUE)

# find awk program
find_program(AWK awk mawk gawk)
if (AWK MATCHES ".+-NOTFOUND")
message(FATAL_ERROR "FATAL: awk (and mawk and gawk) could not be found (${AWK}).")
endif ()
16 changes: 16 additions & 0 deletions cmake/glib.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
if (__GLIB_INCLUDED)
return()
endif (__GLIB_INCLUDED)
set(__GLIB_INCLUDED TRUE)

set(WITH_GLIB_VERSION "2.0" CACHE STRING "use GLib (default=2.0)")

find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB glib-${WITH_GLIB_VERSION})

if (NOT GLIB_FOUND)
return()
endif (NOT GLIB_FOUND)

set(HAVE_GLIB 1)
include_directories(${GLIB_INCLUDE_DIRS})
34 changes: 34 additions & 0 deletions cmake/inline.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
if (__INLINE_INCLUDED)
return()
endif (__INLINE_INCLUDED)
set(__INLINE_INCLUDED TRUE)

include(CheckCSourceCompiles)

foreach (KEYWORD "inline" "__inline__" "__inline")
set(_INLINE_SOURCE "
typedef int foo_t;
static ${KEYWORD} foo_t static_foo (void) {return 0; }
${KEYWORD} foo_t foo (void) {return 0; }
int main() { return 0; }
")
check_c_source_compiles("${_INLINE_SOURCE}" _${KEYWORD}_COMPLIED)
if (_${KEYWORD}_COMPLIED)
set(C_INLINE ${KEYWORD})
break()
endif (_${KEYWORD}_COMPLIED)
ENDFOREACH (KEYWORD)

# Whether inline
if (DEFINED C_INLINE)
set(SU_HAVE_INLINE 1)
set(SU_INLINE ${C_INLINE})
set(su_inline "static ${C_INLINE}")
if (ENABLE_TAG_CAST)
set(SU_INLINE_TAG_CAST 1)
endif (ENABLE_TAG_CAST)
else ()
set(SU_HAVE_INLINE 0)
set(SU_INLINE /*inline*/)
set(su_inline static)
endif ()
36 changes: 36 additions & 0 deletions cmake/openssl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
if (__OPENSSL_INCLUDED)
return()
endif (__OPENSSL_INCLUDED)
set(__OPENSSL_INCLUDED TRUE)

option(ENABLE_TLS "use OpenSSL (enabled)" ON)
if (NOT ENABLE_TLS)
return()
endif (NOT ENABLE_TLS)

include(utils)
sofia_include_file(openssl/tls1.h)

# Check Whether enable tls
find_package(PkgConfig REQUIRED)
pkg_check_modules(OPENSSL openssl)
if (OPENSSL_FOUND)
set(HAVE_LIBCRYPTO 1)
set(HAVE_OPENSSL 1)
set(HAVE_LIBSSL 1)
set(HAVE_TLS 1)
link_libraries(${OPENSSL_LIBRARIES})
else (OPENSSL_FOUND)
if (HAVE_OPENSSL_TLS1_H)
sofia_library_exists(crypto BIO_new HAVE_OPENSSL)
if (NOT HAVE_OPENSSL)
message(WARNING "OpenSSL crypto library was not found")
endif (NOT HAVE_OPENSSL)
sofia_library_exists(ssl TLSv1_method HAVE_TLS)
if (NOT HAVE_TLS)
message(WARNING "OpenSSL protocol library was not found")
endif (NOT HAVE_TLS)
else (HAVE_OPENSSL_TLS1_H)
message(WARNING "OpenSSL include files were not found")
endif (HAVE_OPENSSL_TLS1_H)
endif (OPENSSL_FOUND)
30 changes: 30 additions & 0 deletions cmake/pthread.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
if (__PTHREAD_INCLUDED)
return()
endif (__PTHREAD_INCLUDED)
set(__PTHREAD_INCLUDED TRUE)

include(utils)

sofia_include_file(pthread.h)
if (NOT HAVE_PTHREAD_H)
return()
endif (NOT HAVE_PTHREAD_H)

link_libraries(pthread)
sofia_library_exists(pthread pthread_create)

# Define if you have pthread_setschedparam()
sofia_library_exists(pthread pthread_setschedparam HAVE_PTHREAD_SETSCHEDPARAM)

set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} pthread)
sofia_source_runs("
pthread_rwlock_t rw;
int main() {
pthread_rwlock_init(&rw, NULL);
pthread_rwlock_rdlock(&rw);
pthread_rwlock_rdlock(&rw);
pthread_rwlock_unlock(&rw);
/* pthread_rwlock_trywrlock() should fail (not return 0) */
return pthread_rwlock_trywrlock(&rw) != 0 ? 0 : 1;
}
" HAVE_PTHREAD_RWLOCK)
23 changes: 23 additions & 0 deletions cmake/size_compat.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
if (__SIZE_COMPAT_INCLUDED)
return()
endif (__SIZE_COMPAT_INCLUDED)
set(__SIZE_COMPAT_INCLUDED TRUE)

option(ENABLE_SIZE_COMPAT "use compatibility size_t types" OFF)

# define sofia_size_t
if (ENABLE_SIZE_COMPAT)
set(SOFIA_ISIZE_T size_t)
set(ISIZE_MAX SIZE_MAX)
set(SOFIA_ISSIZE_T ssize_t)
set(ISSIZE_MAX SSIZE_MAX)
set(SOFIA_USIZE_T size_t)
set(USIZE_MAX SIZE_MAX)
else ()
set(SOFIA_ISIZE_T int)
set(ISIZE_MAX INT_MAX)
set(SOFIA_ISSIZE_T int)
set(ISSIZE_MAX INT_MAX)
set(SOFIA_USIZE_T unsigned)
set(USIZE_MAX UINT_MAX)
endif (ENABLE_SIZE_COMPAT)
Loading

0 comments on commit a0434e8

Please sign in to comment.