# ------------------------------------------------------------------------------
# Preliminary setup
# ------------------------------------------------------------------------------

cmake_minimum_required(VERSION 3.12)

# CMAKE_OSX_DEPLOYMENT_TARGET should be set prior to the first project() or
# enable_language() command invocation because it may influence configuration
# of the toolchain and flags.
# Also, see https://stackoverflow.com/questions/34208360/cmake-seems-to-ignore-cmake-osx-deployment-target

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
	set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14" CACHE STRING "Minimum OS X deployment version")
endif()

# ------------------------------------------------------------------------------
# Project
# ------------------------------------------------------------------------------

project(giada LANGUAGES CXX)

# ------------------------------------------------------------------------------
# Lists definition
#
# SOURCES - contains the source files
# PREPROCESSOR_DEFS - preprocessor definitions
# INCLUDE_DIRS - include directories (e.g. -I)
# COMPILER_OPTIONS - additional flags for the compiler
# LIBRARIES - external dependencies to link
# COMPILER_FEATURES - e.g. C++17
# TARGET_PROPERTIES - additional properties for the target 'giada'.
# ------------------------------------------------------------------------------

list(APPEND SOURCES
	src/main.cpp
	src/core/engine.cpp
	src/core/worker.cpp
	src/core/eventDispatcher.cpp
	src/core/midiDispatcher.cpp
	src/core/midiMapper.cpp
	src/core/midiEvent.cpp
	src/core/quantizer.cpp
	src/core/conf.cpp
	src/core/kernelAudio.cpp
	src/core/jackTransport.cpp
	src/core/mixerHandler.cpp
	src/core/sequencer.cpp
	src/core/metronome.cpp
	src/core/init.cpp
	src/core/wave.cpp
	src/core/waveFx.cpp
	src/core/kernelMidi.cpp
	src/core/graphics.cpp
	src/core/patch.cpp
	src/core/actions/actionRecorder.cpp
	src/core/actions/actions.cpp
	src/core/mixer.cpp
    src/core/synchronizer.cpp
	src/core/waveManager.cpp
    src/core/recorder.cpp
	src/core/midiLearnParam.cpp
	src/core/resampler.cpp
	src/core/plugins/pluginHost.cpp
	src/core/plugins/pluginManager.cpp
	src/core/plugins/plugin.cpp
	src/core/plugins/pluginState.cpp
	src/core/channels/sampleActionRecorder.cpp
	src/core/channels/midiActionRecorder.cpp
	src/core/channels/waveReader.cpp
	src/core/channels/midiController.cpp
	src/core/channels/sampleReactor.cpp
	src/core/channels/sampleAdvancer.cpp
	src/core/channels/samplePlayer.cpp
	src/core/channels/audioReceiver.cpp
	src/core/channels/midiLighter.cpp
	src/core/channels/midiLearner.cpp
	src/core/channels/midiSender.cpp
	src/core/channels/midiReceiver.cpp
	src/core/channels/channel.cpp
	src/core/channels/channelManager.cpp
	src/core/model/sequencer.cpp
	src/core/model/mixer.cpp
	src/core/model/recorder.cpp
	src/core/model/model.cpp
	src/core/model/storage.cpp
	src/core/idManager.cpp
	src/glue/events.cpp
	src/glue/main.cpp
	src/glue/io.cpp
	src/glue/storage.cpp
	src/glue/channel.cpp
	src/glue/plugin.cpp
	src/glue/recorder.cpp
	src/glue/sampleEditor.cpp
	src/glue/actionEditor.cpp
	src/glue/config.cpp
	src/glue/layout.cpp
	src/gui/ui.cpp
	src/gui/dialogs/window.cpp
	src/gui/dispatcher.cpp
	src/gui/updater.cpp
	src/gui/drawing.cpp
	src/gui/dialogs/progress.cpp
	src/gui/dialogs/keyGrabber.cpp
	src/gui/dialogs/about.cpp
	src/gui/dialogs/mainWindow.cpp
	src/gui/dialogs/beatsInput.cpp
	src/gui/dialogs/warnings.cpp
	src/gui/dialogs/bpmInput.cpp
	src/gui/dialogs/channelNameInput.cpp
	src/gui/dialogs/config.cpp
	src/gui/dialogs/pluginList.cpp
	src/gui/dialogs/pluginWindow.cpp
	src/gui/dialogs/sampleEditor.cpp
	src/gui/dialogs/pluginWindowGUI.cpp
	src/gui/dialogs/pluginChooser.cpp
	src/gui/dialogs/actionEditor/baseActionEditor.cpp
	src/gui/dialogs/actionEditor/sampleActionEditor.cpp
	src/gui/dialogs/actionEditor/midiActionEditor.cpp
	src/gui/dialogs/browser/browserBase.cpp
	src/gui/dialogs/browser/browserDir.cpp
	src/gui/dialogs/browser/browserLoad.cpp
	src/gui/dialogs/browser/browserSave.cpp
	src/gui/dialogs/midiIO/midiOutputBase.cpp
	src/gui/dialogs/midiIO/midiOutputSampleCh.cpp
	src/gui/dialogs/midiIO/midiOutputMidiCh.cpp
	src/gui/dialogs/midiIO/midiInputBase.cpp
	src/gui/dialogs/midiIO/midiInputChannel.cpp
	src/gui/dialogs/midiIO/midiInputMaster.cpp
	src/gui/elems/midiIO/midiLearner.cpp
	src/gui/elems/midiIO/midiLearnerPack.cpp
	src/gui/elems/browser.cpp
	src/gui/elems/soundMeter.cpp
	src/gui/elems/plugin/pluginBrowser.cpp
	src/gui/elems/plugin/pluginParameter.cpp
	src/gui/elems/plugin/pluginElement.cpp
	src/gui/elems/sampleEditor/waveform.cpp
	src/gui/elems/sampleEditor/waveTools.cpp
	src/gui/elems/sampleEditor/volumeTool.cpp
	src/gui/elems/sampleEditor/boostTool.cpp
	src/gui/elems/sampleEditor/panTool.cpp
	src/gui/elems/sampleEditor/pitchTool.cpp
	src/gui/elems/sampleEditor/rangeTool.cpp
	src/gui/elems/sampleEditor/shiftTool.cpp
	src/gui/elems/actionEditor/baseActionEditor.cpp
	src/gui/elems/actionEditor/baseAction.cpp
	src/gui/elems/actionEditor/envelopeEditor.cpp
	src/gui/elems/actionEditor/velocityEditor.cpp
	src/gui/elems/actionEditor/envelopePoint.cpp
	src/gui/elems/actionEditor/pianoRoll.cpp
	src/gui/elems/actionEditor/pianoItem.cpp
	src/gui/elems/actionEditor/sampleActionEditor.cpp
	src/gui/elems/actionEditor/sampleAction.cpp
	src/gui/elems/actionEditor/gridTool.cpp
	src/gui/elems/actionEditor/splitScroll.cpp
	src/gui/elems/mainWindow/mainIO.cpp
	src/gui/elems/mainWindow/mainMenu.cpp
	src/gui/elems/mainWindow/mainTimer.cpp
	src/gui/elems/mainWindow/mainTransport.cpp
	src/gui/elems/mainWindow/sequencer.cpp
	src/gui/elems/mainWindow/keyboard/channelMode.cpp
	src/gui/elems/mainWindow/keyboard/channelButton.cpp
	src/gui/elems/mainWindow/keyboard/channelStatus.cpp
	src/gui/elems/mainWindow/keyboard/keyboard.cpp
	src/gui/elems/mainWindow/keyboard/column.cpp
	src/gui/elems/mainWindow/keyboard/sampleChannel.cpp
	src/gui/elems/mainWindow/keyboard/midiChannel.cpp
	src/gui/elems/mainWindow/keyboard/channel.cpp
	src/gui/elems/mainWindow/keyboard/sampleChannelButton.cpp
	src/gui/elems/mainWindow/keyboard/midiChannelButton.cpp
	src/gui/elems/config/tabMisc.cpp
	src/gui/elems/config/tabMidi.cpp
	src/gui/elems/config/tabAudio.cpp
	src/gui/elems/config/tabBehaviors.cpp
	src/gui/elems/config/tabPlugins.cpp
	src/gui/elems/basics/scroll.cpp
	src/gui/elems/basics/pack.cpp
	src/gui/elems/basics/group.cpp
	src/gui/elems/basics/scrollPack.cpp
	src/gui/elems/basics/boxtypes.cpp
	src/gui/elems/basics/statusButton.cpp
	src/gui/elems/basics/button.cpp
	src/gui/elems/basics/resizerBar.cpp
	src/gui/elems/basics/input.cpp
	src/gui/elems/basics/liquidScroll.cpp
	src/gui/elems/basics/choice.cpp
	src/gui/elems/basics/dial.cpp
	src/gui/elems/basics/box.cpp
	src/gui/elems/basics/slider.cpp
	src/gui/elems/basics/progress.cpp
	src/gui/elems/basics/check.cpp
	src/gui/elems/basics/split.cpp
	src/utils/log.cpp
	src/utils/time.cpp
	src/utils/math.cpp
	src/utils/gui.cpp
	src/utils/fs.cpp
	src/utils/ver.cpp
	src/utils/string.cpp
	src/deps/rtaudio/RtAudio.cpp
	src/deps/mcl-audio-buffer/src/audioBuffer.cpp)

list(APPEND PREPROCESSOR_DEFS)
list(APPEND INCLUDE_DIRS
	${CMAKE_SOURCE_DIR}
	${CMAKE_SOURCE_DIR}/src)
list(APPEND COMPILER_OPTIONS)
list(APPEND LIBRARIES)
list(APPEND COMPILER_FEATURES cxx_std_17)
list(APPEND TARGET_PROPERTIES)

# ------------------------------------------------------------------------------
# Detect OS
# ------------------------------------------------------------------------------

if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
	set(OS_LINUX 1)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
	set(OS_WINDOWS 1)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
	set(OS_MACOS 1)
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
	set(OS_FREEBSD 1)
else()
	message(FATAL_ERROR "Unsupported platform '${CMAKE_SYSTEM_NAME}', quitting.")
endif()

# ------------------------------------------------------------------------------
# Compiler warnings
# ------------------------------------------------------------------------------

if(DEFINED OS_WINDOWS)
	list(APPEND COMPILER_OPTIONS /W4 /bigobj /external:anglebrackets /external:W0)
else()
	list(APPEND COMPILER_OPTIONS -Wall -Wextra -Wpedantic)
endif()

# ------------------------------------------------------------------------------
# Options
# ------------------------------------------------------------------------------

option(WITH_VST2 "Enable VST2 support." OFF)
option(WITH_VST3 "Enable VST3 support." OFF)
option(WITH_TESTS "Include the test suite." OFF)

if(DEFINED OS_LINUX)
	option(WITH_ALSA "Enable ALSA support (Linux only)." ON)
	option(WITH_PULSE "Enable PulseAudio support (Linux only)." ON)
	option(WITH_JACK "Enable JACK support (Linux only)." ON)
endif()

if(WITH_TESTS)
	list(APPEND PREPROCESSOR_DEFS 
		WITH_TESTS
		TEST_RESOURCES_DIR="${CMAKE_SOURCE_DIR}/tests/resources/")
endif()

if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
	list(APPEND PREPROCESSOR_DEFS NDEBUG)
endif()

# ------------------------------------------------------------------------------
# Dependencies
# ------------------------------------------------------------------------------

# Threads (system)

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
list(APPEND LIBRARIES Threads::Threads)

# pkg-config/pkgconf, required to find some external dependencies on some
# platforms
find_package(PkgConfig)

# RtMidi

find_package(RtMidi CONFIG)
if (RtMidi_FOUND)
	list(APPEND LIBRARIES RtMidi::rtmidi)
	message("RtMidi library found in " ${RtMidi_DIR})
elseif (PkgConfig_FOUND)
	pkg_check_modules(RtMidi IMPORTED_TARGET rtmidi)
	if (RtMidi_FOUND)
		list(APPEND LIBRARIES PkgConfig::RtMidi)
		message("RtMidi library found")
	endif()
endif()

if (NOT RtMidi_FOUND)
	# Fallback to find_library mode (in case rtmidi is too old). 
	find_library(LIBRARY_RTMIDI NAMES rtmidi)
	list(APPEND LIBRARIES ${LIBRARY_RTMIDI})

	if (NOT LIBRARY_RTMIDI)
		message(FATAL_ERROR "Can't find RtMidi, aborting.")
	endif()

	# RtMidi header path may vary across OSes, so a fix is needed.
	# TODO - Find a way to avoid this additional step

	find_path(LIBRARY_RTMIDI_INCLUDE_DIR RtMidi.h PATH_SUFFIXES rtmidi)
	list(APPEND INCLUDE_DIRS ${LIBRARY_RTMIDI_INCLUDE_DIR})
	message("RtMidi library found in " ${RtMidi_DIR})
endif()

# FLTK 

set(FLTK_SKIP_FLUID TRUE)  # Don't search for FLTK's fluid
set(FLTK_SKIP_OPENGL TRUE) # Don't search for FLTK's OpenGL
find_package(FLTK REQUIRED NO_MODULE)
list(APPEND LIBRARIES fltk)
list(APPEND INCLUDE_DIRS ${FLTK_INCLUDE_DIRS})
message("FLTK library found in " ${FLTK_DIR})

# Libsndfile

find_package(SndFile CONFIG)
if (SndFile_FOUND)
	list(APPEND LIBRARIES SndFile::sndfile)
	message("Libsndfile library found in " ${SndFile_DIR})
elseif(PkgConfig_FOUND)
	pkg_check_modules(SndFile IMPORTED_TARGET sndfile)
	if (SndFile_FOUND)
		list(APPEND LIBRARIES PkgConfig::SndFile)
		message("Libsndfile library found")
	endif()	
endif()

if (NOT SndFile_FOUND)
	# Fallback to find_library mode (in case libsndfile is too old). 
	find_library(LIBRARY_SNDFILE NAMES sndfile libsndfile libsndfile-1)
	
	if (NOT LIBRARY_SNDFILE)
		message(FATAL_ERROR "Can't find libsndfile, aborting.")
	endif()

	list(APPEND LIBRARIES ${LIBRARY_SNDFILE})
	message("Libsndfile library found in " ${LIBRARY_SNDFILE})

	# Find optional dependencies.

	find_library(LIBRARY_FLAC NAMES flac FLAC)
	find_library(LIBRARY_OGG NAMES ogg)
	find_library(LIBRARY_OPUS NAMES opus libopus)
	find_library(LIBRARY_VORBIS NAMES vorbis)
	find_library(LIBRARY_VORBISENC NAMES vorbisenc)

	if(LIBRARY_FLAC)
		list(APPEND LIBRARIES ${LIBRARY_FLAC})
	endif()
	if(LIBRARY_OGG)
		list(APPEND LIBRARIES ${LIBRARY_OGG})
	endif()
	if(LIBRARY_OPUS)
		list(APPEND LIBRARIES ${LIBRARY_OPUS})
	endif()
	if(LIBRARY_VORBIS)
		list(APPEND LIBRARIES ${LIBRARY_VORBIS})
	endif()
	if(LIBRARY_VORBISENC)
		list(APPEND LIBRARIES ${LIBRARY_VORBISENC})
	endif()	
endif()

# Libsamplerate

find_package(SampleRate CONFIG)
if (SampleRate_FOUND)
	list(APPEND LIBRARIES SampleRate::samplerate)
	message("Libsamplerate library found in " ${SampleRate_DIR})
else() 
	# Fallback to find_library mode (in case Libsamplerate is too old). 
	find_library(LIBRARY_SAMPLERATE 
	    NAMES samplerate libsamplerate libsamplerate-0 liblibsamplerate-0
	    PATHS ${_VCPKG_ROOT_DIR}/installed/${VCPKG_TARGET_TRIPLET}
		REQUIRED)
	list(APPEND LIBRARIES ${LIBRARY_SAMPLERATE})
	message("Libsamplerate library found in " ${LIBRARY_SAMPLERATE})
endif()

# Catch (if tests enabled)

if (WITH_TESTS)

	find_package(Catch2 CONFIG REQUIRED)
	list(APPEND LIBRARIES Catch2::Catch2)
	message("Catch2 library found in " ${Catch2_DIR})

endif()

# ------------------------------------------------------------------------------
# Conditional checks for different platforms.
# ------------------------------------------------------------------------------

if(DEFINED OS_LINUX)

	find_package(X11 REQUIRED)
	find_package(ALSA REQUIRED)
	find_library(LIBRARY_PULSE NAMES pulse REQUIRED)
	find_library(LIBRARY_PULSE_SIMPLE NAMES pulse-simple REQUIRED)
	find_library(LIBRARY_FONTCONFIG NAMES fontconfig REQUIRED)
	pkg_check_modules(JACK REQUIRED jack)
	list(APPEND LIBRARIES
		${X11_LIBRARIES} ${X11_Xrender_LIB} ${X11_Xft_LIB} ${X11_Xfixes_LIB}
		${X11_Xinerama_LIB} ${X11_Xcursor_LIB} ${X11_Xpm_LIB} ${LIBRARY_PULSE}
		${LIBRARY_PULSE_SIMPLE} ${LIBRARY_FONTCONFIG} ${JACK_LDFLAGS}
		${CMAKE_DL_LIBS} ${ALSA_LIBRARIES} pthread stdc++fs)

	if (WITH_ALSA)
		list(APPEND PREPROCESSOR_DEFS __LINUX_ALSA__)
	endif()
	if (WITH_PULSE)
		list(APPEND PREPROCESSOR_DEFS __LINUX_PULSE__)
	endif()
	if (WITH_JACK)
		list(APPEND PREPROCESSOR_DEFS WITH_AUDIO_JACK __UNIX_JACK__)
	endif()

elseif(DEFINED OS_WINDOWS)

	list(APPEND LIBRARIES dsound)

	list(APPEND SOURCES
		src/deps/rtaudio/include/asio.h
		src/deps/rtaudio/include/asio.cpp
		src/deps/rtaudio/include/asiosys.h
		src/deps/rtaudio/include/asiolist.h
		src/deps/rtaudio/include/asiolist.cpp
		src/deps/rtaudio/include/asiodrivers.h
		src/deps/rtaudio/include/asiodrivers.cpp
		src/deps/rtaudio/include/iasiothiscallresolver.h
		src/deps/rtaudio/include/iasiothiscallresolver.cpp
		src/ext/resource.rc)

	list(APPEND INCLUDE_DIRS
		src/deps/rtaudio/include)

	list(APPEND PREPROCESSOR_DEFS
		__WINDOWS_ASIO__
		__WINDOWS_WASAPI__
		__WINDOWS_DS__)

elseif(DEFINED OS_MACOS)

	find_library(CORE_AUDIO_LIBRARY CoreAudio REQUIRED)
	find_library(CORE_MIDI_LIBRARY CoreMIDI REQUIRED)
	find_library(COCOA_LIBRARY Cocoa REQUIRED)
	find_library(CARBON_LIBRARY Carbon REQUIRED)
	find_library(CORE_FOUNDATION_LIBRARY CoreFoundation REQUIRED)
	find_library(ACCELERATE_LIBRARY Accelerate REQUIRED)
	find_library(WEBKIT_LIBRARY WebKit REQUIRED)
	find_library(QUARZ_CORE_LIBRARY QuartzCore REQUIRED)
	find_library(IOKIT_LIBRARY IOKit REQUIRED)
	list(APPEND LIBRARIES
		${CORE_AUDIO_LIBRARY} ${CORE_MIDI_LIBRARY} ${COCOA_LIBRARY}
		${CARBON_LIBRARY} ${CORE_FOUNDATION_LIBRARY} ${ACCELERATE_LIBRARY}
		${WEBKIT_LIBRARY} ${QUARZ_CORE_LIBRARY} ${IOKIT_LIBRARY})

	list(APPEND SOURCES
		src/utils/cocoa.mm
		src/utils/cocoa.h)

	# TODO: why??
	list(APPEND INCLUDE_DIRS
		"/usr/local/include")

	list(APPEND PREPROCESSOR_DEFS 
		__MACOSX_CORE__)

elseif (DEFINED OS_FREEBSD)

	find_package(X11 REQUIRED)
	find_library(LIBRARY_PULSE NAMES pulse REQUIRED)
	find_library(LIBRARY_PULSE_SIMPLE NAMES pulse-simple REQUIRED)
	find_library(LIBRARY_FONTCONFIG NAMES fontconfig REQUIRED)
	find_library(LIBRARY_JACK NAMES jack REQUIRED)
	list(APPEND LIBRARIES
		${X11_LIBRARIES} ${X11_Xrender_LIB} ${X11_Xft_LIB} ${X11_Xfixes_LIB}
		${X11_Xinerama_LIB} ${X11_Xcursor_LIB} ${X11_Xpm_LIB} ${LIBRARY_PULSE}
		${LIBRARY_PULSE_SIMPLE} ${LIBRARY_FONTCONFIG} ${LIBRARY_JACK}
		${CMAKE_DL_LIBS} pthread)
	
	list(APPEND PREPROCESSOR_DEFS
		WITH_AUDIO_JACK
		__LINUX_PULSE__
		__UNIX_JACK__)

endif()

# ------------------------------------------------------------------------------
# Extra parameters if compiled with VST.
# ------------------------------------------------------------------------------

if(WITH_VST2 OR WITH_VST3)

	list(APPEND SOURCES
		src/deps/juce/modules/juce_audio_basics/juce_audio_basics.cpp
		src/deps/juce/modules/juce_audio_processors/juce_audio_processors.cpp
		src/deps/juce/modules/juce_core/juce_core.cpp
		src/deps/juce/modules/juce_data_structures/juce_data_structures.cpp
		src/deps/juce/modules/juce_events/juce_events.cpp
		src/deps/juce/modules/juce_graphics/juce_graphics.cpp
		src/deps/juce/modules/juce_gui_basics/juce_gui_basics.cpp
		src/deps/juce/modules/juce_gui_extra/juce_gui_extra.cpp)

	list(APPEND INCLUDE_DIRS
		${CMAKE_SOURCE_DIR}/src/deps/juce/modules
		${CMAKE_SOURCE_DIR}/src/deps/vst3sdk)

	if(DEFINED OS_LINUX)
		find_package(Freetype REQUIRED)
		list(APPEND LIBRARIES ${FREETYPE_LIBRARIES})
		list(APPEND INCLUDE_DIRS ${FREETYPE_INCLUDE_DIRS})
	endif()

	list(APPEND PREPROCESSOR_DEFS
		WITH_VST
		JUCE_DEBUG=$<BOOL:$<CONFIG:Debug>>
		JUCE_MODAL_LOOPS_PERMITTED=1
		JUCE_GLOBAL_MODULE_SETTINGS_INCLUDED=1
		JUCE_MODULE_AVAILABLE_juce_gui_basics=1
		JUCE_STANDALONE_APPLICATION=1
		JUCE_PLUGINHOST_AU=0
		JUCE_WEB_BROWSER=0
		JUCE_USE_CURL=0)

	if(WITH_VST2)
		list(APPEND PREPROCESSOR_DEFS
			WITH_VST2
			JUCE_PLUGINHOST_VST=1)
	endif()
	if(WITH_VST3)
		list(APPEND PREPROCESSOR_DEFS
			WITH_VST3
			JUCE_PLUGINHOST_VST3=1)
	endif()

endif()

# ------------------------------------------------------------------------------
# Finalize 'giada' target (main executable).
# ------------------------------------------------------------------------------

add_executable(giada)
target_compile_features(giada PRIVATE ${COMPILER_FEATURES})
target_sources(giada PRIVATE ${SOURCES})
target_compile_definitions(giada PRIVATE ${PREPROCESSOR_DEFS})
target_include_directories(giada PRIVATE ${INCLUDE_DIRS})
target_link_libraries(giada PRIVATE ${LIBRARIES})
target_compile_options(giada PRIVATE ${COMPILER_OPTIONS})

# ------------------------------------------------------------------------------
# Install rules
# ------------------------------------------------------------------------------

if(DEFINED OS_LINUX)
	include(GNUInstallDirs)
	install(TARGETS giada DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR})
	install(FILES ${CMAKE_SOURCE_DIR}/extras/com.giadamusic.Giada.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications)
	install(FILES ${CMAKE_SOURCE_DIR}/extras/com.giadamusic.Giada.metainfo.xml DESTINATION ${CMAKE_INSTALL_PREFIX}/share/metainfo)
	install(FILES ${CMAKE_SOURCE_DIR}/extras/giada-logo.svg RENAME com.giadamusic.Giada.svg DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/scalable/apps)
endif()

# ------------------------------------------------------------------------------
# Extra
# ------------------------------------------------------------------------------

# TODO - move these into the 'if [OS]' conditionals (needs smarter list first)

if(DEFINED OS_WINDOWS)

	# Enable static linking of the MSVC runtime library on Windows
	
	set_target_properties(giada PROPERTIES
		MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

elseif(DEFINED OS_MACOS)

	# Enable hardened runtime:
	# https://developer.apple.com/documentation/security/hardened_runtime
	
	set_target_properties(giada PROPERTIES
		XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME YES)

endif()
