include (FindPkgConfig)

if (DETECTION STREQUAL "UDEV")
	pkg_check_modules (MAINLIBS REQUIRED gtk+-2.0)
	set_source_files_properties (${PROJECT_NAME}.c PROPERTIES COMPILE_FLAGS -DUDEV_DETECTION)
	message (STATUS "Using UDEV for device and media detection.")
	find_path (UDEV_ROOT cdrom_id /lib/udev /usr/lib/udev)
	message (STATUS "Udev tools root directory: " ${UDEV_ROOT})
elseif (DETECTION STREQUAL "LIBCDIO")
	pkg_check_modules (MAINLIBS REQUIRED gtk+-2.0 libcdio)
	set_source_files_properties (${PROJECT_NAME}.c PROPERTIES COMPILE_FLAGS -DLIBCDIO_DETECTION)
	message (STATUS "Using LIBCDIO for device and media detection.")	
	pkg_check_modules (DETECTIONLIBS REQUIRED libcdio glib-2.0)
	add_executable (simpleburn-media-detection simpleburn-cdio-media-detection.c)
	target_link_libraries (simpleburn-media-detection ${DETECTIONLIBS_LDFLAGS} -lm) #"-lm": if not detected, but won't hurt
	install (TARGETS simpleburn-media-detection DESTINATION bin)
endif (DETECTION STREQUAL "UDEV")

if (DEBUG)
	get_source_file_property(CFLAGS ${PROJECT_NAME}.c COMPILE_FLAGS)
	if (CFLAGS STREQUAL NOTFOUND)
		set_source_files_properties (${PROJECT_NAME}.c PROPERTIES COMPILE_FLAGS -DDEBUG)
	else (CFLAGS STREQUAL NOTFOUND)
		set_source_files_properties (${PROJECT_NAME}.c PROPERTIES COMPILE_FLAGS "${CFLAGS} -DDEBUG")
	endif (CFLAGS STREQUAL NOTFOUND)
	message (STATUS "Debug informations are enabled.")
endif (DEBUG)

if (ALLOW_DEVICES_SYMLINKS)
	get_source_file_property(CFLAGS ${PROJECT_NAME}.c COMPILE_FLAGS)
	set_source_files_properties (${PROJECT_NAME}.c PROPERTIES COMPILE_FLAGS "${CFLAGS} -DALLOW_DEVICES_SYMLINKS")
	message (STATUS "Symbolic links for devices are enabled.")
endif (ALLOW_DEVICES_SYMLINKS)

set (LOCALE_DIR ${CMAKE_INSTALL_PREFIX}/share/locale)
set (UI_FILE ${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/${PROJECT_NAME}.ui)
set (APP_ICON ${CMAKE_INSTALL_PREFIX}/share/pixmaps/${PROJECT_NAME}.png)
configure_file (config.h.cmake config.h)
include_directories (${${PROJECT_NAME}_BINARY_DIR}/src)

add_executable (${PROJECT_NAME} ${PROJECT_NAME}.c)
include_directories (${MAINLIBS_INCLUDE_DIRS}) 
target_link_libraries (${PROJECT_NAME} ${MAINLIBS_LDFLAGS} -lm)

install (TARGETS ${PROJECT_NAME} DESTINATION bin)
install (FILES ${PROJECT_NAME}.ui DESTINATION share/${PROJECT_NAME})
install (FILES ${PROJECT_NAME}.desktop DESTINATION share/applications)
install (FILES ${PROJECT_NAME}.png DESTINATION share/pixmaps)

add_executable (simpleburn-gauges simpleburn-gauges.c)
install (TARGETS simpleburn-gauges DESTINATION bin)
