FILE(GLOB SRC_NTLMCLIENT "ntlm.c" "ntlm.h" "util.c" "util.h")
LIST(SORT SRC_NTLMCLIENT)

ADD_DEFINITIONS(-DNTLM_STATIC=1)

DISABLE_WARNINGS(implicit-fallthrough)

IF(USE_ICONV)
	ADD_DEFINITIONS(-DUNICODE_ICONV=1)
	FILE(GLOB SRC_NTLMCLIENT_UNICODE "unicode_iconv.c" "unicode_iconv.h")
ELSE()
	ADD_DEFINITIONS(-DUNICODE_BUILTIN=1)
	FILE(GLOB SRC_NTLMCLIENT_UNICODE "unicode_builtin.c" "unicode_builtin.h")
ENDIF()

IF(USE_HTTPS STREQUAL "SecureTransport")
	ADD_DEFINITIONS(-DCRYPT_COMMONCRYPTO)
	SET(SRC_NTLMCLIENT_CRYPTO "crypt_commoncrypto.c" "crypt_commoncrypto.h")
	# CC_MD4 has been deprecated in macOS 10.15.
	SET_SOURCE_FILES_PROPERTIES("crypt_commoncrypto.c" COMPILE_FLAGS "-Wno-deprecated")
ELSEIF(USE_HTTPS STREQUAL "OpenSSL")
	ADD_DEFINITIONS(-DCRYPT_OPENSSL)
	INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
	SET(SRC_NTLMCLIENT_CRYPTO "crypt_openssl.c" "crypt_openssl.h")
ELSEIF(USE_HTTPS STREQUAL "OpenSSL-Dynamic")
	ADD_DEFINITIONS(-DCRYPT_OPENSSL)
	ADD_DEFINITIONS(-DCRYPT_OPENSSL_DYNAMIC)
	SET(SRC_NTLMCLIENT_CRYPTO "crypt_openssl.c" "crypt_openssl.h")
ELSEIF(USE_HTTPS STREQUAL "mbedTLS")
	ADD_DEFINITIONS(-DCRYPT_MBEDTLS)
	INCLUDE_DIRECTORIES(${MBEDTLS_INCLUDE_DIR})
	SET(SRC_NTLMCLIENT_CRYPTO "crypt_mbedtls.c" "crypt_mbedtls.h")
ELSE()
	MESSAGE(FATAL_ERROR "Unable to use libgit2's HTTPS backend (${USE_HTTPS}) for NTLM crypto")
ENDIF()

ADD_LIBRARY(ntlmclient OBJECT ${SRC_NTLMCLIENT} ${SRC_NTLMCLIENT_UNICODE} ${SRC_NTLMCLIENT_CRYPTO})
