if(UPNP_ENABLE_TESTING)
	enable_testing()
	add_subdirectory(test)
endif()

set(IXML_SOURCES
	src/attr.c
	src/document.c
	src/element.c
	src/ixml.c
	src/ixmldebug.c
	src/ixmlmembuf.c
	src/ixmlparser.c
	src/namedNodeMap.c
	src/node.c
	src/nodeList.c
)

set(IXML_HEADERS
	inc/ixml.h
	inc/ixmldebug.h)

if(UPNP_BUILD_SHARED)
	add_library(ixml_shared SHARED ${IXML_SOURCES} ${IXML_HEADERS})

	add_library(UPNP::IXMLShared ALIAS ixml_shared)

	set_target_properties(
		ixml_shared
		PROPERTIES C_VISIBILITY_PRESET "hidden"
				EXPORT_NAME UPNP::IXMLShared
				OUTPUT_NAME ixml
				PUBLIC_HEADER "${IXML_HEADERS}"
				SOVERSION ${PUPNP_VERSION_MAJOR}
				VERSION ${PUPNP_VERSION}
	)

	target_compile_definitions(
		ixml_shared
		PRIVATE
			$<$<BOOL:${IXML_HAVE_SCRIPTSUPPORT}>:IXML_HAVE_SCRIPTSUPPORT>
		PRIVATE LIBUPNP_EXPORTS
		PUBLIC $<$<BOOL:${MSVC}>:UPNP_USE_MSVCPP>
		PUBLIC $<$<BOOL:${MSVC}>:LIBUPNP_EXPORTS>
		PUBLIC $<$<BOOL:${_LARGE_FILES}>:_LARGE_FILES>
		PUBLIC $<$<BOOL:${_FILE_OFFSET_BITS}>:_FILE_OFFSET_BITS=64>
		PUBLIC $<IF:$<CONFIG:Debug>,DEBUG,NDEBUG>
	)

	target_include_directories(
		ixml_shared
		PRIVATE ${PUPNP_BINARY_DIR}/
		PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc/>
		PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/inc/>
		PUBLIC $<BUILD_INTERFACE:${PUPNP_SOURCE_DIR}/upnp/inc/>
		PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/upnp>
	)

	install(
		TARGETS ixml_shared
		EXPORT PUPNP
		ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
			COMPONENT UPNP_Development
		LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
			COMPONENT UPNP_RunTime
			NAMELINK_COMPONENT UPNP_Development
		PUBLIC_HEADER
		        DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/upnp
			COMPONENT UPNP_Development
		RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
			COMPONENT UPNP_RunTime
	)
endif()

if(UPNP_BUILD_STATIC)
	add_library(ixml_static STATIC ${IXML_SOURCES} ${IXML_HEADERS})

	add_library(UPNP::IXMLStatic ALIAS ixml_static)

	set_target_properties(
		ixml_static
		PROPERTIES C_VISIBILITY_PRESET "hidden"
				EXPORT_NAME UPNP::IXMLStatic
				OUTPUT_NAME ixml${STATIC_POSTFIX}
				PUBLIC_HEADER "${IXML_HEADERS}"
				VERSION ${PUPNP_VERSION}
	)

	target_compile_definitions(
		ixml_static
		PRIVATE
			$<$<BOOL:${IXML_HAVE_SCRIPTSUPPORT}>:IXML_HAVE_SCRIPTSUPPORT>
		PRIVATE LIBUPNP_EXPORTS
		PUBLIC UPNP_STATIC_LIB
		PUBLIC $<$<BOOL:${MSVC}>:UPNP_USE_MSVCPP>
		PUBLIC $<IF:$<CONFIG:Debug>,DEBUG,NDEBUG>
		PUBLIC $<$<BOOL:${_LARGE_FILES}>:_LARGE_FILES>
		PUBLIC $<$<BOOL:${_FILE_OFFSET_BITS}>:_FILE_OFFSET_BITS=64>
	)

	target_include_directories(
		ixml_static
		PRIVATE ${PUPNP_BINARY_DIR}/
		PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc/>
		PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/inc/>
		PUBLIC $<BUILD_INTERFACE:${PUPNP_SOURCE_DIR}/upnp/inc/>
		PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/upnp>
	)

	install(
		TARGETS ixml_static
		EXPORT PUPNP
		ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
			COMPONENT UPNP_Development
		LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
			COMPONENT UPNP_RunTime
			NAMELINK_COMPONENT UPNP_Development
		PUBLIC_HEADER
		        DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/upnp
			COMPONENT UPNP_Development
		RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
			COMPONENT UPNP_RunTime
	)
endif()
