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})
