include (FindPkgConfig)
if(ENABLE_GTK4)
	pkg_check_modules (GTKLIBS REQUIRED gtk4)
	set (GTK4 1)
else()
	pkg_check_modules (GTKLIBS REQUIRED gtk+-3.0)
endif()
if(ENABLE_THUNARX)
	pkg_check_modules (GTK3LIBS REQUIRED gtk+-3.0)
	pkg_check_modules (THUNARX REQUIRED thunarx-3)
endif()

set (LOCALE_DIR ${CMAKE_INSTALL_PREFIX}/share/locale)
configure_file (config.h.cmake config.h)
include_directories (${CMAKE_BINARY_DIR}/src)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")

add_executable (gcryfolder-password-prompt gcryfolder-password-prompt.c)
target_include_directories (gcryfolder-password-prompt PRIVATE ${GTKLIBS_INCLUDE_DIRS}) 
target_link_libraries (gcryfolder-password-prompt ${GTKLIBS_LDFLAGS})

if(ENABLE_THUNARX)
	add_library (thunar-encryption STATIC thunar-encryption.c)
	target_include_directories (thunar-encryption PRIVATE ${GTK3LIBS_INCLUDE_DIRS} PUBLIC ${THUNARX_INCLUDE_DIRS})
	target_link_libraries (thunar-encryption ${GTK3LIBS_LDFLAGS} ${THUNARX_LDFLAGS})
	add_library (thunar-encryption-plugin SHARED thunar-encryption-plugin.c)
	target_link_libraries (thunar-encryption-plugin thunar-encryption ${GTK3LIBS_LDFLAGS} ${THUNARX_LDFLAGS})
endif()

install (TARGETS gcryfolder-password-prompt DESTINATION bin)
install (PROGRAMS gcryfolder.sh DESTINATION bin)
install (PROGRAMS umount.fuse DESTINATION /bin) #must be in the same path as /bin/umount
if(NOT ENABLE_THUNARX)
	install (FILES gcryfolder.desktop DESTINATION share/applications)
endif()
install (FILES encripted-folder.svg DESTINATION share/icons/hicolor/scalable/apps/)
install (FILES encripted-folder-new.svg DESTINATION share/icons/hicolor/scalable/apps/)
if(ENABLE_THUNARX)
	install (TARGETS thunar-encryption-plugin DESTINATION ${CMAKE_INSTALL_LIBDIR}/thunarx-3)
endif()

add_custom_target (uninstall)
add_custom_command (TARGET uninstall COMMAND xargs rm -f < ${CMAKE_BINARY_DIR}/install_manifest.txt)
add_custom_command (TARGET uninstall COMMAND rmdir ${CMAKE_INSTALL_PREFIX}/doc/${PROJECT_NAME}-${PROJECT_VERSION})
if(ENABLE_THUNARX)
	add_custom_command (TARGET uninstall COMMAND rmdir --ignore-fail-on-non-empty ${CMAKE_INSTALL_PREFIX}/lib/thunarx-3)
endif()
