set(muniwin_headers
src/about_dlg.h
src/addfiles_dlg.h
src/addfilter_dlg.h
src/addfolder_dlg.h
src/airmass_dlg.h
src/amasscurve_dlg.h
src/biascorr_dlg.h
src/callback.h
src/catfile_class.h
src/catfile_dlg.h
src/ccdfile_class.h
src/ccdfile_dlg.h
src/ccdtempcurve_dlg.h
src/chart_dlg.h
src/chooseaperture_dlg.h
src/choosestars_dlg.h
src/colorchooser_dlg.h
src/configuration.h
src/convert_dlg.h
src/darkcorr_dlg.h
src/editselections_dlg.h
src/export_aavso.h
src/export_baavss.h
src/export_dlgs.h
src/export_options.h
src/express_dlg.h
src/file_classes.h
src/file_dlg.h
src/findvariables_dlg.h
src/flatcorr_dlg.h
src/frameinfo_dlg.h
src/frameset_class.h
src/frame_dlg.h
src/graph_toolbox.h
src/helcor_dlg.h
src/helper_classes.h
src/helper_dlgs.h
src/image_class.h
src/infobox.h
src/info_dlg.h
src/jdconv_dlg.h
src/lightcurve_dlg.h
src/locations.h
src/main.h
src/main_dlg.h
src/makecatalogfile_dlg.h
src/masterbias_dlg.h
src/masterdark_dlg.h
src/masterflat_dlg.h
src/matching_dlg.h
src/matching_mt.h
src/matching_st.h
src/measurement.h
src/menubar.h
src/merge_dlg.h
src/messages_dlg.h
src/newfiles_dlg.h
src/objects.h
src/objects_dlg.h
src/object_dlg.h
src/objproperties_dlg.h
src/observer_dlg.h
src/output_dlg.h
src/photometry2_dlg.h
src/photometry_dlg.h
src/phot_class.h
src/phtfile_dlg.h
src/popup.h
src/preferences_dlg.h
src/preview.h
src/proc_classes.h
src/profile.h
src/profiles_dlg.h
src/profile_editor.h
src/progress_dlg.h
src/project.h
src/project_dlg.h
src/qphot.h
src/senddumpfiles.h
src/showheader_dlg.h
src/showwcsdata_dlg.h
src/sound.h
src/table_class.h
src/table_dlg.h
src/thumbnails_dlg.h
src/timecorr_dlg.h
src/toolbar.h
src/trackcurve_dlg.h
src/utils.h
src/varcat.h
src/varfind.h
src/varfindfile_dlg.h
)

set(muniwin_sources 
${muniwin_headers}
src/about_dlg.cpp
src/addfiles_dlg.cpp
src/addfilter_dlg.cpp
src/addfolder_dlg.cpp
src/airmass_dlg.cpp
src/amasscurve_dlg.cpp
src/biascorr_dlg.cpp
src/callback.cpp
src/catfile_class.cpp
src/catfile_dlg.cpp
src/ccdfile_class.cpp
src/ccdfile_dlg.cpp
src/ccdtempcurve_dlg.cpp
src/chart_dlg.cpp
src/chooseaperture_dlg.cpp
src/choosestars_dlg.cpp
src/colorchooser_dlg.cpp
src/configuration.cpp
src/convert_dlg.cpp
src/darkcorr_dlg.cpp
src/editselections_dlg.cpp
src/export_aavso.cpp
src/export_baavss.cpp
src/export_dlgs.cpp
src/export_options.cpp
src/express_dlg.cpp
src/file_classes.cpp
src/file_dlg.cpp
src/findvariables_dlg.cpp
src/flatcorr_dlg.cpp
src/frameinfo_dlg.cpp
src/frameset_class.cpp
src/frame_dlg.cpp
src/graph_toolbox.cpp
src/helcor_dlg.cpp
src/helper_classes.cpp
src/helper_dlgs.cpp
src/image_class.cpp
src/infobox.cpp
src/info_dlg.cpp
src/jdconv_dlg.cpp
src/lightcurve_dlg.cpp
src/locations.cpp
src/main.cpp
src/main_dlg.cpp
src/makecatalogfile_dlg.cpp
src/masterbias_dlg.cpp
src/masterdark_dlg.cpp
src/masterflat_dlg.cpp
src/matching_dlg.cpp
src/matching_mt.cpp
src/matching_st.cpp
src/measurement.cpp
src/menubar.cpp
src/merge_dlg.cpp
src/messages_dlg.cpp
src/newfiles_dlg.cpp
src/objects.cpp
src/objects_dlg.cpp
src/object_dlg.cpp
src/objproperties_dlg.cpp
src/observer_dlg.cpp
src/output_dlg.cpp
src/photometry2_dlg.cpp
src/photometry_dlg.cpp
src/phot_class.cpp
src/phtfile_dlg.cpp
src/popup.cpp
src/preferences_dlg.cpp
src/preview.cpp
src/proc_classes.cpp
src/profile.cpp
src/profiles_dlg.cpp
src/profile_editor.cpp
src/progress_dlg.cpp
src/project.cpp
src/project_dlg.cpp
src/qphot.cpp
src/showheader_dlg.cpp
src/showwcsdata_dlg.cpp
src/sound.cpp
src/table_class.cpp
src/table_dlg.cpp
src/thumbnails_dlg.cpp
src/timecorr_dlg.cpp
src/toolbar.cpp
src/trackcurve_dlg.cpp
src/utils.cpp
src/varcat.cpp
src/varfind.cpp
src/varfindfile_dlg.cpp
)

set(muniwin_libraries 
	libcmpack
	cmpack_widgets 
	manual 
	GTK2::gtk 
	cmpack_cfitsio
	cmpack_expat
	${M_LIBRARY}
)

add_subdirectory(widgets)

add_executable(muniwin WIN32 ${muniwin_sources})
set_target_properties(muniwin PROPERTIES FOLDER muniwin)
target_link_libraries(muniwin PUBLIC ${muniwin_libraries})

if(WIN32)
	configure_file(src/muniwin.rc.in muniwin.rc @ONLY)
	configure_file(src/muniwin.ico muniwin.ico COPYONLY)
	target_sources(muniwin PRIVATE muniwin.rc)
endif(WIN32)


if(MSVC)
	target_link_libraries(muniwin PRIVATE htmlhelp.lib winmm.lib)
	target_compile_options(muniwin PRIVATE /wd4311)
else(MSVC)
	target_compile_options(muniwin PRIVATE -Wdeprecated-declarations)
endif(MSVC)

file(GLOB_RECURSE resource_icons res/icons/*.png)
file(GLOB_RECURSE resource_sounds res/sounds/*.wav)

add_custom_target(resources ALL 
	COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/share/icons
	COMMAND ${CMAKE_COMMAND} -E copy_if_different ${resource_icons} ${CMAKE_BINARY_DIR}/share/icons
	COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/share/sounds
	COMMAND ${CMAKE_COMMAND} -E copy_if_different ${resource_sounds} ${CMAKE_BINARY_DIR}/share/sounds
	COMMENT "Copying resource files ..."
	SOURCES ${resource_files}
)
set_target_properties(resources PROPERTIES FOLDER utils)

# Install executable
install(TARGETS muniwin)

# Install PDBs
if (MSVC)
    install(FILES $<TARGET_PDB_FILE:muniwin> 
        CONFIGURATIONS "RelWithDebInfo" "Debug" 
        TYPE BIN
        OPTIONAL
    )
endif(MSVC)

# Install resources
if(UNIX AND NOT WIN32)
	install(FILES ${resource_icons} DESTINATION "${CMUNIPACK_INSTALL_DATADIR}/icons")
	install(FILES ${resource_sounds} DESTINATION "${CMUNIPACK_INSTALL_DATADIR}/sounds")
else(UNIX AND NOT WIN32)
	install(FILES ${resource_icons} DESTINATION "${CMAKE_INSTALL_DATADIR}/icons")
	install(FILES ${resource_sounds} DESTINATION "${CMAKE_INSTALL_DATADIR}/sounds")
endif(UNIX AND NOT WIN32)

if(WIN32)
	# GTK binaries
	set(gtk2_runtime_dependencies)
	foreach(f ${GTK2_LIBRARIES} expat.lib fontconfig.lib freetype.lib intl.lib pangowin32-1.0.lib png14.lib zlib1.lib)
		get_filename_component(fname ${f} NAME_WLE)
		find_file(gtk2_lib${fname}_dll NAMES lib${fname}-0.dll lib${fname}-1.dll lib${fname}-2.dll lib${fname}-3.dll lib${fname}-4.dll lib${fname}-5.dll 
			lib${fname}-6.dll lib${fname}-7.dll lib${fname}-8.dll lib${fname}-9.dll lib${fname}-10.dll lib${fname}-11.dll lib${fname}-12.dll 
			lib${fname}-13.dll lib${fname}-14.dll ${fname}.dll PATHS ${GTK2_ROOT}/bin)
		if (gtk2_lib${fname}_dll)
			list(APPEND gtk2_runtime_dependencies ${gtk2_lib${fname}_dll})
		else()
			message(STATUS "The Gtk shared library ${fname} was not found.")
		endif()
	endforeach()
	# Install dependencies
	install(FILES ${gtk2_runtime_dependencies} TYPE BIN)
	# Install Gtk configuration file
	install(FILES "${GTK2_ROOT}/share/themes/ms-windows/gtk-2.0/gtkrc" DESTINATION "${CMAKE_INSTALL_SYSCONFDIR}/gtk-2.0")
	# Find optional Gtk modules
	set(gtk2_runtime_modules)
	file(GLOB gtk2_runtime_modules "${GTK2_ROOT}/lib/gtk-2.0/2.10.0/engines/*.dll")
	install(FILES ${gtk2_runtime_modules} DESTINATION "${CMAKE_INSTALL_LIBDIR}/gtk-2.0/2.10.0/engines")
endif(WIN32)
