PROJECT(plasma-applet-yawp)
cmake_minimum_required(VERSION 2.6)

#if you don't want the full compiler output, remove the following line
SET(CMAKE_VERBOSE_MAKEFILE ON)

#add definitions, compiler switches, etc.
#ADD_DEFINITIONS(-Wall -O2)

#  CMAKE_BUILD_TYPE:
#  A variable which controls the type of build when using a single-configuration generator like the Makefile generator.
#  CMake will create by default the following variables when using a single-configuration generator:
#
#    * None (CMAKE_C_FLAGS or CMAKE_CXX_FLAGS used)
#    * Debug (CMAKE_C_FLAGS_DEBUG or CMAKE_CXX_FLAGS_DEBUG)
#    * Release (CMAKE_C_FLAGS_RELEASE or CMAKE_CXX_FLAGS_RELEASE)
#    * RelWithDebInfo (CMAKE_C_FLAGS_RELWITHDEBINFO or CMAKE_CXX_FLAGS_RELWITHDEBINFO
#    * MinSizeRel (CMAKE_C_FLAGS_MINSIZEREL or CMAKE_CXX_FLAGS_MINSIZEREL) 


## Find the required Libaries
##
FIND_PACKAGE(KDE4 REQUIRED)
INCLUDE(KDE4Defaults)
INCLUDE(MacroLibrary)


find_package(KDE4Workspace QUIET)

## Need a better way to find cmake scripts at arb locations
if ( NOT ${KDE4Workspace_FOUND} )
	message(STATUS "COULD NOT FIND KDE4Workspace TRYING /usr/lib64/cmake/KDE4Workspace-4.3.1")
	SET (KDE4Workspace_DIR /usr/lib64/cmake/KDE4Workspace-4.3.1)
	find_package(KDE4Workspace REQUIRED)
endif ( NOT ${KDE4Workspace_FOUND} )

if ( ${KDE_VERSION} VERSION_LESS "4.1.90" )
	find_package(Plasma REQUIRED)
else ( ${KDE_VERSION} VERSION_LESS "4.1.90" )
	set( PLASMA_LIBS ${KDE4_PLASMA_LIBS} )
endif ( ${KDE_VERSION} VERSION_LESS "4.1.90" )

if ( ${KDE_VERSION} VERSION_GREATER "4.2.9" )
	set( KDE4WORKSPACE_WEATHERION_LIBRARY weather_ion)
endif ( ${KDE_VERSION} VERSION_GREATER "4.2.9" )

FIND_PACKAGE(Qt4 REQUIRED QtNetwork QtGui QtCore QtXml QtSvg QtDbus)


INCLUDE_DIRECTORIES(
	${QT_INCLUDES}
	${KDE4_INCLUDE_DIR}
	${KDE4_INCLUDES}
	${KDE4WORKSPACE_INCLUDE_DIR}
	${CMAKE_CURRENT_SOURCE_DIR}
	)
	
ADD_DEFINITIONS(${QT_DEFINITIONS} ${KDE4_DEFINITIONS})

## enable or disable the src/logger/streamlogger.cpp log-system
## when disabling the logsystem, no debug output occurs
IF( "${CMAKE_BUILD_TYPE}" STREQUAL "Debug" OR "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo" )
	## Loglevel needs to be valid, when streamlogger_definitions.h will be build.
	IF( NOT DEBUG_LOGLEVEL )
		SET(DEBUG_LOGLEVEL "Debug")
	ENDIF( NOT DEBUG_LOGLEVEL )

	## enable logging and create header that contains the settings (loglevel and logfile)
	ADD_DEFINITIONS( -DENABLE_DSTREAMLOGGER )
	CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/logger/streamlogger_definitions.h.in ${CMAKE_BINARY_DIR}/logger/streamlogger_definitions.h)
ENDIF( "${CMAKE_BUILD_TYPE}" STREQUAL "Debug" OR "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo" )

# Choose the type of build.  Example: SET(CMAKE_BUILD_TYPE Debug) 
MESSAGE( STATUS "CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE} )

# the compiler flags for compiling C sources 
MESSAGE( STATUS "CMAKE_C_FLAGS: " ${CMAKE_C_FLAGS} )

# If set, runtime paths are not added when using shared libraries. Default it is set to OFF
MESSAGE( STATUS "CMAKE_SKIP_RPATH: " ${CMAKE_SKIP_RPATH} )
MESSAGE( STATUS "DEBUG_LOGLEVEL: " ${DEBUG_LOGLEVEL} )
MESSAGE( STATUS "DEBUG_LOGFILE: " ${DEBUG_LOGFILE} )

############################################################
##
##    YAWP specific settings
##

##	DEFINE THE PACKAGE VERSION AND NAME
SET(YAWP_MAJOR_VERSION 0)
SET(YAWP_MINOR_VERSION 4)
SET(YAWP_PATCH_VERSION 5)
SET(YAWP_NAME "yaWP")

SET(QT_VERSION_STRING ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH})


configure_file(config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
macro_display_feature_log()


add_subdirectory(applet)
add_subdirectory(ions)
add_subdirectory(po)

IF( "${BUILD_UNITTESTS}" STREQUAL "YES" )
	## This will create a static lib. We can link a program against a static
	## but we can not link a plugin against a static lib. At least i don not know how to do it,
	## So, if you know how to do it, please let me know.
	add_subdirectory(logger)
	add_subdirectory(unittest)
ENDIF( "${BUILD_UNITTESTS}" STREQUAL "YES" )

############################################################
##
##    Package Generator
##
IF(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
	MESSAGE(STATUS "CMakeRoot: ${CMAKE_ROOT}/Modules/CPack.cmake")
	SET(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE 1)
	INCLUDE(InstallRequiredSystemLibraries)

	SET(CPACK_PACKAGE_RELOCATABLE "true")
	SET(CPACK_SET_DESTDIR "on")
	SET(CPACK_PACKAGING_INSTALL_PREFIX "/tmp")
	SET(CPACK_GENERATOR "DEB;RPM;STGZ;TBZ2;TGZ;TZ;ZIP;SOURCE_TGZ;SOURCE_TZ;SOURCE_ZIP;")
	SET(CPACK_SOURCE_IGNORE_FILES 
		"/build/"
		"/.svn/"
		".kdev4$"
		"~$")

	SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Yet Another Weather Plasmoid")
	SET(CPACK_PACKAGE_VENDOR "Plasma Factory")
	SET(CPACK_PACKAGE_CONTACT "Plasma Factory <plasmafactory@jcell.co.za>")
	SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYRIGHT")

	SET(CPACK_PACKAGE_VERSION_MAJOR	${YAWP_MAJOR_VERSION})
	SET(CPACK_PACKAGE_VERSION_MINOR	${YAWP_MINOR_VERSION})	# to create a debian confirm file-version-string
	STRING(REGEX REPLACE "_" "-" CPACK_PACKAGE_VERSION_PATCH ${YAWP_PATCH_VERSION})
	SET(CPACK_SOURCE_PACKAGE_FILE_NAME	${CMAKE_PROJECT_NAME}_${YAWP_MAJOR_VERSION}.${YAWP_MINOR_VERSION}.${CPACK_PACKAGE_VERSION_PATCH}_source)

	##	LIST EXECUTABLES
	SET(CPACK_STRIP_FILES "lib//plasma_applet_yawp.so;lib//ion_accuweather.so;lib//ion_google.so;lib/ion_wunderground.so")


	##	DEFINE SOME DEBIAN SPECIFIC VARIABLES
	##
	IF( "${PACKAGE_TYPE}" STREQUAL "DEB" )
		IF(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
			SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE amd64)
		ELSEIF(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
			SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386)
		ELSE(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
			SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
		ENDIF(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")

		SET(CPACK_PACKAGE_FILE_NAME ${CMAKE_PROJECT_NAME}_${YAWP_MAJOR_VERSION}.${YAWP_MINOR_VERSION}.${CPACK_PACKAGE_VERSION_PATCH}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE})

		SET(CPACK_DEBIAN_PACKAGE_NAME ${CMAKE_PROJECT_NAME})
		SET(CPACK_DEBIAN_PACKAGE_HOMEPAGE "http://kde-look.org/content/show.php/yaWP+%28Yet+Another+Weather+Plasmoid%29?content=94106")
		SET(CPACK_DEBIAN_PACKAGE_DESCRIPTION "Plasma widget for KDE 4 that displays some weather information. Yet Another Weather Plasmoid that shows the current weather conditions\n and up to 4 days forecast depending on the chosen weather engine (ion).\n This package also contains two ions (accuweather and wunderground).")
		SET(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
		SET(CPACK_DEBIAN_PACKAGE_SECTION "kde")
		SET(CPACK_DEBIAN_PACKAGE_DEPENDS "gettext, libplasma3, kdebase-runtime (>= 4:${KDE_VERSION}), kdelibs-bin (>= 4:${KDE_VERSION}), libqt4-network (>= ${QT_VERSION_STRING}), libqt4-svg (>= ${QT_VERSION_STRING}), libqt4-xml (>= ${QT_VERSION_STRING}), libqtcore4 (>= ${QT_VERSION_STRING}), libqtgui4 (>= ${QT_VERSION_STRING})")
		
		add_subdirectory(distros/Debian)
		
	ENDIF ( "${PACKAGE_TYPE}" STREQUAL "DEB" )

	##	DEFINE SOME RPM SPECIFIC VARIABLES
	##
	IF( "${PACKAGE_TYPE}" STREQUAL "RPM" )
		SET(CPACK_RPM_PACKAGE_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})

		SET(CPACK_PACKAGE_FILE_NAME ${CMAKE_PROJECT_NAME}_${YAWP_MAJOR_VERSION}.${YAWP_MINOR_VERSION}.${CPACK_PACKAGE_VERSION_PATCH}_${CPACK_RPM_PACKAGE_ARCHITECTURE})
		SET(CPACK_RPM_PACKAGE_VERSION ${YAWP_MAJOR_VERSION}.${YAWP_MINOR_VERSION}.${CPACK_PACKAGE_VERSION_PATCH})

		SET(CPACK_RPM_PACKAGE_NAME ${CMAKE_PROJECT_NAME})
		SET(CPACK_RPM_PACKAGE_SUMMARY "Plasma widget for KDE 4 that displays some weather information")
		SET(CPACK_RPM_PACKAGE_DESCRIPTION "Yet Another Weather Plasmoid that shows the current weather conditions and up to 4 days forecast depending on the chosen weather engine (ion). This package also contains two ions (accuweather and wunderground).")
		SET(CPACK_RPM_PACKAGE_GROUP "System/GUI/KDE")
		SET(CPACK_RPM_PACKAGE_REQUIRES "gettext, plasma-addons, kdebase4-runtime >= ${KDE_VERSION}, kdelibs4 >= ${KDE_VERSION}, libqt4 >= ${QT_VERSION_STRING}")
		SET(CPACK_RPM_PACKAGE_LICENSE "GPL-2.0+ and GPL-2.0")
		
	ENDIF( "${PACKAGE_TYPE}" STREQUAL "RPM" )
	
	INCLUDE(CPack)
ENDIF(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
##
##    End of Package Generator
##
############################################################

