project (resiprocate)

#if (NOT OPENSSL_INCLUDE)
#    message(FATAL_ERROR "OPENSSL_INCLUDE has to be directory with OpenSSL 1.1.x include files.")
#endif()

# Rely on C++ 20
set (CMAKE_CXX_STANDARD 20)
set (CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

set (DIR_ARES rutil/dns/ares)
set (ARES_SOURCES
    ${DIR_ARES}/ares_timeout.c
    ${DIR_ARES}/ares_strerror.c
    ${DIR_ARES}/ares_send.c
    ${DIR_ARES}/ares_search.c
    ${DIR_ARES}/ares_query.c
    ${DIR_ARES}/ares_process.c
    ${DIR_ARES}/ares_parse_ptr_reply.c
    ${DIR_ARES}/ares_parse_a_reply.c
    ${DIR_ARES}/ares_mkquery.c
    ${DIR_ARES}/ares_local.c
    ${DIR_ARES}/ares_init.c
    ${DIR_ARES}/ares_gethostbyname.c
    ${DIR_ARES}/ares_gethostbyaddr.c
    ${DIR_ARES}/ares_free_string.c
    ${DIR_ARES}/ares_free_hostent.c
    ${DIR_ARES}/ares_free_errmem.c
    ${DIR_ARES}/ares_fds.c
    ${DIR_ARES}/ares_expand_name.c
    ${DIR_ARES}/ares_destroy.c
    ${DIR_ARES}/ares__read_line.c
    ${DIR_ARES}/ares__get_hostent.c
    ${DIR_ARES}/ares__close_sockets.c
)

set (STACK_SOURCES
    resip/stack/TokenOrQuotedStringCategory.hxx
    resip/stack/TokenOrQuotedStringCategory.cxx
    resip/stack/TrickleIceContents.hxx
    resip/stack/TrickleIceContents.cxx
    resip/stack/TcpConnectState.hxx
    resip/stack/TcpConnectState.cxx
    resip/stack/gen/MonthHash.cxx
    resip/stack/gen/DayOfWeekHash.cxx
    resip/stack/Compression.cxx
    resip/stack/CallId.cxx
    resip/stack/BranchParameter.cxx
    resip/stack/BasicNonceHelper.cxx
    resip/stack/Auth.cxx
    resip/stack/ApplicationSip.cxx
    resip/stack/ApiCheck.cxx
    resip/stack/Aor.cxx
    resip/stack/DateCategory.cxx
    resip/stack/DataParameter.cxx
    resip/stack/CSeqCategory.cxx
    resip/stack/CpimContents.cxx
    resip/stack/ContentsFactoryBase.cxx
    resip/stack/Contents.cxx
    resip/stack/ConnectionManager.cxx
    resip/stack/ConnectionBase.cxx
    resip/stack/Connection.cxx
    resip/stack/DnsResult.cxx
    resip/stack/DnsInterface.cxx
    resip/stack/DeprecatedDialog.cxx
    resip/stack/GenericUri.cxx
    resip/stack/GenericContents.cxx
    resip/stack/FloatParameter.cxx
    resip/stack/ExternalBodyContents.cxx
    resip/stack/ExtensionParameter.cxx
    resip/stack/ExtensionHeader.cxx
    resip/stack/ExpiresCategory.cxx
    resip/stack/ExistsParameter.cxx
    resip/stack/ExistsOrDataParameter.cxx
    resip/stack/EventStackThread.cxx
    resip/stack/Embedded.cxx
    resip/stack/DtlsMessage.cxx
    resip/stack/gen/HeaderHash.cxx
    resip/stack/HeaderFieldValueList.cxx
    resip/stack/HeaderFieldValue.cxx
    resip/stack/MsgHeaderScanner.cxx
    resip/stack/Mime.cxx
    resip/stack/MethodTypes.cxx
    resip/stack/gen/MethodHash.cxx
    resip/stack/MessageWaitingContents.cxx
    resip/stack/MessageFilterRule.cxx
    resip/stack/Message.cxx
    resip/stack/LazyParser.cxx
    resip/stack/KeepAliveMessage.cxx
    resip/stack/InvalidContents.cxx
    resip/stack/InterruptableStackThread.cxx
    resip/stack/InteropHelper.cxx
    resip/stack/InternalTransport.cxx
    resip/stack/IntegerParameter.cxx
    resip/stack/IntegerCategory.cxx
    resip/stack/Helper.cxx
    resip/stack/HeaderTypes.cxx
    resip/stack/Headers.cxx
    resip/stack/gen/ParameterHash.cxx
    resip/stack/Parameter.cxx
    resip/stack/OctetContents.cxx
    resip/stack/NonceHelper.cxx
    resip/stack/NameAddr.cxx
    resip/stack/MultipartSignedContents.cxx
    resip/stack/MultipartRelatedContents.cxx
    resip/stack/MultipartMixedContents.cxx
    resip/stack/MultipartAlternativeContents.cxx
    resip/stack/SipStack.cxx
    resip/stack/SipMessage.cxx
    resip/stack/SipFrag.cxx
    resip/stack/SERNonceHelper.cxx
    resip/stack/SecurityAttributes.cxx
    resip/stack/SdpContents.cxx
    resip/stack/RportParameter.cxx
    resip/stack/Rlmi.cxx
    resip/stack/RequestLine.cxx
    resip/stack/RAckCategory.cxx
    resip/stack/QValueParameter.cxx
    resip/stack/QValue.cxx
    resip/stack/QuotedDataParameter.cxx
    resip/stack/PrivacyCategory.cxx
    resip/stack/PlainContents.cxx
    resip/stack/Pkcs8Contents.cxx
    resip/stack/Pkcs7Contents.cxx
    resip/stack/Pidf.cxx
    resip/stack/ParserContainerBase.cxx
    resip/stack/ParserCategory.cxx
    resip/stack/ParserCategories.cxx
    resip/stack/ParameterTypes.cxx
    resip/stack/X509Contents.cxx
    resip/stack/WarningCategory.cxx
    resip/stack/Via.cxx
    resip/stack/Uri.cxx
    resip/stack/UnknownParameter.cxx
    resip/stack/UInt32Parameter.cxx
    resip/stack/UInt32Category.cxx
    resip/stack/Cookie.hxx
    resip/stack/Cookie.cxx
    resip/stack/UdpTransport.cxx

    resip/stack/WsBaseTransport.cxx
    resip/stack/WsBaseTransport.hxx
    resip/stack/WsConnectionBase.cxx
    resip/stack/WsConnectionBase.hxx
    resip/stack/WsConnection.cxx
    resip/stack/WsConnection.hxx
    resip/stack/WsTransport.cxx
    resip/stack/WsTransport.hxx
    resip/stack/WsFrameExtractor.cxx
    resip/stack/WsFrameExtractor.hxx
    resip/stack/WsCookieContext.cxx
    resip/stack/WsCookieContext.hxx
    resip/stack/WsDecorator.cxx
    resip/stack/WsDecorator.hxx
    resip/stack/ssl/WssTransport.cxx
    resip/stack/ssl/WssTransport.hxx
    resip/stack/ssl/WssConnection.cxx
    resip/stack/ssl/WssConnection.hxx
    resip/stack/ssl/TlsBaseTransport.cxx
    resip/stack/ssl/TlsBaseTransport.hxx

    resip/stack/TuSelector.cxx
    resip/stack/TupleMarkManager.cxx
    resip/stack/Tuple.cxx
    resip/stack/TuIM.cxx
    resip/stack/TransportThread.cxx
    resip/stack/TransportSelector.cxx
    resip/stack/TransportFailure.cxx
    resip/stack/Transport.cxx
    resip/stack/TransactionUserMessage.cxx
    resip/stack/TransactionUser.cxx
    resip/stack/TransactionState.cxx
    resip/stack/TransactionMap.cxx
    resip/stack/TransactionController.cxx
    resip/stack/Token.cxx
    resip/stack/TimerQueue.cxx
    resip/stack/TimerMessage.cxx
    resip/stack/TimeAccumulate.cxx
    resip/stack/TcpTransport.cxx
    resip/stack/TcpConnection.cxx
    resip/stack/TcpBaseTransport.cxx
    resip/stack/Symbols.cxx
    resip/stack/StringCategory.cxx
    resip/stack/StatusLine.cxx
    resip/stack/StatisticsMessage.cxx
    resip/stack/StatisticsManager.cxx
    resip/stack/StatisticsHandler.cxx
    resip/stack/StatelessHandler.cxx
    resip/stack/StackThread.cxx
    resip/stack/ssl/Security.cxx
    #resip/stack/ssl/MacSecurity.cxx
    resip/stack/ssl/TlsConnection.cxx
    resip/stack/ssl/TlsTransport.cxx

    resip/stack/BasicDomainMatcher.hxx
    resip/stack/BasicDomainMatcher.cxx
    )

if (CMAKE_SYSTEM MATCHES "Windows*")
    set (STACK_SOURCES ${STACK_SOURCES}
        resip/stack/ssl/WinSecurity.cxx)
endif()

set (DUM_SOURCES
    resip/dum/DialogUsageManager.cxx
    resip/dum/DialogUsage.cxx
    resip/dum/DialogSetId.cxx
    resip/dum/DialogSet.cxx
    resip/dum/DialogId.cxx
    resip/dum/DialogEventStateManager.cxx
    resip/dum/DialogEventInfo.cxx
    resip/dum/Dialog.cxx
    resip/dum/DestroyUsage.cxx
    resip/dum/DefaultServerReferHandler.cxx
    resip/dum/ContactInstanceRecord.cxx
    resip/dum/ClientSubscription.cxx
    resip/dum/ClientRegistration.cxx
    resip/dum/ClientPublication.cxx
    resip/dum/ClientPagerMessage.cxx
    resip/dum/ClientOutOfDialogReq.cxx
    resip/dum/ClientInviteSession.cxx
    resip/dum/ClientAuthManager.cxx
    resip/dum/ClientAuthExtension.cxx
    resip/dum/ChallengeInfo.cxx
    resip/dum/CertMessage.cxx
    resip/dum/BaseUsage.cxx
    resip/dum/BaseSubscription.cxx
    resip/dum/BaseCreator.cxx
    resip/dum/AppDialogSetFactory.cxx
    resip/dum/AppDialogSet.cxx
    resip/dum/AppDialog.cxx
    resip/dum/KeepAliveTimeout.cxx
    resip/dum/KeepAliveManager.cxx
    resip/dum/InviteSessionHandler.cxx
    resip/dum/InviteSessionCreator.cxx
    resip/dum/InviteSession.cxx
    resip/dum/InMemorySyncRegDb.cxx
    resip/dum/InMemoryRegistrationDatabase.cxx
    resip/dum/IdentityHandler.cxx
    resip/dum/HttpProvider.cxx
    resip/dum/HttpGetMessage.cxx
    resip/dum/HandleManager.cxx
    resip/dum/HandleException.cxx
    resip/dum/Handled.cxx
    resip/dum/Handle.cxx
    resip/dum/EncryptionRequest.cxx
    resip/dum/DumTimeout.cxx
    resip/dum/DumThread.cxx
    resip/dum/DumProcessHandler.cxx
    resip/dum/DumHelper.cxx
    resip/dum/DumFeatureMessage.cxx
    resip/dum/DumFeatureChain.cxx
    resip/dum/DumFeature.cxx
    resip/dum/DumDecrypted.cxx
    resip/dum/ServerSubscription.cxx
    resip/dum/ServerRegistration.cxx
    resip/dum/ServerPublication.cxx
    resip/dum/ServerPagerMessage.cxx
    resip/dum/ServerOutOfDialogReq.cxx
    resip/dum/ServerInviteSession.cxx
    resip/dum/ServerAuthManager.cxx
    resip/dum/RegistrationHandler.cxx
    resip/dum/RegistrationCreator.cxx
    resip/dum/RedirectManager.cxx
    resip/dum/RADIUSServerAuthManager.cxx
    resip/dum/PublicationCreator.cxx
    resip/dum/Profile.cxx
    resip/dum/PagerMessageCreator.cxx
    resip/dum/OutOfDialogReqCreator.cxx
    resip/dum/OutgoingEvent.cxx
    resip/dum/NonDialogUsage.cxx
    resip/dum/NetworkAssociation.cxx
    resip/dum/MergedRequestRemovalCommand.cxx
    resip/dum/MergedRequestKey.cxx
    resip/dum/MasterProfile.cxx
    resip/dum/UserProfile.cxx
    resip/dum/UserAuthInfo.cxx
    resip/dum/TlsPeerAuthManager.cxx
    resip/dum/TargetCommand.cxx
    resip/dum/SubscriptionState.cxx
    resip/dum/SubscriptionHandler.cxx
    resip/dum/SubscriptionCreator.cxx
    resip/dum/ssl/EncryptionManager.cxx
    )

SET (RUTIL_SOURCES
    rutil/FileSystem.cxx
    rutil/FdPoll.cxx
    rutil/DnsUtil.cxx
    rutil/ssl/OpenSSLInit.cxx
    rutil/ssl/SHA1Stream.cxx
    rutil/dns/RRVip.cxx
    rutil/dns/RROverlay.cxx
    rutil/dns/RRList.cxx
    rutil/dns/RRCache.cxx
    rutil/dns/QueryTypes.cxx
    # rutil/dns/LocalDns.cxx
    rutil/dns/ExternalDnsFactory.cxx
    rutil/dns/DnsThread.cxx
    rutil/dns/DnsStub.cxx
    rutil/dns/DnsSrvRecord.cxx
    rutil/dns/DnsResourceRecord.cxx
    rutil/dns/DnsNaptrRecord.cxx
    rutil/dns/DnsHostRecord.cxx
    rutil/dns/DnsCnameRecord.cxx
    rutil/dns/DnsAAAARecord.cxx
    rutil/dns/AresDns.cxx
    rutil/DataStream.cxx
    rutil/Data.cxx
    rutil/CountStream.cxx
    rutil/ConfigParse.cxx
    # rutil/Condition.cxx
    rutil/Coders.cxx
    rutil/BaseException.cxx
    rutil/AbstractFifo.cxx
    rutil/XMLCursor.cxx
    rutil/vmd5.cxx
    rutil/TransportType.cxx
    rutil/Timer.cxx
    rutil/Time.cxx
    rutil/ThreadIf.cxx
    rutil/SysLogStream.cxx
    rutil/SysLogBuf.cxx
    rutil/Subsystem.cxx
    rutil/stun/Udp.cxx
    rutil/stun/Stun.cxx
    rutil/Socket.cxx
    rutil/ServerProcess.cxx
    rutil/SelectInterruptor.cxx
    rutil/RWMutex.cxx
    rutil/resipfaststreams.cxx
    # rutil/RecursiveMutex.cxx
    rutil/Random.cxx
    rutil/RADIUSDigestAuthenticator.cxx
    rutil/PoolBase.cxx
    rutil/Poll.cxx
    rutil/ParseException.cxx
    rutil/ParseBuffer.cxx
    # rutil/Mutex.cxx
    rutil/MD5Stream.cxx
    rutil/Log.cxx
    rutil/Lock.cxx
    rutil/KeyValueStore.cxx
    rutil/HeapInstanceCounter.cxx
    rutil/GeneralCongestionManager.cxx
    rutil/ssl/OpenSSLDeleter.hxx
    rutil/ssl/OpenSSLDeleter.cxx
    )

if (CMAKE_SYSTEM MATCHES "Windows*")
    set (RUTIL_SOURCES ${RUTIL_SOURCES} rutil/WinCompat.cxx)
endif()

add_library(resiprocate STATIC ${ARES_SOURCES} ${RUTIL_SOURCES} ${STACK_SOURCES} ${DUM_SOURCES})

target_include_directories(resiprocate PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${DIR_ARES}
    ${OPENSSL_INCLUDE}
    )

set (RESIP_DEFINES -DUSE_SSL -DUSE_IPV6 -DUSE_ARES)
if (TARGET_WIN)
    set (RESIP_DEFINES ${RESIP_DEFINES} -DARES_LEGACY_DEFINES -DNOMINMAX)
else()
    set (RESIP_DEFINES ${RESIP_DEFINES} -DHAVE_ARPA_NAMESER_H)
endif()

find_package(OpenSSL)
target_link_libraries(resiprocate PUBLIC OpenSSL::SSL)
target_link_libraries(resiprocate PUBLIC OpenSSL::Crypto)

target_compile_definitions(resiprocate PUBLIC ${RESIP_DEFINES})

if (TARGET_LINUX OR TARGET_OSX OR TARGET_ANDROID OR TARGET_IOS)
    target_compile_options(resiprocate PUBLIC -Wno-deprecated -Wno-deprecated-declarations)
endif()
