include_directories(AFTER ${PYTHON_INCLUDE_PATH})

python_add_module(libs
	cal.c
	#calcmd.c
	libs.c
	msgapi.c
	msgapi-defs.c
	pybongo.c
	streamio.c
	json.c
	tests/tests.c
	bongoutil.c
)

target_include_directories(libs PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

python_add_module(bootstrap 
	bootstrap.c
	msgapi-defs.c
	pybongo.c
)

python_add_module(_calendar
	calendar-module.c
	cal.c
	json.c
	pybongo.c
)

python_add_module(_external_accounts
	external-accounts-module.c
)

python_add_module(_qrcode
	qrcode-module.c
)

python_add_module(_auth_security
	auth-security-module.c
)

python_add_module(_rules
	rules-module.c
)

# remove 'lib' prefix from these libraries.
set_target_properties(libs bootstrap _calendar _external_accounts _qrcode _auth_security _rules
	PROPERTIES
	PREFIX ""
)

target_link_libraries(libs
	bongomsgapi
	bongojson
	bongoutil
	bongoxpl
	bongocal
	bongoconnio
	bongostreamio
	${PYTHON_LIBRARIES}
)

target_link_libraries(bootstrap
	bongomsgapi
	${PYTHON_LIBRARIES}
)

target_link_libraries(_calendar
	bongomsgapi
	bongojson
	bongoutil
	bongoxpl
	bongocal
	${PYTHON_LIBRARIES}
)

target_link_libraries(_external_accounts
	bongocollectoraccounts
	bongoxpl
	GLib2::GLib2
	${PYTHON_LIBRARIES}
)

target_link_libraries(_qrcode
	QRencode::QRencode
	${PYTHON_LIBRARIES}
)

target_link_libraries(_auth_security
	bongoauthstore
	bongoauthsecurity
	${PYTHON_LIBRARIES}
)

target_link_libraries(_rules
	bongomsgapi
	bongoxpl
	${PYTHON_LIBRARIES}
)

install(TARGETS libs bootstrap _calendar _external_accounts _qrcode _auth_security _rules DESTINATION ${PYTHON_SITELIB_PATH}/libbongo/)
install(FILES __init__.py DESTINATION ${PYTHON_SITELIB_PATH}/libbongo/)

if(BUILD_TESTING)
	add_test(NAME python-qrcode
		COMMAND "${CMAKE_COMMAND}" -E env
			"PYTHONPATH=$<TARGET_FILE_DIR:_qrcode>"
			"${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/qrcode-test.py")
	add_test(NAME python-auth-security
		COMMAND "${CMAKE_COMMAND}" -E env
			"PYTHONPATH=$<TARGET_FILE_DIR:_auth_security>"
			"${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/auth-security-test.py")
endif()
