# Add Platform specific configuration for a generic app variation
MACRO( WG_APP_PLATFORM_CONFIGURATION )
	IF( BW_PLATFORM_WINDOWS )
		SET( PLATFORM_LIBRARIES
			shlwapi)
		SET( PLUGIN_CONFIG_FOLDER plugins )
		SET( PLUGIN_SETTINGS_FOLDER ./ )
	ELSEIF( BW_PLATFORM_MAC )
		SET(PLATFORM_LIBRARIES
			core_common)
		SET( PLUGIN_CONFIG_FOLDER ../Resources/plugins )
		SET( PLUGIN_SETTINGS_FOLDER ./ )

		SET( CMAKE_EXE_LINKER_FLAGS
			"${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,@loader_path/../Frameworks"
		)
	ENDIF()
ENDMACRO()

FUNCTION( WG_CREATE_CONFIG_FILE _CONFIG_FILENAME)
	# Generate the config file if it doesn't already exists, otherwise adding it to the solution will fail
	IF(NOT EXISTS ${_CONFIG_FILENAME})
		file(WRITE ${_CONFIG_FILENAME} 
			"# AUTOMATICALLY GENERATED FILE! Do not edit this file.\n"
			"# Generated from: " ${CMAKE_CURRENT_LIST_FILE} "\n")
	ENDIF()
ENDFUNCTION()

# Macro for setting the default used config file for a generic app variation
FUNCTION( WG_APP_DEFAULT_CONFIG_FILE _CONFIG_FILENAME )
	ADD_DEFINITIONS( -DDEFAULT_CONFIG_FILE=L\"${_CONFIG_FILENAME}\" )
	WG_CREATE_CONFIG_FILE( "config/${_CONFIG_FILENAME}")
ENDFUNCTION()

# Macro for setting the default used pre config file for a qt desktop app variation
FUNCTION( WG_APP_DEFAULT_PRE_CONFIG_FILE _CONFIG_FILENAME )
	ADD_DEFINITIONS( -DDEFAULT_PRE_CONFIG_FILE=L\"${_CONFIG_FILENAME}\" )
	WG_CREATE_CONFIG_FILE( "config/${_CONFIG_FILENAME}")
ENDFUNCTION()

# Macro for setting the default used post config file for a qt desktop app variation
FUNCTION( WG_APP_DEFAULT_POST_CONFIG_FILE _CONFIG_FILENAME )
	ADD_DEFINITIONS( -DDEFAULT_POST_CONFIG_FILE=L\"${_CONFIG_FILENAME}\" )
	WG_CREATE_CONFIG_FILE( "config/${_CONFIG_FILENAME}")
ENDFUNCTION()

# Macro for setting the default splash resource path for a qt desktop app variation
FUNCTION( WG_APP_SPLASH_RESOURCE_PATH _SPLASH_PATH )
	ADD_DEFINITIONS( -DDEFAULT_SPLASH_RESOURCE_PATH=\"${_SPLASH_PATH}\" )
ENDFUNCTION()

# Macro for the framework for a generic app variation
# Will automatically copy any config files set in PLUGIN_CONFIG_FILES
# Will automatically copy any settings files set in PLUGIN_SETTINGS_FILES
# Set default config file used by: WG_APP_DEFAULT_CONFIG_FILE( file.txt )
MACRO( WG_APP_MAKE_GENERIC )
	INCLUDE( WGToolsCoreProject )
	INCLUDE( WGProjectUserFile )

	SET( APP_CODE_SRCS
		${WG_TOOLS_SOURCE_DIR}/core/app/generic_app/app/main.cpp
	)
	SOURCE_GROUP( "App" FILES ${APP_CODE_SRCS} )

	IF( NOT PLUGIN_CONFIG_FILES )
		SET( PLUGIN_CONFIG_FILES )
	ENDIF()
	
	FILE(GLOB PLUGIN_CONFIG_FILES_GLOB ${PLUGIN_CONFIG_FILES})
	SOURCE_GROUP( "Plugin Configurations" FILES ${PLUGIN_CONFIG_FILES_GLOB} )

	IF( NOT PLUGIN_SETTINGS_FILES )
		SET( PLUGIN_SETTINGS_FILES )
	ENDIF()	
	
	FILE(GLOB PLUGIN_SETTINGS_FILES_GLOB ${PLUGIN_SETTINGS_FILES})
	SOURCE_GROUP( "Plugin Settings" FILES ${PLUGIN_SETTINGS_FILES_GLOB} )

	WG_BLOB_SOURCES( BLOB_SRCS
		${APP_CODE_SRCS}
		${PLUGIN_CONFIG_FILES_GLOB}
		${PLUGIN_SETTINGS_FILES_GLOB}
		${ARGN}
	)
	
	BW_ADD_TOOL_EXE( ${PROJECT_NAME} WIN32 ${BLOB_SRCS} )

	WG_APP_PLATFORM_CONFIGURATION()

	BW_TARGET_LINK_LIBRARIES( ${PROJECT_NAME} PRIVATE
		core_wgtf_app
		core_generic_plugin_manager
		core_file_logging
		wgtf_memory

		# external libraries
		${PLATFORM_LIBRARIES}
	)

	BW_CUSTOM_COPY_TO_PROJECT_OUTPUT( ${PLUGIN_CONFIG_FOLDER} "${PLUGIN_CONFIG_FILES_GLOB}" )
	BW_CUSTOM_COPY_TO_PROJECT_OUTPUT( ${PLUGIN_SETTINGS_FOLDER} "${PLUGIN_SETTINGS_FILES_GLOB}" )

	BW_PROJECT_CATEGORY( ${PROJECT_NAME} "Executables" )
ENDMACRO()
