Skip to content

Commit a0434e8

Browse files
committed
[cmake-build] initial commit
1 parent 4152840 commit a0434e8

36 files changed

+2127
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,7 @@ test-driver
7070
utils/sip-date
7171
utils/sip-dig
7272
utils/sip-options
73+
74+
#cmake
75+
.idea
76+
*build*

CMakeLists.txt

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(sofia-sip C)
3+
4+
# parse project version
5+
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.spec SPEC_VERSION_LINE REGEX "^Version: +")
6+
string(REGEX REPLACE ".+ +(.+)" "\\1" PROJECT_VERSION ${SPEC_VERSION_LINE})
7+
set(PACKAGE_NAME "${PROJECT_NAME}")
8+
set(PACKAGE_VERSION "${PROJECT_VERSION}")
9+
set(VERSION "${PROJECT_VERSION}")
10+
message(STATUS "${PROJECT_NAME}: ${PROJECT_VERSION}")
11+
12+
# project default make options
13+
option(ENABLE_NTH "HTTP-related modules nth and http (enabled)" ON)
14+
option(ENABLE_STUN "enable stun module (enabled)" ON)
15+
option(ENABLE_NTLM "enable NTLM support (disabled)" OFF)
16+
option(ENABLE_MEMLEAK_LOG "enable logging of possible memory leaks (disabled)" OFF)
17+
option(ENABLE_TAG_CAST "cast tag values with inlined functions (enabled)" ON)
18+
option(ENABLE_TESTS "enable ctest framework" OFF)
19+
20+
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
21+
include(glib)
22+
include(inline)
23+
include(openssl)
24+
include(pthread)
25+
include(size_compat)
26+
include(sofia)
27+
include(FindUnixCommands)
28+
29+
# find pkg-config command
30+
find_package(PkgConfig REQUIRED)
31+
32+
# Whether hava check library
33+
pkg_check_modules(CHECK check>=0.9.4)
34+
if (CHECK_FOUND)
35+
set(HAVE_CHECK 1)
36+
endif (CHECK_FOUND)
37+
38+
# Check whether enable NTLM
39+
if (ENABLE_NTLM)
40+
set(HAVE_NTLM 1)
41+
set(HAVE_SOFIA_NTLM 1)
42+
endif (ENABLE_NTLM)
43+
44+
# Check whether enable memory leak log
45+
if (ENABLE_MEMLEAK_LOG)
46+
set(HAVE_MEMLEAK_LOG 1)
47+
endif (ENABLE_MEMLEAK_LOG)
48+
49+
# Check whether enable stun
50+
if (ENABLE_STUN)
51+
set(HAVE_STUN 1)
52+
set(HAVE_SOFIA_STUN 1)
53+
if (NOT HAVE_OPENSSL)
54+
message(WARNING "** TLS support for STUN disabled as OpenSSL headers and/or libraries were not found **")
55+
endif (NOT HAVE_OPENSSL)
56+
endif (ENABLE_STUN)
57+
58+
# Check whether enable nth
59+
if (ENABLE_NTH)
60+
set(HAVE_NTH 1)
61+
endif (ENABLE_NTH)
62+
63+
configure_file(
64+
${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake
65+
${CMAKE_CURRENT_BINARY_DIR}/config.h
66+
)
67+
68+
include_directories(
69+
${CMAKE_CURRENT_SOURCE_DIR}/s2check
70+
${CMAKE_CURRENT_SOURCE_DIR}/tests
71+
${CMAKE_CURRENT_BINARY_DIR}
72+
)
73+
74+
# whether enable tests
75+
if (ENABLE_TESTS)
76+
include(CTest)
77+
endif (ENABLE_TESTS)
78+
if (NOT ENABLE_TESTS AND ENABLE_MODULE_TEST)
79+
string(TOUPPER "enable_${ENABLE_MODULE_TEST}_TESTS" _var)
80+
set(${_var} 1)
81+
if (ENABLE_TPORT_TESTS)
82+
set(ENABLE_MSG_TESTS 1)
83+
endif ()
84+
include(CTest)
85+
endif (NOT ENABLE_TESTS AND ENABLE_MODULE_TEST)
86+
87+
add_compile_options(-fPIC)
88+
file(TOUCH ${CMAKE_CURRENT_BINARY_DIR}/dummy.c)
89+
add_library(empty OBJECT ${CMAKE_CURRENT_BINARY_DIR}/dummy.c)
90+
91+
add_subdirectory(libsofia-sip-ua)
92+
add_subdirectory(libsofia-sip-ua-glib)
93+
add_subdirectory(s2check)
94+
add_subdirectory(tests)
95+
add_subdirectory(utils)

cmake/awk.cmake

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
if (__AWK_INCLUDED)
2+
return()
3+
endif (__AWK_INCLUDED)
4+
set(__AWK_INCLUDED TRUE)
5+
6+
# find awk program
7+
find_program(AWK awk mawk gawk)
8+
if (AWK MATCHES ".+-NOTFOUND")
9+
message(FATAL_ERROR "FATAL: awk (and mawk and gawk) could not be found (${AWK}).")
10+
endif ()

cmake/glib.cmake

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
if (__GLIB_INCLUDED)
2+
return()
3+
endif (__GLIB_INCLUDED)
4+
set(__GLIB_INCLUDED TRUE)
5+
6+
set(WITH_GLIB_VERSION "2.0" CACHE STRING "use GLib (default=2.0)")
7+
8+
find_package(PkgConfig REQUIRED)
9+
pkg_check_modules(GLIB glib-${WITH_GLIB_VERSION})
10+
11+
if (NOT GLIB_FOUND)
12+
return()
13+
endif (NOT GLIB_FOUND)
14+
15+
set(HAVE_GLIB 1)
16+
include_directories(${GLIB_INCLUDE_DIRS})

cmake/inline.cmake

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
if (__INLINE_INCLUDED)
2+
return()
3+
endif (__INLINE_INCLUDED)
4+
set(__INLINE_INCLUDED TRUE)
5+
6+
include(CheckCSourceCompiles)
7+
8+
foreach (KEYWORD "inline" "__inline__" "__inline")
9+
set(_INLINE_SOURCE "
10+
typedef int foo_t;
11+
static ${KEYWORD} foo_t static_foo (void) {return 0; }
12+
${KEYWORD} foo_t foo (void) {return 0; }
13+
int main() { return 0; }
14+
")
15+
check_c_source_compiles("${_INLINE_SOURCE}" _${KEYWORD}_COMPLIED)
16+
if (_${KEYWORD}_COMPLIED)
17+
set(C_INLINE ${KEYWORD})
18+
break()
19+
endif (_${KEYWORD}_COMPLIED)
20+
ENDFOREACH (KEYWORD)
21+
22+
# Whether inline
23+
if (DEFINED C_INLINE)
24+
set(SU_HAVE_INLINE 1)
25+
set(SU_INLINE ${C_INLINE})
26+
set(su_inline "static ${C_INLINE}")
27+
if (ENABLE_TAG_CAST)
28+
set(SU_INLINE_TAG_CAST 1)
29+
endif (ENABLE_TAG_CAST)
30+
else ()
31+
set(SU_HAVE_INLINE 0)
32+
set(SU_INLINE /*inline*/)
33+
set(su_inline static)
34+
endif ()

cmake/openssl.cmake

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
if (__OPENSSL_INCLUDED)
2+
return()
3+
endif (__OPENSSL_INCLUDED)
4+
set(__OPENSSL_INCLUDED TRUE)
5+
6+
option(ENABLE_TLS "use OpenSSL (enabled)" ON)
7+
if (NOT ENABLE_TLS)
8+
return()
9+
endif (NOT ENABLE_TLS)
10+
11+
include(utils)
12+
sofia_include_file(openssl/tls1.h)
13+
14+
# Check Whether enable tls
15+
find_package(PkgConfig REQUIRED)
16+
pkg_check_modules(OPENSSL openssl)
17+
if (OPENSSL_FOUND)
18+
set(HAVE_LIBCRYPTO 1)
19+
set(HAVE_OPENSSL 1)
20+
set(HAVE_LIBSSL 1)
21+
set(HAVE_TLS 1)
22+
link_libraries(${OPENSSL_LIBRARIES})
23+
else (OPENSSL_FOUND)
24+
if (HAVE_OPENSSL_TLS1_H)
25+
sofia_library_exists(crypto BIO_new HAVE_OPENSSL)
26+
if (NOT HAVE_OPENSSL)
27+
message(WARNING "OpenSSL crypto library was not found")
28+
endif (NOT HAVE_OPENSSL)
29+
sofia_library_exists(ssl TLSv1_method HAVE_TLS)
30+
if (NOT HAVE_TLS)
31+
message(WARNING "OpenSSL protocol library was not found")
32+
endif (NOT HAVE_TLS)
33+
else (HAVE_OPENSSL_TLS1_H)
34+
message(WARNING "OpenSSL include files were not found")
35+
endif (HAVE_OPENSSL_TLS1_H)
36+
endif (OPENSSL_FOUND)

cmake/pthread.cmake

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
if (__PTHREAD_INCLUDED)
2+
return()
3+
endif (__PTHREAD_INCLUDED)
4+
set(__PTHREAD_INCLUDED TRUE)
5+
6+
include(utils)
7+
8+
sofia_include_file(pthread.h)
9+
if (NOT HAVE_PTHREAD_H)
10+
return()
11+
endif (NOT HAVE_PTHREAD_H)
12+
13+
link_libraries(pthread)
14+
sofia_library_exists(pthread pthread_create)
15+
16+
# Define if you have pthread_setschedparam()
17+
sofia_library_exists(pthread pthread_setschedparam HAVE_PTHREAD_SETSCHEDPARAM)
18+
19+
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} pthread)
20+
sofia_source_runs("
21+
pthread_rwlock_t rw;
22+
int main() {
23+
pthread_rwlock_init(&rw, NULL);
24+
pthread_rwlock_rdlock(&rw);
25+
pthread_rwlock_rdlock(&rw);
26+
pthread_rwlock_unlock(&rw);
27+
/* pthread_rwlock_trywrlock() should fail (not return 0) */
28+
return pthread_rwlock_trywrlock(&rw) != 0 ? 0 : 1;
29+
}
30+
" HAVE_PTHREAD_RWLOCK)

cmake/size_compat.cmake

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
if (__SIZE_COMPAT_INCLUDED)
2+
return()
3+
endif (__SIZE_COMPAT_INCLUDED)
4+
set(__SIZE_COMPAT_INCLUDED TRUE)
5+
6+
option(ENABLE_SIZE_COMPAT "use compatibility size_t types" OFF)
7+
8+
# define sofia_size_t
9+
if (ENABLE_SIZE_COMPAT)
10+
set(SOFIA_ISIZE_T size_t)
11+
set(ISIZE_MAX SIZE_MAX)
12+
set(SOFIA_ISSIZE_T ssize_t)
13+
set(ISSIZE_MAX SSIZE_MAX)
14+
set(SOFIA_USIZE_T size_t)
15+
set(USIZE_MAX SIZE_MAX)
16+
else ()
17+
set(SOFIA_ISIZE_T int)
18+
set(ISIZE_MAX INT_MAX)
19+
set(SOFIA_ISSIZE_T int)
20+
set(ISSIZE_MAX INT_MAX)
21+
set(SOFIA_USIZE_T unsigned)
22+
set(USIZE_MAX UINT_MAX)
23+
endif (ENABLE_SIZE_COMPAT)

0 commit comments

Comments
 (0)