# Template rules for modules
IF(WANT_COEXISTENCE)
	SET(KVIRC_BINARYNAME ${PACKAGE}${VERSION_MAJOR})
	SET(KVILIB_BINARYNAME kvilib${VERSION_MAJOR})
ELSE()
	SET(KVIRC_BINARYNAME ${PACKAGE})
	SET(KVILIB_BINARYNAME kvilib)
ENDIF()

ADD_LIBRARY(${kvi_module_name} MODULE ${${kvi_module_name}_SRCS} ${${kvi_module_name}_MOC_SRCS})

# LIBS is a list.. but we need to get rid of -Wl,--no-undefined inside each element
SET(MODULE_LIBS)

FOREACH(LIB ${LIBS})
	STRING(REPLACE "-Wl,--no-undefined" "" LIB ${LIB})
	IF(${LIB})
		SET(MODULE_LIBS ${MODULE_LIBS} ${LIB})
	ENDIF(${LIB})
ENDFOREACH(LIB ${LIBS})


IF(WIN32)
	TARGET_LINK_LIBRARIES(${kvi_module_name} ${KVILIB_BINARYNAME} ${KVIRC_BINARYNAME} ${KVIRC_BINARYNAME} ${MODULE_LIBS})
ELSE()
	TARGET_LINK_LIBRARIES(${kvi_module_name} ${KVILIB_BINARYNAME} ${MODULE_LIBS})
ENDIF()

STRING(REPLACE "-Wl,--no-undefined" "" MODULE_ADDITIONAL_LINK_FLAGS "${ADDITIONAL_LINK_FLAGS}")

SET_TARGET_PROPERTIES(${kvi_module_name} PROPERTIES LINK_FLAGS "${MODULE_ADDITIONAL_LINK_FLAGS}")
SET_TARGET_PROPERTIES(${kvi_module_name} PROPERTIES COMPILE_FLAGS "${ADDITIONAL_COMPILE_FLAGS}")

IF(WANT_STRIP)
	GET_TARGET_PROPERTY(kvi_module_location ${kvi_module_name} LOCATION)
	INSTALL(CODE "EXEC_PROGRAM(${STRIP_EXECUTABLE} ARGS -s \"${kvi_module_location}\")")
ENDIF()

INSTALL(TARGETS ${kvi_module_name} LIBRARY DESTINATION "${KVIRC_MOD_PATH}")
