set(_external_sources
	"${CMAKE_CURRENT_SOURCE_DIR}/../common/src/Common.cpp"
	src/ExternalShortener.cpp)

add_library(EchoionUrlShortenerExternalPlugin MODULE
	${_external_sources}
	src/Plugin.cpp)
target_include_directories(EchoionUrlShortenerExternalPlugin PRIVATE
	"${CMAKE_CURRENT_SOURCE_DIR}/include"
	"${CMAKE_CURRENT_SOURCE_DIR}/../common/include")
target_compile_features(EchoionUrlShortenerExternalPlugin PRIVATE cxx_std_26)
target_link_libraries(EchoionUrlShortenerExternalPlugin PRIVATE
	Echoion::ApiPlugin
	Echoion::ApiConfig
	Void::ShortUrl
	Void::Data
	Void::Net
	Void::Text
	Boost::url
	Threads::Threads)
set_target_properties(EchoionUrlShortenerExternalPlugin PROPERTIES
	PREFIX ""
	OUTPUT_NAME "url-shortener-external"
	LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/plugins"
	RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/plugins"
	BUILD_RPATH_USE_ORIGIN ON
	INSTALL_RPATH ""
	INSTALL_RPATH_USE_LINK_PATH FALSE)

if(MSVC)
	target_compile_options(EchoionUrlShortenerExternalPlugin PRIVATE /W4 /WX-)
else()
	target_compile_options(EchoionUrlShortenerExternalPlugin PRIVATE
		-Wall -Wextra -Wpedantic)
endif()

install(TARGETS EchoionUrlShortenerExternalPlugin
	LIBRARY DESTINATION
		"${CMAKE_INSTALL_DATADIR}/echoion/bootstrap-plugins/url-shortener-external/${ECHOION_URL_SHORTENER_EXTERNAL_VERSION}"
		COMPONENT Runtime
	RUNTIME DESTINATION
		"${CMAKE_INSTALL_DATADIR}/echoion/bootstrap-plugins/url-shortener-external/${ECHOION_URL_SHORTENER_EXTERNAL_VERSION}"
		COMPONENT Runtime)

if(BUILD_TESTS)
	add_executable(echoion_url_shortener_external_tests
		${_external_sources}
		tests/ExternalShortenerTests.cpp)
	target_include_directories(echoion_url_shortener_external_tests PRIVATE
		"${CMAKE_CURRENT_SOURCE_DIR}/include"
		"${CMAKE_CURRENT_SOURCE_DIR}/../common/include")
	target_compile_features(echoion_url_shortener_external_tests PRIVATE
		cxx_std_26)
	target_link_libraries(echoion_url_shortener_external_tests PRIVATE
		Void::ShortUrl Void::Data Void::Net Void::Text Boost::url Threads::Threads)
	add_test(NAME echoion_url_shortener_external_tests
		COMMAND echoion_url_shortener_external_tests)
	set_tests_properties(echoion_url_shortener_external_tests PROPERTIES
		TIMEOUT 20)
endif()
