add_library(bongoauthstore SHARED
	auth-security-store.c)

target_include_directories(bongoauthstore PUBLIC
	${CMAKE_CURRENT_SOURCE_DIR})

target_link_libraries(bongoauthstore PRIVATE
	bongoauthsecurity
	LibGcrypt::LibGcrypt
	SQLite3::SQLite3)

set_target_properties(bongoauthstore PROPERTIES
	SOVERSION 0
	VERSION ${BONGO_V_STR})

install(TARGETS bongoauthstore DESTINATION ${LIB_INSTALL_DIR})

add_library(authsqlite3 MODULE
	sqlite.c
	ldap.c
	password.c)

target_link_libraries(authsqlite3 PRIVATE
	bongoauthstore
	bongoauthsecurity
	bongomsgapi
	bongoutil
	bongoxpl
	LibGcrypt::LibGcrypt
	OpenLDAP::LDAP
	SQLite3::SQLite3)

install(TARGETS authsqlite3 DESTINATION ${LIB_INSTALL_DIR}/bongo-auth)

if(BUILD_TESTING)
	add_executable(auth-password-test tests/password-test.c password.c)
	target_include_directories(auth-password-test PRIVATE
		${CMAKE_CURRENT_SOURCE_DIR})
	target_link_libraries(auth-password-test PRIVATE
		bongoauthsecurity
		bongoxpl
		LibGcrypt::LibGcrypt)
	add_test(NAME auth-password COMMAND auth-password-test)

	add_executable(auth-security-store-test
		tests/auth-security-store-test.c)
	target_link_libraries(auth-security-store-test PRIVATE
		bongoauthstore
		bongoauthsecurity
		OATH::OATH
		SQLite3::SQLite3)
	add_test(NAME auth-security-store COMMAND auth-security-store-test)

	add_executable(auth-ldap-test
		tests/ldap-auth-test.c
		ldap.c)
	target_include_directories(auth-ldap-test PRIVATE
		${CMAKE_CURRENT_SOURCE_DIR})
	target_link_libraries(auth-ldap-test PRIVATE OpenLDAP::LDAP)
	add_test(NAME auth-ldap COMMAND auth-ldap-test)

	add_executable(auth-module-load-test tests/module-load-test.c)
	target_link_libraries(auth-module-load-test PRIVATE ${CMAKE_DL_LIBS})
	add_test(NAME auth-module-load
		COMMAND auth-module-load-test $<TARGET_FILE:authsqlite3>)
endif()
