code:
# FindFFTW.cmake - Try to find FFTW3
# Copyright (c) 2018 Lukas W <lukaswhl/at/gmail.com>
# This file is MIT licensed.
# See http://opensource.org/licenses/MIT

# Try pkgconfig for hints
find_package(PkgConfig QUIET)

if(NOT FFTW_FIND_COMPONENTS)
	set(FFTW_FIND_COMPONENTS fftw3f fftw3 fftwl)
endif()

if(PKG_CONFIG_FOUND)
	pkg_check_modules(FFTW_PKG QUIET fftw>=3.0.0)
	pkg_check_modules(FFTW3_PKG QUIET fftw3>=3.0.0)
endif()

find_path(FFTW_INCLUDE_DIR
	NAMES fftw3.h
	PATHS ${FFTW_PKG_INCLUDE_DIRS} ${FFTW3_PKG_INCLUDE_DIRS}
)

set(check_list)

foreach(comp ${FFTW_FIND_COMPONENTS})
	string(TOUPPER ${comp} COMP)
	if(PKG_CONFIG_FOUND)
		pkg_check_modules(${COMP}_PKG QUIET ${comp}>=3.0.0)
	endif()

	find_library(${COMP}_LIBRARY
		NAMES ${comp}
		PATHS ${comp}_PKG_LIBRARY_DIRS
 	)
 	list(APPEND check_list ${COMP}_LIBRARY)

	set(${COMP}_LIBRARIES ${${COMP}_LIBRARY} CACHE FILEPATH "${COMP} library path")
	set(${COMP}_INCLUDE_DIRS ${FFTW_INCLUDE_DIR} CACHE PATH "${COMP} include path")
	mark_as_advanced(${COMP}_LIBRARIES ${COMP}_INCLUDE_DIRS)
endforeach()

find_package(PackageHandleStandardArgs)
find_package_handle_standard_args(FFTW DEFAULT_MSG FFTW_INCLUDE_DIR ${check_list})

set(FFTW_INCLUDE_DIRS ${FFTW_INCLUDE_DIR})

mark_as_advanced(FFTW_LIBRARY FFTW_LIBRARIES FFTW_INCLUDE_DIR FFTW_INCLUDE_DIRS ${check_list})


code:
# - Try to find LAME
# Once done this will define
#
# LAME_FOUND - system has liblame
# LAME_INCLUDE_DIRS - the liblame include directory
# LAME_LIBRARIES - The liblame libraries

find_path(LAME_INCLUDE_DIRS lame/lame.h)
find_library(LAME_LIBRARIES mp3lame)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Lame DEFAULT_MSG LAME_INCLUDE_DIRS LAME_LIBRARIES)

list(APPEND LAME_DEFINITIONS -DHAVE_LIBMP3LAME=1)

mark_as_advanced(LAME_INCLUDE_DIRS LAME_LIBRARIES LAME_DEFINITIONS)

repo_name: CYBERDEViL/LMMS

license: mit


code:
# - Try to find the OggVorbis libraries
# Once done this will define
#
#  OGGVORBIS_FOUND - system has OggVorbis
#  OGGVORBIS_VERSION - set either to 1 or 2
#  OGGVORBIS_INCLUDE_DIR - the OggVorbis include directory
#  OGGVORBIS_LIBRARIES - The libraries needed to use OggVorbis
#  OGG_LIBRARY         - The Ogg library
#  VORBIS_LIBRARY      - The Vorbis library
#  VORBISFILE_LIBRARY  - The VorbisFile library
#  VORBISENC_LIBRARY   - The VorbisEnc library

# Copyright (c) 2006, Richard Laerkaeng, <richard@goteborg.utfors.se>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.

include (CheckLibraryExists)

find_path(VORBIS_INCLUDE_DIR vorbis/vorbisfile.h)
find_path(OGG_INCLUDE_DIR ogg/ogg.h)

find_library(OGG_LIBRARY NAMES ogg)
find_library(VORBIS_LIBRARY NAMES vorbis)
find_library(VORBISFILE_LIBRARY NAMES vorbisfile)
find_library(VORBISENC_LIBRARY NAMES vorbisenc)

if (VORBIS_INCLUDE_DIR AND VORBIS_LIBRARY AND VORBISFILE_LIBRARY AND VORBISENC_LIBRARY)
   set(OGGVORBIS_FOUND TRUE)

   set(OGGVORBIS_LIBRARIES ${OGG_LIBRARY} ${VORBIS_LIBRARY} ${VORBISFILE_LIBRARY} ${VORBISENC_LIBRARY})

   set(_CMAKE_REQUIRED_LIBRARIES_TMP ${CMAKE_REQUIRED_LIBRARIES})
   set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${OGGVORBIS_LIBRARIES})
   check_library_exists(vorbis vorbis_bitrate_addblock "" HAVE_LIBVORBISENC2)
   set(CMAKE_REQUIRED_LIBRARIES ${_CMAKE_REQUIRED_LIBRARIES_TMP})

   if (HAVE_LIBVORBISENC2)
      set (OGGVORBIS_VERSION 2)
   else (HAVE_LIBVORBISENC2)
      set (OGGVORBIS_VERSION 1)
   endif (HAVE_LIBVORBISENC2)

else (VORBIS_INCLUDE_DIR AND VORBIS_LIBRARY AND VORBISFILE_LIBRARY AND VORBISENC_LIBRARY)
   set (OGGVORBIS_VERSION)
   set(OGGVORBIS_FOUND FALSE)
endif (VORBIS_INCLUDE_DIR AND VORBIS_LIBRARY AND VORBISFILE_LIBRARY AND VORBISENC_LIBRARY)

if (OGGVORBIS_FOUND)
   if (NOT OggVorbis_FIND_QUIETLY)
      message(STATUS "Found OggVorbis: ${OGGVORBIS_LIBRARIES}")
   endif (NOT OggVorbis_FIND_QUIETLY)
else (OGGVORBIS_FOUND)
   if (OggVorbis_FIND_REQUIRED)
      message(FATAL_ERROR "Could NOT find OggVorbis libraries")
   endif (OggVorbis_FIND_REQUIRED)
   if (NOT OggVorbis_FIND_QUITELY)
      message(STATUS "Could NOT find OggVorbis libraries")
   endif (NOT OggVorbis_FIND_QUITELY)
endif (OGGVORBIS_FOUND)

#check_include_files(vorbis/vorbisfile.h HAVE_VORBISFILE_H)
#check_library_exists(ogg ogg_page_version "" HAVE_LIBOGG)
#check_library_exists(vorbis vorbis_info_init "" HAVE_LIBVORBIS)
#check_library_exists(vorbisfile ov_open "" HAVE_LIBVORBISFILE)
#check_library_exists(vorbisenc vorbis_info_clear "" HAVE_LIBVORBISENC)
#check_library_exists(vorbis vorbis_bitrate_addblock "" HAVE_LIBVORBISENC2)

#if (HAVE_LIBOGG AND HAVE_VORBISFILE_H AND HAVE_LIBVORBIS AND HAVE_LIBVORBISFILE AND HAVE_LIBVORBISENC)
#    message(STATUS "Ogg/Vorbis found")
#    set (VORBIS_LIBS "-lvorbis -logg")
#    set (VORBISFILE_LIBS "-lvorbisfile")
#    set (VORBISENC_LIBS "-lvorbisenc")
#    set (OGGVORBIS_FOUND TRUE)
#    if (HAVE_LIBVORBISENC2)
#        set (HAVE_VORBIS 2)
#    else (HAVE_LIBVORBISENC2)
#        set (HAVE_VORBIS 1)
#    endif (HAVE_LIBVORBISENC2)
#else (HAVE_LIBOGG AND HAVE_VORBISFILE_H AND HAVE_LIBVORBIS AND HAVE_LIBVORBISFILE AND HAVE_LIBVORBISENC)
#    message(STATUS "Ogg/Vorbis not found")
#endif (HAVE_LIBOGG AND HAVE_VORBISFILE_H AND HAVE_LIBVORBIS AND HAVE_LIBVORBISFILE AND HAVE_LIBVORBISENC)


code:
# - Try to find Portaudio
# Once done this will define
#
#  PORTAUDIO_FOUND - system has Portaudio
#  PORTAUDIO_INCLUDE_DIRS - the Portaudio include directory
#  PORTAUDIO_LIBRARIES - Link these to use Portaudio
#  PORTAUDIO_DEFINITIONS - Compiler switches required for using Portaudio
#
#  Copyright (c) 2006 Andreas Schneider <mail@cynapses.org>
#
# Redistribution and use is allowed according to the terms of the New BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#

if (PORTAUDIO_LIBRARIES AND PORTAUDIO_INCLUDE_DIRS)
  # in cache already
  set(PORTAUDIO_FOUND TRUE)
else (PORTAUDIO_LIBRARIES AND PORTAUDIO_INCLUDE_DIRS)
   include(FindPkgConfig)
   pkg_check_modules(PORTAUDIO portaudio-2.0)
  if (PORTAUDIO_FOUND)
    if (NOT Portaudio_FIND_QUIETLY)
      message(STATUS "Found Portaudio: ${PORTAUDIO_LIBRARIES}")
    endif (NOT Portaudio_FIND_QUIETLY)
  else (PORTAUDIO_FOUND)
    if (Portaudio_FIND_REQUIRED)
      message(FATAL_ERROR "Could not find Portaudio")
    endif (Portaudio_FIND_REQUIRED)
  endif (PORTAUDIO_FOUND)

  # show the PORTAUDIO_INCLUDE_DIRS and PORTAUDIO_LIBRARIES variables only in the advanced view
  mark_as_advanced(PORTAUDIO_INCLUDE_DIRS PORTAUDIO_LIBRARIES)

endif (PORTAUDIO_LIBRARIES AND PORTAUDIO_INCLUDE_DIRS)


code:
# - Try to find PulseAudioSimple
# Once done this will define
#
#  PULSEAUDIO_FOUND - system has PulseAudioSimple
#  PULSEAUDIO_INCLUDE_DIR - the PulseAudioSimple include directory
#  PULSEAUDIO_LIBRARIES - the libraries needed to use PulseAudioSimple
#  PULSEAUDIO_DEFINITIONS - Compiler switches required for using PulseAudioSimple
#
IF(NO_PULSE)
        message(status "<disabled per request>")
ELSE(NO_PULSE)

IF (PULSEAUDIO_INCLUDE_DIR AND PULSEAUDIO_LIBRARIES)
   # in cache already
   SET(PULSEAUDIO_FIND_QUIETLY TRUE)
ENDIF (PULSEAUDIO_INCLUDE_DIR AND PULSEAUDIO_LIBRARIES)

IF (NOT WIN32)
   # use pkg-config to get the directories and then use these values
   # in the FIND_PATH() and FIND_LIBRARY() calls
   INCLUDE(FindPkgConfig)
   pkg_check_modules(PA libpulse)
	set(_PASIncDir ${PA_INCLUDE_DIRS})
	set(_PASLinkDir ${PA_LIBRARY_DIRS})
	set(_PASLinkFlags ${PA_LDFLAGS})
	set(_PASCflags ${PA_CFLAGS})
   SET(PULSEAUDIO_DEFINITIONS ${_PASCflags})
ENDIF (NOT WIN32)

FIND_PATH(PULSEAUDIO_INCLUDE_DIR pulse/pulseaudio.h
   PATHS
   ${_PASIncDir}
   PATH_SUFFIXES pulse
   )

FIND_LIBRARY(PULSEAUDIO_LIBRARIES NAMES pulse libpulse
   PATHS
   ${_PASLinkDir}
   )

IF (PULSEAUDIO_INCLUDE_DIR AND PULSEAUDIO_LIBRARIES)
   SET(PULSEAUDIO_FOUND TRUE)
ELSE (PULSEAUDIO_INCLUDE_DIR AND PULSEAUDIO_LIBRARIES)
   SET(PULSEAUDIO_FOUND FALSE)
ENDIF (PULSEAUDIO_INCLUDE_DIR AND PULSEAUDIO_LIBRARIES)

IF (PULSEAUDIO_FOUND)
   IF (NOT PULSEAUDIO_FIND_QUIETLY)
      MESSAGE(STATUS "Found PulseAudio Simple: ${PULSEAUDIO_LIBRARIES}")
   ENDIF (NOT PULSEAUDIO_FIND_QUIETLY)
   SET(USE_PULSE_ 1)
ELSE (PULSEAUDIO_FOUND)
      MESSAGE(STATUS "Could NOT find LibXml2")
ENDIF (PULSEAUDIO_FOUND)

MARK_AS_ADVANCED(PULSEAUDIO_INCLUDE_DIR PULSEAUDIO_LIBRARIES)

ENDIf(NO_PULSE)


code:
# This module defines
# SDL2_LIBRARY, the name of the library to link against
# SDL2_FOUND, if false, do not try to link to SDL2
# SDL2_INCLUDE_DIR, where to find SDL.h
#
# This module responds to the the flag:
# SDL2_BUILDING_LIBRARY
# If this is defined, then no SDL2main will be linked in because
# only applications need main().
# Otherwise, it is assumed you are building an application and this
# module will attempt to locate and set the the proper link flags
# as part of the returned SDL2_LIBRARY variable.
#
# Don't forget to include SDLmain.h and SDLmain.m your project for the
# OS X framework based version. (Other versions link to -lSDL2main which
# this module will try to find on your behalf.) Also for OS X, this
# module will automatically add the -framework Cocoa on your behalf.
#
#
# Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration
# and no SDL2_LIBRARY, it means CMake did not find your SDL2 library
# (SDL2.dll, libsdl2.so, SDL2.framework, etc).
# Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again.
# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value
# as appropriate. These values are used to generate the final SDL2_LIBRARY
# variable, but when these values are unset, SDL2_LIBRARY does not get created.
#
#
# $SDL2DIR is an environment variable that would
# correspond to the ./configure --prefix=$SDL2DIR
# used in building SDL2.
# l.e.galup  9-20-02
#
# Modified by Eric Wing.
# Added code to assist with automated building by using environmental variables
# and providing a more controlled/consistent search behavior.
# Added new modifications to recognize OS X frameworks and
# additional Unix paths (FreeBSD, etc).
# Also corrected the header search path to follow "proper" SDL guidelines.
# Added a search for SDL2main which is needed by some platforms.
# Added a search for threads which is needed by some platforms.
# Added needed compile switches for MinGW.
#
# On OSX, this will prefer the Framework version (if found) over others.
# People will have to manually change the cache values of
# SDL2_LIBRARY to override this selection or set the CMake environment
# CMAKE_INCLUDE_PATH to modify the search paths.
#
# Note that the header path has changed from SDL2/SDL.h to just SDL.h
# This needed to change because "proper" SDL convention
# is #include "SDL.h", not <SDL2/SDL.h>. This is done for portability
# reasons because not all systems place things in SDL2/ (see FreeBSD).

#=============================================================================
# Copyright 2003-2009 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file COPYING-CMAKE-SCRIPTS for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
#  License text for the above reference.)

# message("<FindSDL2.cmake>")

SET(SDL2_SEARCH_PATHS
	~/Library/Frameworks
	/Library/Frameworks
	/usr/local
	/usr
	/sw # Fink
	/opt/local # DarwinPorts
	/opt/csw # Blastwave
	/opt
	${SDL2_PATH}
)

FIND_PATH(SDL2_INCLUDE_DIR SDL.h
	HINTS
	$ENV{SDL2DIR}
	PATH_SUFFIXES SDL2 include/SDL2 include
	PATHS ${SDL2_SEARCH_PATHS}
)

if(CMAKE_SIZEOF_VOID_P EQUAL 8)
	set(PATH_SUFFIXES lib64 lib/x64 lib)
else()
	set(PATH_SUFFIXES lib/x86 lib)
endif()

FIND_LIBRARY(SDL2_LIBRARY_TEMP
	NAMES SDL2
	HINTS
	$ENV{SDL2DIR}
	PATH_SUFFIXES ${PATH_SUFFIXES}
	PATHS ${SDL2_SEARCH_PATHS}
)

IF(NOT SDL2_BUILDING_LIBRARY)
	IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
		# Non-OS X framework versions expect you to also dynamically link to
		# SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms
		# seem to provide SDL2main for compatibility even though they don't
		# necessarily need it.
		FIND_LIBRARY(SDL2MAIN_LIBRARY
			NAMES SDL2main
			HINTS
			$ENV{SDL2DIR}
			PATH_SUFFIXES ${PATH_SUFFIXES}
			PATHS ${SDL2_SEARCH_PATHS}
		)
	ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
ENDIF(NOT SDL2_BUILDING_LIBRARY)

# SDL2 may require threads on your system.
# The Apple build may not need an explicit flag because one of the
# frameworks may already provide it.
# But for non-OSX systems, I will use the CMake Threads package.
IF(NOT APPLE)
	FIND_PACKAGE(Threads)
ENDIF(NOT APPLE)

# MinGW needs an additional link flag, -mwindows
# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -mwindows
IF(MINGW)
	SET(MINGW32_LIBRARY mingw32 "-mwindows" CACHE STRING "mwindows for MinGW")
ENDIF(MINGW)

IF(SDL2_LIBRARY_TEMP)
	# For SDL2main
	IF(NOT SDL2_BUILDING_LIBRARY)
		IF(SDL2MAIN_LIBRARY)
			SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP})
		ENDIF(SDL2MAIN_LIBRARY)
	ENDIF(NOT SDL2_BUILDING_LIBRARY)

	# For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa.
	# CMake doesn't display the -framework Cocoa string in the UI even
	# though it actually is there if I modify a pre-used variable.
	# I think it has something to do with the CACHE STRING.
	# So I use a temporary variable until the end so I can set the
	# "real" variable in one-shot.
	IF(APPLE)
		SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} "-framework Cocoa")
	ENDIF(APPLE)

	# For threads, as mentioned Apple doesn't need this.
	# In fact, there seems to be a problem if I used the Threads package
	# and try using this line, so I'm just skipping it entirely for OS X.
	IF(NOT APPLE)
		SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
	ENDIF(NOT APPLE)

	# For MinGW library
	IF(MINGW)
		SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP})
	ENDIF(MINGW)

	# Set the final string here so the GUI reflects the final state.
	SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found")
	# Set the temp variable to INTERNAL so it is not seen in the CMake GUI
	SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "")
ENDIF(SDL2_LIBRARY_TEMP)

# message("</FindSDL2.cmake>")

INCLUDE(FindPackageHandleStandardArgs)

FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR)


code:
FIND_PATH(STK_INCLUDE_DIR Stk.h /usr/include/stk /usr/local/include/stk ${CMAKE_INSTALL_PREFIX}/include/stk ${CMAKE_FIND_ROOT_PATH}/include/stk)

FIND_LIBRARY(STK_LIBRARY NAMES stk PATH /usr/lib /usr/local/lib ${CMAKE_INSTALL_PREFIX}/lib ${CMAKE_FIND_ROOT_PATH}/lib)

IF (STK_INCLUDE_DIR AND STK_LIBRARY)
   SET(STK_FOUND TRUE)
ENDIF (STK_INCLUDE_DIR AND STK_LIBRARY)

IF (STK_FOUND)
   IF (NOT STK_FIND_QUIETLY)
      MESSAGE(STATUS "Found STK: ${STK_LIBRARY}")
	SET(HAVE_STK TRUE)
   ENDIF (NOT STK_FIND_QUIETLY)
ELSE (STK_FOUND)
   IF (STK_FIND_REQUIRED)
      MESSAGE(FATAL_ERROR "Could not find STK")
   ENDIF (STK_FIND_REQUIRED)
ENDIF (STK_FOUND)


code:
# FindFFTW.cmake - Try to find FFTW3
# Copyright (c) 2018 Lukas W <lukaswhl/at/gmail.com>
# This file is MIT licensed.
# See http://opensource.org/licenses/MIT

find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
	pkg_check_modules(SAMPLERATE_PKG samplerate)
endif()

find_path(SAMPLERATE_INCLUDE_DIR
	NAMES samplerate.h
	PATHS ${SAMPLERATE_PKG_INCLUDE_DIRS}
)

set(SAMPLERATE_NAMES samplerate libsamplerate)
if(Samplerate_FIND_VERSION_MAJOR)
	list(APPEND SAMPLERATE_NAMES libsamplerate-${Samplerate_FIND_VERSION_MAJOR})
else()
	list(APPEND SAMPLERATE_NAMES libsamplerate-0)
endif()

find_library(SAMPLERATE_LIBRARY
	NAMES ${SAMPLERATE_NAMES}
	PATHS ${SAMPLERATE_PKG_LIBRARY_DIRS}
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(SAMPLERATE DEFAULT_MSG SAMPLERATE_LIBRARY SAMPLERATE_INCLUDE_DIR)

mark_as_advanced(SAMPLERATE_INCLUDE_DIR SAMPLERATE_LIBRARY )

set(SAMPLERATE_LIBRARIES ${SAMPLERATE_LIBRARY} )
set(SAMPLERATE_INCLUDE_DIRS ${SAMPLERATE_INCLUDE_DIR})


code:
# FindSndFile.cmake - Try to find libsndfile
# Copyright (c) 2018 Lukas W <lukaswhl/at/gmail.com>
# This file is MIT licensed.
# See http://opensource.org/licenses/MIT

# Try pkgconfig for hints
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
	pkg_check_modules(SNDFILE_PKG sndfile)
endif(PKG_CONFIG_FOUND)
set(SndFile_DEFINITIONS ${SNDFILE_PKG_CFLAGS_OTHER})

if(WIN32)
	# Try Vcpkg
	find_package(LibSndFile ${SndFile_FIND_VERSION} CONFIG QUIET)
	if(LibSndFile_FOUND)
		get_target_property(LibSndFile_Location sndfile-shared LOCATION)
		get_target_property(LibSndFile_Include_Path sndfile-shared INTERFACE_INCLUDE_DIRECTORIES)
		get_filename_component(LibSndFile_Path LibSndFile_Location PATH)
	endif()
endif()

find_path(SNDFILE_INCLUDE_DIR
	NAMES sndfile.h
	PATHS ${SNDFILE_PKG_INCLUDE_DIRS} ${LibSndFile_Include_Path}
)

find_library(SNDFILE_LIBRARY
	NAMES sndfile libsndfile libsndfile-1
	PATHS ${SNDFILE_PKG_LIBRARY_DIRS} ${LibSndFile_Path}
)

find_package(PackageHandleStandardArgs)
find_package_handle_standard_args(SndFile DEFAULT_MSG SNDFILE_LIBRARY SNDFILE_INCLUDE_DIR)

set(SNDFILE_LIBRARIES ${SNDFILE_LIBRARY})
set(SNDFILE_INCLUDE_DIRS ${SNDFILE_INCLUDE_DIR})

mark_as_advanced(SNDFILE_LIBRARY SNDFILE_LIBRARIES SNDFILE_INCLUDE_DIR SNDFILE_INCLUDE_DIRS)


code:
# sndio check, based on FindAlsa.cmake
#

# Copyright (c) 2006, David Faure, <faure@kde.org>
# Copyright (c) 2007, Matthias Kretz <kretz@kde.org>
# Copyright (c) 2009, Jacob Meuser <jakemsr@sdf.lonestar.org>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.

include(CheckIncludeFiles)
include(CheckIncludeFileCXX)
include(CheckLibraryExists)

# Already done by toplevel
find_library(SNDIO_LIBRARY sndio)
set(SNDIO_LIBRARY_DIR "")
if(SNDIO_LIBRARY)
   get_filename_component(SNDIO_LIBRARY_DIR ${SNDIO_LIBRARY} PATH)
endif(SNDIO_LIBRARY)

check_library_exists(sndio sio_open "${SNDIO_LIBRARY_DIR}" HAVE_SIO_OPEN)

find_path(SNDIO_INCLUDE_DIR sndio.h)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(SNDIO DEFAULT_MSG SNDIO_LIBRARY SNDIO_INCLUDE_DIR HAVE_SIO_OPEN)

if(SNDIO_FOUND)
    set(SNDIO_INCLUDE_DIRS "${SNDIO_INCLUDE_DIR}")
    set(SNDIO_LIBRARIES "${SNDIO_LIBRARY}")
endif()

mark_as_advanced(SNDIO_INCLUDE_DIR SNDIO_LIBRARY SNDIO_INCLUDE_DIRS SNDIO_LIBRARIES)


code:
# Copyright (c) 2015 Andrew Kelley
# This file is MIT licensed.
# See http://opensource.org/licenses/MIT

# SOUNDIO_FOUND
# SOUNDIO_INCLUDE_DIR
# SOUNDIO_LIBRARY

find_path(SOUNDIO_INCLUDE_DIR NAMES soundio/soundio.h)

find_library(SOUNDIO_LIBRARY NAMES soundio)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(SOUNDIO DEFAULT_MSG SOUNDIO_LIBRARY SOUNDIO_INCLUDE_DIR)

mark_as_advanced(SOUNDIO_INCLUDE_DIR SOUNDIO_LIBRARY)


code:
# - Try to find the wine libraries
# Once done this will define
#
#  WINE_FOUND - System has wine
#  WINE_INCLUDE_DIRS - The wine include directories
#  WINE_DEFINITIONS - Compiler switches required for using wine
#

MACRO(_findwine_find_flags output expression result)
	STRING(REPLACE " " ";" WINEBUILD_FLAGS "${output}")
	FOREACH(FLAG ${WINEBUILD_FLAGS})
		IF("${FLAG}" MATCHES "${expression}")
			LIST(APPEND ${result} "${FLAG}")
		ENDIF()
	ENDFOREACH()
ENDMACRO()

MACRO(_regex_replace_foreach EXPRESSION REPLACEMENT RESULT INPUT)
	SET(${RESULT} "")
	FOREACH(ITEM ${INPUT})
		STRING(REGEX REPLACE "${EXPRESSION}" "${REPLACEMENT}" ITEM "${ITEM}")
		LIST(APPEND ${RESULT} "${ITEM}")
	ENDFOREACH()
ENDMACRO()

LIST(APPEND CMAKE_PREFIX_PATH /opt/wine-stable /opt/wine-devel /opt/wine-staging /usr/lib/wine/)

FIND_PROGRAM(WINE_CXX
	NAMES wineg++ winegcc winegcc64 winegcc32 winegcc-stable
	PATHS /usr/lib/wine
)
FIND_PROGRAM(WINE_BUILD NAMES winebuild)
# Detect wine paths and handle linking problems
IF(WINE_CXX)
	EXEC_PROGRAM(${WINE_CXX} ARGS "-m32 -v /dev/zero" OUTPUT_VARIABLE WINEBUILD_OUTPUT_32)
	EXEC_PROGRAM(${WINE_CXX} ARGS "-m64 -v /dev/zero" OUTPUT_VARIABLE WINEBUILD_OUTPUT_64)
	_findwine_find_flags("${WINEBUILD_OUTPUT_32}" "^-isystem/usr/include$" BUGGED_WINEGCC)
	_findwine_find_flags("${WINEBUILD_OUTPUT_32}" "^-isystem" WINEGCC_INCLUDE_DIR)
	_findwine_find_flags("${WINEBUILD_OUTPUT_32}" "libwinecrt0\\.a.*" WINECRT_32)
	_findwine_find_flags("${WINEBUILD_OUTPUT_64}" "libwinecrt0\\.a.*" WINECRT_64)
	_regex_replace_foreach("^-isystem" "" WINE_INCLUDE_HINT "${WINEGCC_INCLUDE_DIR}")
	_regex_replace_foreach("/wine/windows$" "" WINE_INCLUDE_HINT "${WINE_INCLUDE_HINT}")
	STRING(REGEX REPLACE "wine/libwinecrt0\\.a.*" "" WINE_32_LIBRARY_DIR "${WINECRT_32}")
	STRING(REGEX REPLACE "wine/libwinecrt0\\.a.*" "" WINE_64_LIBRARY_DIR "${WINECRT_64}")

	IF(BUGGED_WINEGCC)
		MESSAGE(WARNING "Your winegcc is unusable due to https://bugs.winehq.org/show_bug.cgi?id=46293,\n
			Consider either upgrading or downgrading wine.")
		RETURN()
	ENDIF()
	IF(WINE_32_LIBRARY_DIR STREQUAL WINE_64_LIBRARY_DIR)
		MESSAGE(STATUS "Old winegcc detected, trying to use workaround linking")
		# Fix library search directory according to the target bitness
		IF(WINE_32_LIBRARY_DIR MATCHES "/lib/(x86_64|i386)-")
			# Debian systems
			STRING(REPLACE "/lib/x86_64-" "/lib/i386-" WINE_32_LIBRARY_DIR "${WINE_32_LIBRARY_DIR}")
			STRING(REPLACE "/lib/i386-" "/lib/x86_64-" WINE_64_LIBRARY_DIR "${WINE_64_LIBRARY_DIR}")
		ELSEIF(WINE_32_LIBRARY_DIR MATCHES "/(lib|lib64)/wine/$")
			# WineHQ (/opt/wine-stable, /opt/wine-devel, /opt/wine-staging)
			STRING(REGEX REPLACE "/lib64/wine/$" "/lib/wine/" WINE_32_LIBRARY_DIR "${WINE_32_LIBRARY_DIR}")
			STRING(REGEX REPLACE "/lib/wine/$" "/lib64/wine/" WINE_64_LIBRARY_DIR "${WINE_64_LIBRARY_DIR}")
		ELSEIF(WINE_32_LIBRARY_DIR MATCHES "/lib32/")
			# Systems with old multilib layout
			STRING(REPLACE "/lib32/" "/lib/" WINE_64_LIBRARY_DIR "${WINE_32_LIBRARY_DIR}")
		ELSEIF(WINE_32_LIBRARY_DIR MATCHES "/lib64/")
			# We need to test if the corresponding 64bit library directory is lib or lib32
			STRING(REPLACE "/lib64/" "/lib32/" WINE_32_LIBRARY_DIR "${WINE_64_LIBRARY_DIR}")
			IF(NOT EXISTS "${WINE_32_LIBRARY_DIR}")
				STRING(REPLACE "/lib64/" "/lib/" WINE_32_LIBRARY_DIR "${WINE_64_LIBRARY_DIR}")
			ENDIF()
		ELSEIF(WINE_32_LIBRARY_DIR MATCHES "/lib/")
			# Test if this directory is for 32bit or 64bit
			STRING(REPLACE "/lib/" "/lib32/" WINE_32_LIBRARY_DIR "${WINE_64_LIBRARY_DIR}")
			IF(NOT EXISTS "${WINE_32_LIBRARY_DIR}")
				SET(WINE_32_LIBRARY_DIR "${WINE_64_LIBRARY_DIR}")
				STRING(REPLACE "/lib/" "/lib64/" WINE_64_LIBRARY_DIR "${WINE_64_LIBRARY_DIR}")
			ENDIF()
		ELSE()
			MESSAGE(WARNING "Can't detect wine installation layout. You may get some build errors.")
		ENDIF()
		SET(WINE_LIBRARY_FIX "${WINE_32_LIBRARY_DIR} and ${WINE_64_LIBRARY_DIR}")
	ENDIF()
ENDIF()

FIND_PATH(WINE_INCLUDE_DIR wine/exception.h
	HINTS ${WINE_INCLUDE_HINT}
)

SET(_ARCHITECTURE ${CMAKE_LIBRARY_ARCHITECTURE})

SET(CMAKE_LIBRARY_ARCHITECTURE ${_ARCHITECTURE})

SET(WINE_INCLUDE_DIRS ${WINE_INCLUDE_DIR} )

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Wine DEFAULT_MSG WINE_CXX WINE_INCLUDE_DIRS)

mark_as_advanced(WINE_INCLUDE_DIR WINE_LIBRARY WINE_CXX WINE_BUILD)

IF(WINE_32_LIBRARY_DIR)
	IF(WINE_32_LIBRARY_DIR MATCHES "wine*/lib")
		SET(WINE_32_FLAGS "-L${WINE_32_LIBRARY_DIR} -L${WINE_32_LIBRARY_DIR}../")
		SET(WINE_32_LIBRARY_DIRS "${WINE_32_LIBRARY_DIR}:${WINE_32_LIBRARY_DIR}/..")
	ELSE()
		SET(WINE_32_FLAGS "-L${WINE_32_LIBRARY_DIR} -L${WINE_32_LIBRARY_DIR}wine/")
		SET(WINE_32_LIBRARY_DIRS "${WINE_32_LIBRARY_DIR}:${WINE_32_LIBRARY_DIR}wine/")
	ENDIF()
ENDIF()

IF(WINE_64_LIBRARY_DIR)
	IF(WINE_64_LIBRARY_DIR MATCHES "wine*/lib")
		SET(WINE_64_FLAGS "-L${WINE_64_LIBRARY_DIR} -L${WINE_64_LIBRARY_DIR}../")
		SET(WINE_64_LIBRARY_DIRS "${WINE_64_LIBRARY_DIR}:${WINE_64_LIBRARY_DIR}/..")
	ELSE()
		SET(WINE_64_FLAGS "-L${WINE_64_LIBRARY_DIR} -L${WINE_64_LIBRARY_DIR}wine/")
		SET(WINE_64_LIBRARY_DIRS "${WINE_64_LIBRARY_DIR}:${WINE_64_LIBRARY_DIR}wine/")
	ENDIF()
ENDIF()

# Create winegcc wrapper
configure_file(${CMAKE_CURRENT_LIST_DIR}/winegcc_wrapper.in winegcc_wrapper @ONLY)
SET(WINEGCC "${CMAKE_CURRENT_BINARY_DIR}/winegcc_wrapper")


code:
# GenQrc.cmake - Copyright (c) 2015 Lukas W <lukaswhl/at/gmail.com>

# Generates a simple qrc file containing the given resource files ${ARGN}:
#     GEN_QRC(resources.qrc artwork.png icon.png PREFIX /icons)
# Files may also be added using a pattern with the GLOB keyword, e.g.:
#     GEN_QRC(resources.qrc GLOB *.png)
FUNCTION(GEN_QRC OUT_FILE)
	CMAKE_PARSE_ARGUMENTS(RC "" "PREFIX;GLOB" "" ${ARGN})

	IF(DEFINED RC_GLOB)
		FILE(GLOB GLOB_FILES ${RC_GLOB})
	ENDIF()

	# Set the standard prefix to "/" if none is given
	IF(NOT DEFINED RC_PREFIX)
		SET(RC_PREFIX "/")
	ENDIF()

	# We need to convert our list to a string in order to pass it to the script
	# on the command line.
	STRING(REPLACE ";" "\;" FILES "${RC_UNPARSED_ARGUMENTS};${GLOB_FILES}")

	SET(GENQRC_SCRIPT "${CMAKE_SOURCE_DIR}/cmake/scripts/GenQrc.cmake")
	ADD_CUSTOM_COMMAND(
		OUTPUT ${OUT_FILE}
		COMMAND ${CMAKE_COMMAND} -D OUT_FILE=${OUT_FILE} -D RC_PREFIX=${RC_PREFIX} -D FILES:list=${FILES} -D DIR=${CMAKE_CURRENT_SOURCE_DIR} -P "${GENQRC_SCRIPT}"
		DEPENDS ${GENQRC_SCRIPT}
		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
		VERBATIM
	)
ENDFUNCTION()

# Generates a qrc file named ${QRC_OUT} from ${ARGN}, rccs it and returns Qt's
# output file.
# Must only be run once per CMakeLists.txt.
# Usage example:
#     ADD_GEN_QRC(RCC_OUTPUT resources.qrc icon.png manual.pdf)
#     ADD_EXECUTABLE(myexe main.cpp ${RCC_OUTPUT})
MACRO(ADD_GEN_QRC RCCOUT QRC_OUT)
	IF(NOT IS_ABSOLUTE ${QRC_OUT})
		SET(QRC_FILE "${CMAKE_CURRENT_BINARY_DIR}/${QRC_OUT}")
	ELSE()
		SET(QRC_FILE ${QRC_OUT})
	ENDIF()

	GEN_QRC(${QRC_FILE} "${ARGN}")
	QT5_ADD_RESOURCES(${RCCOUT} ${QRC_FILE})
ENDMACRO()


code:
include(GetPrerequisites)
include(CMakeParseArguments)

CMAKE_POLICY(SET CMP0011 NEW)
CMAKE_POLICY(SET CMP0057 NEW)

function(make_absolute var)
	get_filename_component(abs "${${var}}" ABSOLUTE BASE_DIR "${CMAKE_INSTALL_PREFIX}")
	set(${var} ${abs} PARENT_SCOPE)
endfunction()

# Reads lines of a file into a list, skipping '#' comment lines
function(READ_LIST_FILE FILE VAR)
	file(STRINGS "${FILE}" list)

	set(result "")
	foreach(item ${list})
		string(STRIP "${item}" item)
		if(item STREQUAL "" OR item MATCHES "^\#")
			continue()
		endif()
		list(APPEND result "${item}")
	endforeach()

	set(${VAR} ${result} PARENT_SCOPE)
endfunction()

function(make_all_absolute list_var)
	set(result "")
	foreach(file ${${list_var}})
		make_absolute(file)
		list(APPEND result ${file})
	endforeach()
	set(${list_var} ${result} PARENT_SCOPE)
endfunction()

if(CMAKE_BINARY_DIR)
	set(tmp_lib_dir "${CMAKE_BINARY_DIR}/bundled-libraries")
elseif(CMAKE_HOST_UNIX)
	set(tmp_lib_dir "/tmp/bundled-libraries")
elseif(DEFINED ENV{TEMP})
	set(tmp_lib_dir "$ENV{TMP}/bundled-libraries")
else()
	message(FATAL_ERROR "Can't find a temp dir for libraries")
endif()

# Like file(INSTALL), but resolves symlinks
function(install_file_resolved file destination)

	get_filename_component(file_name "${file}" NAME)
	if(IS_SYMLINK "${file}")
		get_filename_component(real_path "${file}" REALPATH)
		get_filename_component(real_name "${real_path}" NAME)
		file(COPY "${real_path}" DESTINATION "${tmp_lib_dir}")
		file(RENAME "${tmp_lib_dir}/${real_name}" "${tmp_lib_dir}/${file_name}")
		set(file_path "${tmp_lib_dir}/${file_name}")
	else()
		set(file_path "${file}")
	endif()

	file(INSTALL "${file_path}" DESTINATION "${destination}")
endfunction()

function(install_resolved)
	cmake_parse_arguments("" "" "DESTINATION" "FILES" ${ARGN})
	foreach(file ${_FILES})
		install_file_resolved("${file}" "${_DESTINATION}")
	endforeach()
endfunction()

if(CMAKE_CROSSCOMPILING)
	# If we're cross-compiling, GetPrerequisites may not be able to find system libraries such as kernel32.dll because
	# they're supplied by the toolchain. To suppress thousands of lines of warnings being printed to the console, we
	# override gp_resolved_file_type to return "system" for any library in ${IGNORE_LIBS} without trying to resolve the
	# file first.
	# GetPrerequisites supports using an override function called gp_resolved_file_type_override, but it's not suited
	# for our purpose because it's only called by gp_resolved_file_type *after* trying to resolve the file.
	function(gp_resolved_file_type original_file file exepath dirs type_var)
		set(file_find "${file}")
		if(_IGNORE_CASE)
			# On case-insensitive systems, convert to upper characters to respect it
			string(TOUPPER "${file_find}" file_find)
		endif()
		SET(IGNORE_LIBS ${_IGNORE_LIBS} CACHE INTERNAL "Ignored library names" FORCE)
		if(IGNORE_LIBS AND ${file_find} IN_LIST IGNORE_LIBS)
			set(${type_var} system PARENT_SCOPE)
		else()
			#_gp_resolved_file_type(${ARGV})
			_gp_resolved_file_type("${original_file}" "${file}" "${exepath}" "${dirs}" "${type_var}" ${ARGN})
		endif()
	endfunction()
endif()

function(INSTALL_DEPENDENCIES)
	cmake_parse_arguments("" "INCLUDE_SYSTEM;IGNORE_CASE" "GP_TOOL;DESTINATION;IGNORE_LIBS_FILE" "FILES;LIB_DIRS;SEARCH_PATHS;IGNORE_LIBS" ${ARGN})

	# Make paths absolute
	make_absolute(_DESTINATION)
	make_all_absolute(_FILES)
	make_all_absolute(_LIB_DIRS)
	make_all_absolute(_SEARCH_PATHS)

	if(_INCLUDE_SYSTEM)
		set(EXCLUDE_SYSTEM 0)
	else()
		set(EXCLUDE_SYSTEM 1)
	endif()

	if(_IGNORE_LIBS_FILE)
		READ_LIST_FILE("${_IGNORE_LIBS_FILE}" _IGNORE_LIBS)
		if(_IGNORE_CASE)
			# On case-insensitive systems, convert to upper characters to respect it
			string(TOUPPER "${_IGNORE_LIBS}" _IGNORE_LIBS)
		endif()
		SET(IGNORE_LIBS ${_IGNORE_LIBS} CACHE INTERNAL "Ignored library names" FORCE)
	endif()

	if(_GP_TOOL)
		set(gp_tool "${_GP_TOOL}")
	endif()

	set(prereqs "")
	foreach(file ${_FILES})
		get_filename_component(file_name "${file}" NAME)
		message("-- Finding prerequisites of ${file_name}")
		find_prerequisites("${file}" _prereqs
			${EXCLUDE_SYSTEM} # exclude system files
			1 # recurse
			""
			"${_LIB_DIRS}"
			"${_SEARCH_PATHS}"
			"${_IGNORE_LIBS}"
		)

		list(APPEND prereqs ${_prereqs})
	endforeach()

	list(REMOVE_DUPLICATES prereqs)

	foreach(prereq ${prereqs})
		get_filename_component(prereq_name "${prereq}" NAME)

		foreach(rpath ${_SEARCH_PATHS})
			if(EXISTS "${rpath}/${prereq_name}")
				list(REMOVE_ITEM prereqs "${prereq}")
				break()
			endif()
		endforeach()
	endforeach()

	#file(INSTALL ${prereqs} DESTINATION ${_DESTINATION})
	install_resolved(FILES ${prereqs} DESTINATION "${_DESTINATION}")
endfunction()

# Like get_prerequisites, but returns full paths
function(FIND_PREREQUISITES target RESULT_VAR exclude_system recurse
	exepath dirs rpaths)
	set(RESULTS)

	get_prerequisites("${target}" _prereqs ${exclude_system} ${recurse}
                  "" "${dirs}" "${rpaths}")

	foreach(prereq ${_prereqs})
		get_filename_component(prereq_name "${prereq}" NAME)
		if(_IGNORE_CASE)
			# Windows is case insensitive.
			# Use upper characters to respect it.
			string(TOUPPER "${prereq_name}" prereq_name)
		endif()
		if("${prereq_name}" IN_LIST IGNORE_LIBS)
			continue()
		endif()

		gp_resolve_item("${LIB_DLL}" "${prereq}" "" "${dirs}" RESOLVED_PREREQ "${rpaths}")

		if(RESOLVED_PREREQ AND IS_ABSOLUTE ${RESOLVED_PREREQ} AND EXISTS ${RESOLVED_PREREQ})
			list(APPEND RESULTS ${RESOLVED_PREREQ})
		else()
			message(FATAL_ERROR "Can't resolve dependency ${prereq}.")
		endif()
	endforeach()

	set(${RESULT_VAR} ${RESULTS} PARENT_SCOPE)
endfunction()


code:
#
# install all files matching certain wildcards below ${LMMS_DATA_DIR}/<subdir>
#
# example:
#
#   INSTALL_DATA_SUBDIRS("samples" "*.ogg;*.wav;*.flac")
#
# Copyright (c) 2008 Tobias Doerffel
#

# helper-macro
MACRO(LIST_CONTAINS var value)
	SET(${var})
		FOREACH (value2 ${ARGN})
			IF (${value} STREQUAL ${value2})
				SET(${var} TRUE)
			ENDIF (${value} STREQUAL ${value2})
	ENDFOREACH (value2)
ENDMACRO(LIST_CONTAINS)

MACRO(INSTALL_DATA_SUBDIRS _subdir _wildcards)
	FOREACH(_wildcard ${_wildcards})
		FILE(GLOB_RECURSE files ${_wildcard})
		LIST(SORT files)
		SET(SUBDIRS)

		FOREACH(_item ${files})
			GET_FILENAME_COMPONENT(_file "${_item}" PATH)
			STRING(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" _file "${_file}")
			LIST_CONTAINS(contains _file ${SUBDIRS})
			IF(NOT contains)
				LIST(APPEND SUBDIRS "${_file}")
			ENDIF(NOT contains)
		ENDFOREACH(_item ${files})

		FOREACH(_item ${SUBDIRS})
			FILE(GLOB files "${_item}/${_wildcard}")
			LIST(SORT files)
			FOREACH(_file ${files})
				INSTALL(FILES "${_file}" DESTINATION "${LMMS_DATA_DIR}/${_subdir}/${_item}/")
			ENDFOREACH(_file ${files})
		ENDFOREACH(_item ${SUBDIRS})
	ENDFOREACH(_wildcard ${_wildcards})
ENDMACRO(INSTALL_DATA_SUBDIRS)


code:
include(DefineInstallVar)

SET(DEFAULT_SEARCH_DIRECTORIES "${BIN_DIR}" "${LIB_DIR}" "${CMAKE_FIND_ROOT_PATH}" "${CMAKE_PREFIX_PATH}")
SET(DEFAULT_SEARCH_SUFFIXES "bin" "lib" "../bin")

# Like INSTALL_DEPENDENCIES but can be called from regular cmake code
# (instead of install(CODE)), takes targets instead of files,
# takes care of configuring search paths, and other platform-specific tweaks.
# Arguments:
#	TARGETS:			list of cmake targets to install.
#	NAME:				unique string for this install.
#	DESTINATION:		directory path to install the binaries to.
#	LIB_DIRS:			list of paths for looking up dependencies.
#	LIB_DIRS_SUFFIXES:	list of possible suffixes for LIB_DIRS entries.
#	SEARCH_PATHS:			list of library search paths on runtime
#	NO_DEFAULT_PATHS:	supply this value to avoid adding DEFAULT_SEARCH_DIRECTORIES
#						to LIB_DIRS and DEFAULT_SEARCH_SUFFIXES to LIB_DIRS_SUFFIXES.
FUNCTION(INSTALL_TARGET_DEPENDENCIES)
	set(options NO_DEFAULT_PATHS)
	set(oneValueArgs NAME)
	set(multiValueArgs TARGETS DESTINATION LIB_DIRS_SUFFIXES LIB_DIRS SEARCH_PATHS)
	cmake_parse_arguments(DEPS "${options}" "${oneValueArgs}"
			"${multiValueArgs}" ${ARGN} )

	if(NOT DEPS_LIB_DIRS)
		set(DEPS_LIB_DIRS "")
	endif()

	# Set default values.
	if(NOT DEPS_NO_DEFAULT_PATHS)
		list(APPEND DEPS_LIB_DIRS ${DEFAULT_SEARCH_DIRECTORIES})
		set(DEPS_LIB_DIRS_SUFFIXES "${DEPS_LIB_DIRS_SUFFIXES}" ${DEFAULT_SEARCH_SUFFIXES})
	endif()

	FOREACH(TARGET ${DEPS_TARGETS})
		IF(NOT TARGET ${TARGET})
			message(FATAL_ERROR "Not a target: ${TARGET}")
		ENDIF()

		# Collect target output files.
		LIST(APPEND DEPLOY_TARGETS "$<TARGET_FILE:${TARGET}>")

		# Collect target link directories
		get_target_property(target_libs ${TARGET} LINK_LIBRARIES)

		foreach(lib ${target_libs})
			if(TARGET ${lib} OR NOT IS_ABSOLUTE ${lib})
				continue()
			endif()

			get_filename_component(lib_dir ${lib} PATH)
			list(APPEND DEPS_LIB_DIRS ${lib_dir})
		endforeach()
	ENDFOREACH()

	LIST(APPEND DEPS_LIB_DIRS ${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES})

	FOREACH(LIB_PATH ${DEPS_LIB_DIRS})
		FOREACH(suffix ${DEPS_LIB_DIRS_SUFFIXES})
			list(APPEND DEPS_LIB_DIRS "${LIB_PATH}/${suffix}")
		ENDFOREACH()
	ENDFOREACH()

	DEFINE_INSTALL_VAR(NAME "DEPLOY_FILES" CONTENT "${DEPLOY_TARGETS}" GENERATOR_EXPRESSION)

	LIST(REMOVE_DUPLICATES DEPS_LIB_DIRS)

	IF(LMMS_BUILD_LINUX)
		FILE(DOWNLOAD "https://raw.githubusercontent.com/AppImage/AppImages/master/excludelist"
				"${CMAKE_BINARY_DIR}/excludelist")
		SET(additional_args INCLUDE_SYSTEM IGNORE_LIBS_FILE ${CMAKE_BINARY_DIR}/excludelist)
	ELSEIF(LMMS_BUILD_WIN32)
		SET(additional_args IGNORE_CASE IGNORE_LIBS_FILE "${LMMS_SOURCE_DIR}/cmake/install/excludelist-win")
		IF(CMAKE_CROSSCOMPILING)
			SET(additional_args "${additional_args}" GP_TOOL objdump)
		ENDIF()
	ENDIF()

	INSTALL(CODE "
		INCLUDE(\"${LMMS_SOURCE_DIR}/cmake/modules/InstallDependencies.cmake\")

		INSTALL_DEPENDENCIES(
			FILES \"\${DEPLOY_FILES}\"
			DESTINATION \"${DEPS_DESTINATION}\"
			LIB_DIRS \"${DEPS_LIB_DIRS}\"
			SEARCH_PATHS \"${DEPS_SEARCH_PATHS}\"
			${additional_args}
		)
	")
ENDFUNCTION()


code:
# Provides a fast mechanism for filtering the plugins used at build-time
SET(PLUGIN_LIST "" CACHE STRING "List of plug-ins to build")
STRING(REPLACE " " ";" PLUGIN_LIST "${PLUGIN_LIST}")
OPTION(LMMS_MINIMAL "Build a minimal list of plug-ins" OFF)
OPTION(LIST_PLUGINS "Lists the available plugins for building" OFF)

SET(MINIMAL_LIST
	audio_file_processor
	kicker
	triple_oscillator
)

IF(LMMS_MINIMAL)
	IF("${PLUGIN_LIST}" STREQUAL "")
		STRING(REPLACE ";" " " MINIMAL_LIST_STRING "${MINIMAL_LIST}")
		MESSAGE(
"-- Using minimal plug-ins: ${MINIMAL_LIST_STRING}\n"
"   Note: You can specify specific plug-ins using -DPLUGIN_LIST=\"foo bar\""
		)
	ENDIF()
	SET(PLUGIN_LIST ${MINIMAL_LIST} ${PLUGIN_LIST})
ENDIF()

SET(LMMS_PLUGIN_LIST
	${MINIMAL_LIST}
	Amplifier
	BassBooster
	bit_invader
	Bitcrush
	carlabase
	carlapatchbay
	carlarack
	CrossoverEQ
	Delay
	DualFilter
	dynamics_processor
	Eq
	Flanger
	HydrogenImport
	ladspa_browser
	LadspaEffect
	Lv2Effect
	Lv2Instrument
	lb302
	MidiImport
	MidiExport
	MultitapEcho
	monstro
	nes
	OpulenZ
	organic
	FreeBoy
	patman
	peak_controller_effect
	GigPlayer
	ReverbSC
	sf2_player
	sfxr
	Sid
	SpectrumAnalyzer
	stereo_enhancer
	stereo_matrix
	stk
	vst_base
	vestige
	VstEffect
	watsyn
	waveshaper
	Vectorscope
	vibed
	Xpressive
	zynaddsubfx
)

IF("${PLUGIN_LIST}" STREQUAL "")
	SET(PLUGIN_LIST ${LMMS_PLUGIN_LIST})
ENDIF()

MACRO(LIST_ALL_PLUGINS)
	MESSAGE("\n\nAll possible -DPLUGIN_LIST values")
	MESSAGE("\n   KEYWORD:")
	MESSAGE("      -DLMMS_MINIMAL=True")
	FOREACH(item IN LISTS MINIMAL_LIST)
		MESSAGE("         ${item}")
	ENDFOREACH()
	MESSAGE("\n   NAME:")
	FOREACH(item IN LISTS LMMS_PLUGIN_LIST)
		MESSAGE("      ${item}")
	ENDFOREACH()
	MESSAGE("\nNote:  This value also impacts the fetching of git submodules.\n")
	MESSAGE(FATAL_ERROR "Information was requested, aborting build!")
ENDMACRO()

IF(LIST_PLUGINS)
	UNSET(LIST_PLUGINS CACHE)
	LIST_ALL_PLUGINS()
ENDIF()

IF(MSVC)
	SET(MSVC_INCOMPATIBLE_PLUGINS
		LadspaEffect
		zynaddsubfx
	)
	message(WARNING "Compiling with MSVC. The following plugins are not available: ${MSVC_INCOMPATIBLE_PLUGINS}")
	LIST(REMOVE_ITEM PLUGIN_LIST ${MSVC_INCOMPATIBLE_PLUGINS})
ENDIF()


code:
FIND_PACKAGE(Git)
IF(GIT_FOUND AND NOT FORCE_VERSION)
	SET(MAJOR_VERSION 0)
	SET(MINOR_VERSION 0)
	SET(PATCH_VERSION 0)
	# Look for git tag information (e.g. Tagged: "v1.0.0", Untagged: "v1.0.0-123-a1b2c3d")
	# Untagged format: [latest tag]-[number of commits]-[latest commit hash]
	EXECUTE_PROCESS(
		COMMAND "${GIT_EXECUTABLE}" describe --tags --match v[0-9].[0-9].[0-9]*
		OUTPUT_VARIABLE GIT_TAG
		WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
		TIMEOUT 10
		OUTPUT_STRIP_TRAILING_WHITESPACE)
	# Read: TAG_LIST = GIT_TAG.split("-")
	STRING(REPLACE "-" ";" TAG_LIST "${GIT_TAG}")
	# Read: TAG_LIST_LENGTH = TAG_LIST.length()
	LIST(LENGTH TAG_LIST TAG_LIST_LENGTH)
	# Untagged versions contain at least 2 dashes, giving 3 strings on split.
	# Hence, for untagged versions TAG_LIST_LENGTH = [dashes in latest tag] + 3.
	# Corollary: if TAG_LIST_LENGTH <= 2, the version must be tagged.
	IF(TAG_LIST_LENGTH GREATER 0)
		# Set FORCE_VERSION to TAG_LIST[0], strip any 'v's to get MAJ.MIN.PAT
		LIST(GET TAG_LIST 0 FORCE_VERSION)
		STRING(REPLACE "v" "" FORCE_VERSION "${FORCE_VERSION}")
		# Split FORCE_VERSION on '.' and populate MAJOR/MINOR/PATCH_VERSION
		STRING(REPLACE "." ";" MAJ_MIN_PAT "${FORCE_VERSION}")
		LIST(GET MAJ_MIN_PAT 0 MAJOR_VERSION)
		LIST(GET MAJ_MIN_PAT 1 MINOR_VERSION)
		LIST(GET MAJ_MIN_PAT 2 PATCH_VERSION)
	ENDIF()
	# 1 dash total: Dash in latest tag, no additional commits => pre-release
	IF(TAG_LIST_LENGTH EQUAL 2)
		LIST(GET TAG_LIST 1 VERSION_STAGE)
		SET(FORCE_VERSION "${FORCE_VERSION}-${VERSION_STAGE}")
	# 2 dashes: Assume untagged with no dashes in latest tag name => stable + commits
	ELSEIF(TAG_LIST_LENGTH EQUAL 3)
		# Get the number of commits and latest commit hash
		LIST(GET TAG_LIST 1 EXTRA_COMMITS)
		LIST(GET TAG_LIST 2 COMMIT_HASH)
		# Bump the patch version
		MATH(EXPR PATCH_VERSION "${PATCH_VERSION}+1")
		# Set the version to MAJOR.MINOR.PATCH-EXTRA_COMMITS+COMMIT_HASH
		SET(FORCE_VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}")
		SET(FORCE_VERSION "${FORCE_VERSION}-${EXTRA_COMMITS}+${COMMIT_HASH}")
	# 3 dashes: Assume untagged with 1 dash in latest tag name => pre-release + commits
	ELSEIF(TAG_LIST_LENGTH EQUAL 4)
		# Get pre-release stage, number of commits, and latest commit hash
		LIST(GET TAG_LIST 1 VERSION_STAGE)
		LIST(GET TAG_LIST 2 EXTRA_COMMITS)
		LIST(GET TAG_LIST 3 COMMIT_HASH)
		# Set the version to MAJOR.MINOR.PATCH-VERSION_STAGE.EXTRA_COMMITS+COMMIT_HASH
		SET(FORCE_VERSION "${FORCE_VERSION}-${VERSION_STAGE}")
		SET(FORCE_VERSION "${FORCE_VERSION}.${EXTRA_COMMITS}+${COMMIT_HASH}")
	ENDIF()
ENDIF()

IF(FORCE_VERSION STREQUAL "internal")
	# Use release info from /CMakeLists.txt
ELSEIF(FORCE_VERSION)
	STRING(REPLACE "." ";" VERSION_LIST "${FORCE_VERSION}")
	LIST(LENGTH VERSION_LIST VERSION_LENGTH)
	LIST(GET VERSION_LIST 0 VERSION_MAJOR)
	LIST(GET VERSION_LIST 1 VERSION_MINOR)
	LIST(GET VERSION_LIST 2 VERSION_RELEASE)
	SET(VERSION_STAGE "")
	SET(VERSION_BUILD 0)
	IF(VERSION_LENGTH GREATER 3)
		LIST(GET VERSION_LIST 3 VERSION_BUILD)
	ENDIF()

	STRING(REPLACE "-" ";" VERSION_LIST "${VERSION_RELEASE}")
	LIST(LENGTH VERSION_LIST VERSION_LENGTH)
	IF(VERSION_LENGTH GREATER 1)
		LIST(GET VERSION_LIST 0 VERSION_RELEASE)
		LIST(GET VERSION_LIST 1 VERSION_STAGE)
	ENDIF()

	SET(VERSION             "${FORCE_VERSION}")
ELSEIF(GIT_FOUND)
	MESSAGE(
"Could not get project version.  Using release info from /CMakeLists.txt"
	)
ELSE()
	MESSAGE("Git not found.  Using release info from /CMakeLists.txt")
ENDIF()

MESSAGE("\n"
	"Configuring ${PROJECT_NAME_UCASE}\n"
	"--------------------------\n"
	"* Project version             : ${VERSION}\n"
	"*   Major version             : ${VERSION_MAJOR}\n"
	"*   Minor version             : ${VERSION_MINOR}\n"
	"*   Release version           : ${VERSION_RELEASE}\n"
	"*   Stage version             : ${VERSION_STAGE}\n"
	"*   Build version             : ${VERSION_BUILD}\n"
        "*\n\n"
	"Optional Version Usage:\n"
	"--------------------------\n"
	"*   Override version:           -DFORCE_VERSION=x.x.x-x\n"
	"*   Ignore Git information:     -DFORCE_VERSION=internal\n"
)


code:
/* Define to 1 if you have the <linux/awe_voice.h> header file. */
#cmakedefine LMMS_HAVE_LINUX_AWE_VOICE_H 1

/* Define to 1 if you have the <sys/awe_voice.h> header file. */
#cmakedefine LMMS_HAVE_SYS_AWE_VOICE_H 1

/* Define to 1 if you have the </usr/src/sys/gnu/i386/isa/sound/awe_voice.h>
   header file. */
#cmakedefine LMMS_HAVE__USR_SRC_SYS_GNU_I386_ISA_SOUND_AWE_VOICE_H 1

/* Define to 1 if you have the </usr/src/sys/i386/isa/sound/awe_voice.h>
   header file. */
#cmakedefine LMMS_HAVE__USR_SRC_SYS_I386_ISA_SOUND_AWE_VOICE_H 1

/* Define to 1 if you have the <awe_voice.h> header file. */
#cmakedefine LMMS_HAVE_AWE_VOICE_H 1

/* Define if you have libasound.so.2 (required for ALSA 0.9.x support) */
#cmakedefine LMMS_HAVE_LIBASOUND2 1

/* Define if libasound has snd_pcm_resume() */
#cmakedefine LMMS_HAVE_SND_PCM_RESUME 1

/* Define to 1 if you have the <alsa/asoundlib.h> header file. */
#cmakedefine LMMS_HAVE_ALSA_ASOUNDLIB_H 1

/* Define to 1 if you have the <sys/asoundlib.h> header file. */
#cmakedefine LMMS_HAVE_SYS_ASOUNDLIB_H 1

/* Define to 1 if you have the <sys/soundcard.h> header file. */
#cmakedefine LMMS_HAVE_SYS_SOUNDCARD_H 1

/* Define to 1 if you have the <machine/soundcard.h> header file. */
#cmakedefine LMMS_HAVE_MACHINE_SOUNDCARD_H 1


code:
#!/bin/sh
# Wrapper script for winegcc to remove .exe file ending automatically
# appended by winebuild.
# See FindWine.cmake for usage

set -e

args="$@"

# Find output name, link mode and architecture
while [ $# -gt 0 ]; do
	key="$1"

	case $key in
		-o)
			output=$2
			shift
			;;
		-c)
			no_link=true
			;;
		-m32)
			win32=true
			;;
		-m64)
			win64=true
			;;
		*)

			;;
	esac

	shift
done

if [ -z "$output" ]; then
	# If -c is used without specifying an output name, GCC defaults to "a.out".
	if [ "$no_link" != true ]; then
		output="a.out"
		no_move=true
	fi
fi

# Some Wine distributions can't find their own headers. WINE_INCLUDE_DIR provided
# by FindWine.cmake
extra_args="-I@WINE_INCLUDE_DIR@ -I@WINE_INCLUDE_DIR@/wine/windows"

# Apply manually specified flags
extra_args="$extra_args @WINE_CXX_FLAGS@"

# Apply -m32 library fix if necessary
# Additionally, apply "-z notext" to fix an inconsistency in ld.lld vs ld.bfd and ld.gold
if [ "$win32" = true ] && [ "$no_link" != true ]; then
	extra_args="$extra_args @WINE_32_FLAGS@ -z notext"
fi

# Apply -m64 library fix if necessary
if [ "$win64" = true ] && [ "$no_link" != true ]; then
	extra_args="$extra_args @WINE_64_FLAGS@"
fi

# Work around https://bugs.winehq.org/show_bug.cgi?id=47710
extra_args="$extra_args -D__WIDL_objidl_generated_name_0000000C="

# Run winegcc
export WINEBUILD=@WINE_BUILD@
@WINE_CXX@ $extra_args $args

if [ "$no_move" = true ] || [ "$no_link" = true ]; then
	exit 0
fi

if [ ! -e "$output.exe" ]; then
	echo "Fatal error in winegcc wrapper: No output file \"$output.exe\" found."
	exit 1
fi

mv $output.exe $output


code:
#!/bin/bash
set -e

ppa_dir=./ppa/

pushd $ppa_dir

for f in *.deb; do
	echo "Extracting $f..."
	ar xv "$f"
	rm debian-binary
	rm control.tar.*
	tar xf data.tar.* --exclude=*mingw*/bin/fluid
	rm data.tar.*
done

popd

echo "Your extracted files should be located in $ppa_dir"


code:
#!/bin/bash

# Trusty=14.04, Precise=12.04
PPA_DISTRO=trusty

# Architecture=i386, amd64
PPA_ARCH=amd64

# These shouldn't change
PPA_HOST=http://ppa.launchpad.net
PPA_USER=tobydox
PPA_PROJECT=mingw-x-trusty
PPA_ROOT=$PPA_HOST/$PPA_USER/$PPA_PROJECT/ubuntu

PPA_URL=$PPA_ROOT/dists/$PPA_DISTRO/main/binary-$PPA_ARCH/Packages.gz

ppa_dir=./ppa/

temp_file=/tmp/ppa_listing_$$
temp_temp_file=/tmp/ppa_listing_temp_$$

skip_files="binutils openssl flac libgig libogg libvorbis x-bootstrap zlib"
skip_files="$skip_files x-runtime gcc qt_4 qt5 x-stk pkgconfig"
skip_files="$skip_files glib2 libpng"

echo "Connecting to $PPA_URL to get list of packages..."
wget -qO- $PPA_URL | gzip -d -c | grep "Filename:" > $temp_file

for j in $skip_files ; do
	grep -v "$j" $temp_file > $temp_temp_file
	mv $temp_temp_file $temp_file
done

line_count=$(wc -l $temp_file |awk '{print $1}')

echo "Found $line_count packages for download..."

echo "Downloading packages.  They will be saved to $ppa_dir"

mkdir $ppa_dir

while read -r j
do
	echo "Downloading $j..."
	echo "$PPA_ROOT/$j"
	wget -qO "$ppa_dir$(basename "$j")" "$(echo "$PPA_ROOT/$j" | sed 's/\/Filename: /\//gi')"
done < $temp_file

echo "Cleaning up temporary files..."
rm -rf $temp_file

echo "Packages have been saved to $ppa_dir.  Please run extract_debs.sh"


code:
#!/bin/bash

set -eu

# Git repo information
fork="lmms"	# i.e. "lmms" or "tobydox"
branch="master"	# i.e. "master" or "stable-1.2"

# Console colors
red="\\x1B[1;31m"
green="\\x1B[1;32m"
yellow="\\x1B[1;33m"
plain="\\x1B[0m"

function info() { echo -e "\n${green}$1${plain}"; }
function warn() { echo -e "\n${yellow}$1${plain}"; }
function err() { echo -e "\n${red}$1${plain}"; exit 1;}

info "Checking for mingw environment"
if ! env | grep MINGW; then
	err "  - Failed. Please relaunch using MinGW shell"
fi

info "Preparing the git directory..."
mkdir "$HOME/.git" || true
touch "$HOME/.git/config" > /dev/null 2>&1
git config --global http.sslverify false

info "Cloning the repository..."
if [ -d ./lmms ]; then
	warn "  - Skipping, ./lmms already exists"
else
	git clone -b $branch https://github.com/$fork/lmms.git
fi

info "Fetching ppa using cmake/msys/fetch_ppas.sh..."
if [ -d "$HOME/ppa" ]; then
        warn "  - Skipping, $HOME/ppa already exists"
else
	lmms/cmake/msys/fetch_ppa.sh
fi

info "Extracting debs to $HOME/ppa/opt/, etc..."
if [ -d "$HOME/ppa/opt" ]; then
        warn "  - Skipping, $HOME/ppa/opt already exists"
else
        lmms/cmake/msys/extract_debs.sh
fi

info "Preparing library merge, making all qt headers writable..."
chmod u+w /mingw64/include/qt4 -R
chmod u+w /mingw32/include/qt4 -R

info "Merging mingw headers and libraries from ppa over existing system libraries..."
if ! find /mingw64 | grep sndfile.h; then
	command cp -r "$HOME/ppa/opt/mingw"* /
else
	warn "  - Skipping, sndfile.h has already been merged"
fi

fltkver="1.3.3"
oggver="1.3.2"
vorbisver="1.3.5"
flacver="1.3.2"
gigver="4.0.0"
stkver="4.5.1"

mingw_root="/$(echo "$MSYSTEM"|tr '[:upper:]' '[:lower:]')"

info "Downloading and building fltk $fltkver"
if ! command -v fluid; then
	wget http://fltk.org/pub/fltk/$fltkver/fltk-$fltkver-source.tar.gz -O "$HOME/fltk-source.tar.gz"
	tar zxf "$HOME/fltk-source.tar.gz" -C "$HOME/"
	pushd "$HOME/fltk-$fltkver"

	info "  - Compiling fltk $fltkver..."
	./configure --prefix="$mingw_root" --enable-shared
	make

	info "  - Installing fltk..."
	make install

#	ln -s $mingw_root/usr/local/bin/fluid.exe $mingw_root/bin/fluid.exe
	popd
else
	warn "  - Skipping, fluid binary already exists"
fi

info "Downloading and building libogg $oggver"
if [ ! -e "$mingw_root/lib/libogg.dll.a" ]; then
	wget http://downloads.xiph.org/releases/ogg/libogg-$oggver.tar.xz -O "$HOME/libogg-source.tar.xz"
	tar xf "$HOME/libogg-source.tar.xz" -C "$HOME/"
	pushd "$HOME/libogg-$oggver"

	info "  - Compiling libogg $oggver..."
	./configure --prefix="$mingw_root"
	make

	info "  - Installing libogg..."
	make install
	# for some reason libgig needs this
	./configure --prefix="/opt$mingw_root"
	make

	info "  - Installing libogg..."
	make install

	popd
else
	warn "  - Skipping, libogg binary already exists"
fi

info "Downloading and building libvorbis $vorbisver"
if [ ! -e "$mingw_root/lib/libvorbis.dll.a" ]; then
	wget http://downloads.xiph.org/releases/vorbis/libvorbis-$vorbisver.tar.xz -O "$HOME/libvorbis-source.tar.xz"
	tar xf "$HOME/libvorbis-source.tar.xz" -C "$HOME/"
	pushd "$HOME/libvorbis-$vorbisver"

	info "  - Compiling libvorbis $vorbisver..."
	./configure --prefix="$mingw_root"
	make

	info "  - Installing libvorbis..."
	make install

	# for some reason libgig needs this
	./configure --prefix="/opt$mingw_root"
	make
	info "  - Installing libvorbis..."
	make install

	popd
else
	warn "  - Skipping, libvorbis binary already exists"
fi

info "Downloading and building flac $flacver"

if [ ! -e "$mingw_root/lib/libFLAC.dll.a" ]; then

	wget http://downloads.xiph.org/releases/flac/flac-$flacver.tar.xz -O "$HOME/flac-source.tar.xz"
	tar xf "$HOME/flac-source.tar.xz" -C "$HOME/"
	pushd "$HOME/flac-$flacver"

	info "  - Compiling flac $flacver..."
	./configure --prefix="$mingw_root"
	make

	info "  - Installing flac..."
	make install

	# for some reason libgig needs this
	./configure --prefix="/opt$mingw_root"
	make

	info "  - Installing flac..."
	make install

	popd
else
	warn "  - Skipping, libvorbis flac already exists"
fi

info "Downloading and building libgig $gigver"

if [ ! -e "$mingw_root/lib/libgig/libgig.dll.a" ]; then
	wget http://download.linuxsampler.org/packages/libgig-$gigver.tar.bz2 -O "$HOME/gig-source.tar.xz"
	tar xf "$HOME/gig-source.tar.xz" -C "$HOME/"
	pushd "$HOME/libgig-$gigver"

	info "  - Compiling libgig $gigver..."
	./configure --prefix="$mingw_root"
	make

	info "  - Installing libgig..."
	make install

	mv "$mingw_root/lib/bin/libakai-0.dll" "$mingw_root/bin"
	mv "$mingw_root/lib/bin/libgig-7.dll" "$mingw_root/bin"

	popd
else
	warn "  - Skipping, libgig binary already exists"
fi

info "Downloading and building stk $stkver"

if [ ! -e "$mingw_root/lib/libstk.dll" ]; then
	wget http://ccrma.stanford.edu/software/stk/release/stk-$stkver.tar.gz -O "$HOME/stk-source.tar.xz"
	tar xf "$HOME/stk-source.tar.xz" -C "$HOME/"
	pushd "$HOME/stk-$stkver"

	info "  - Compiling stk $stkver..."
	./configure --prefix="$mingw_root"
	make

	info "  - Installing stk..."
	make install

	mv "$mingw_root/lib/libstk.so" "$mingw_root/lib/libstk.dll"
	mv "$mingw_root/lib/libstk-$stkver.so" "$mingw_root/lib/libstk-$stkver.dll"

	popd
else
	warn "  - Skipping, stk binary already exists"
fi

# make a symlink to make cmake happy
if [ "$mingw_root" = "/mingw64" ]; then
	if [ ! -e /opt/mingw64/bin/x86_64-w64-mingw32-pkg-config ]; then
		ln -s /usr/bin/pkg-config /opt/mingw64/bin/x86_64-w64-mingw32-pkg-config
	fi
elif [ "$mingw_root" = "/mingw32" ]; then
	if [ ! -e /opt/mingw32/bin/i686-w64-mingw32-pkg-config ]; then
		ln -s /usr/bin/pkg-config /opt/mingw32/bin/i686-w64-mingw32-pkg-config
	fi
fi

info "Cleaning up..."
rm -rf "$HOME/fltk-$fltkver"
rm -rf "$HOME/libogg-$oggver"
rm -rf "$HOME/libvorbis-$vorbisver"
rm -rf "$HOME/flac-$flacver"
rm -rf "$HOME/libgig-$gigver"
rm -rf "$HOME/stk-$stkver"
info "Done."


code:
SET(WIN_PLATFORM mingw)
if(LMMS_MSVC_YEAR)
	SET(WIN_PLATFORM "msvc${LMMS_MSVC_YEAR}")
endif()

SET(CPACK_PACKAGE_ICON                  "${CMAKE_SOURCE_DIR}/cmake/nsis/nsis_branding.bmp")
IF(MSVC)
	STRING(REPLACE "/" "\\\\" CPACK_PACKAGE_ICON ${CPACK_PACKAGE_ICON})
ENDIF(MSVC)
SET(CPACK_NSIS_MUI_ICON                 "${CMAKE_SOURCE_DIR}/cmake/nsis/icon.ico")
SET(CPACK_NSIS_INSTALLED_ICON_NAME      "${CMAKE_PROJECT_NAME}.exe" PARENT_SCOPE)
SET(CPACK_NSIS_DISPLAY_NAME             "${PROJECT_NAME_UCASE} ${VERSION}" PARENT_SCOPE)
SET(CPACK_NSIS_HELP_LINK                "${PROJECT_URL}" PARENT_SCOPE)
SET(CPACK_NSIS_URL_INFO_ABOUT           "${PROJECT_URL}" PARENT_SCOPE)
SET(CPACK_NSIS_CONTACT                  "${PROJECT_EMAIL}" PARENT_SCOPE)
SET(CPACK_PACKAGE_EXECUTABLES           "${CMAKE_PROJECT_NAME}.exe;${PROJECT_NAME_UCASE}" PARENT_SCOPE)
SET(CPACK_NSIS_MENU_LINKS               "${CMAKE_PROJECT_NAME}.exe;${PROJECT_NAME_UCASE}" PARENT_SCOPE)
SET(CPACK_NSIS_DEFINES                  "
  !addincludedir ${CMAKE_SOURCE_DIR}/cmake/nsis
  !include FileAssociation.nsh
  !include LogicLib.nsh
  !include WinVer.nsh")
SET(CPACK_PACKAGE_FILE_NAME             "${CMAKE_PROJECT_NAME}-${VERSION}-${WIN_PLATFORM}-win32")
SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS   "
  \\\${registerExtension} \\\"$INSTDIR\\\\${CMAKE_PROJECT_NAME}.exe\\\" \\\".mmp\\\" \\\"${PROJECT_NAME_UCASE} Project\\\"
  \\\${registerExtension} \\\"$INSTDIR\\\\${CMAKE_PROJECT_NAME}.exe\\\" \\\".mmpz\\\" \\\"${PROJECT_NAME_UCASE} Project (compressed)\\\"
  \\\${IfNot} \\\${AtMostWin7}
    WriteRegDWORD HKLM \\\"Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\SideBySide\\\" \\\"PreferExternalManifest\\\" \\\"1\\\"
  \\\${EndIf}
  " PARENT_SCOPE)
SET(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "
  \\\${unregisterExtension} \\\".mmp\\\" \\\"${PROJECT_NAME_UCASE} Project\\\"
  \\\${unregisterExtension} \\\".mmpz\\\" \\\"${PROJECT_NAME_UCASE} Project (compressed)\\\"
  DeleteRegKey HKCR \\\"${PROJECT_NAME_UCASE} Project\\\"
  DeleteRegKey HKCR \\\"${PROJECT_NAME_UCASE} Project (compressed)\\\"
  " PARENT_SCOPE)

IF(WIN64)
	SET(CPACK_PACKAGE_FILE_NAME      "${CMAKE_PROJECT_NAME}-${VERSION}-${WIN_PLATFORM}-win64")
	SET(CPACK_INSTALL_FIX "$PROGRAMFILES64\\\\${CPACK_PACKAGE_INSTALL_DIRECTORY}\\\\")
	SET(CPACK_NSIS_DEFINES "
		${CPACK_NSIS_DEFINES}
		InstallDir ${CPACK_INSTALL_FIX}
		")
ENDIF()

# Fix windows paths for msys
IF(LMMS_BUILD_MSYS)
	STRING(REPLACE "/" "\\\\" CPACK_PACKAGE_ICON "${CPACK_PACKAGE_ICON}")
	STRING(REPLACE "/" "\\\\" CPACK_NSIS_MUI_ICON "${CPACK_NSIS_MUI_ICON}")
	STRING(REPLACE "/" "\\\\" CPACK_NSIS_DEFINES "${CPACK_NSIS_DEFINES}")
	STRING(REPLACE "/" "\\\\" CMAKE_BINARY_DIR_FIX "${CMAKE_BINARY_DIR}")

	# FIXME: there's no easy way to fix $INST_DIR, so we'll redefine it manually
	IF(WIN64)
		SET(NSIS_ARCH "win64")
	ELSE()
		SET(NSIS_ARCH "win32")
	ENDIF()
	SET(CPACK_NSIS_DEFINES "
		${CPACK_NSIS_DEFINES}
		!define /redef INST_DIR ${CMAKE_BINARY_DIR_FIX}\\\\_CPack_Packages\\\\${NSIS_ARCH}\\\\NSIS\\\\${CPACK_PACKAGE_FILE_NAME}
	")
ENDIF()

# Setup missing parent scopes
SET(CPACK_PACKAGE_FILE_NAME             "${CPACK_PACKAGE_FILE_NAME}" PARENT_SCOPE)
SET(CPACK_NSIS_DEFINES                  "${CPACK_NSIS_DEFINES}" PARENT_SCOPE)
SET(CPACK_PACKAGE_ICON                  "${CPACK_PACKAGE_ICON}" PARENT_SCOPE)
SET(CPACK_NSIS_MUI_ICON                 "${CPACK_NSIS_MUI_ICON}" PARENT_SCOPE)

# Windows resource compilers
CONFIGURE_FILE("lmms.rc.in"             "${CMAKE_BINARY_DIR}/lmms.rc")
CONFIGURE_FILE("zynaddsubfx.rc.in"      "${CMAKE_BINARY_DIR}/plugins/zynaddsubfx/zynaddsubfx.rc")

IF(LMMS_HAVE_STK)
	FILE(GLOB RAWWAVES "${MINGW_PREFIX}/share/stk/rawwaves/*.raw")
	LIST(SORT RAWWAVES)
	INSTALL(FILES ${RAWWAVES} DESTINATION "${DATA_DIR}/stk/rawwaves")
ENDIF()

INSTALL(FILES "lmms.exe.manifest" DESTINATION .)
INSTALL(FILES "lmms.VisualElementsManifest.xml" DESTINATION .)
INSTALL(DIRECTORY "assets" DESTINATION .)


code:
/*
_____________________________________________________________________________

                       File Association
_____________________________________________________________________________

 Based on code taken from http://nsis.sourceforge.net/File_Association

 Usage in script:
 1. !include "FileAssociation.nsh"
 2. [Section|Function]
      ${FileAssociationFunction} "Param1" "Param2" "..." $var
    [SectionEnd|FunctionEnd]

 FileAssociationFunction=[RegisterExtension|UnRegisterExtension]

_____________________________________________________________________________

 ${RegisterExtension} "[executable]" "[extension]" "[description]"

"[executable]"     ; executable which opens the file format
                   ;
"[extension]"      ; extension, which represents the file format to open
                   ;
"[description]"    ; description for the extension. This will be display in Windows Explorer.
                   ;

 ${UnRegisterExtension} "[extension]" "[description]"

"[extension]"      ; extension, which represents the file format to open
                   ;
"[description]"    ; description for the extension. This will be display in Windows Explorer.
                   ;

_____________________________________________________________________________

                         Macros
_____________________________________________________________________________

 Change log window verbosity (default: 3=no script)

 Example:
 !include "FileAssociation.nsh"
 !insertmacro RegisterExtension
 ${FileAssociation_VERBOSE} 4   # all verbosity
 !insertmacro UnRegisterExtension
 ${FileAssociation_VERBOSE} 3   # no script
*/

!ifndef FileAssociation_INCLUDED
!define FileAssociation_INCLUDED

!include Util.nsh

!verbose push
!verbose 3
!ifndef _FileAssociation_VERBOSE
  !define _FileAssociation_VERBOSE 3
!endif
!verbose ${_FileAssociation_VERBOSE}
!define FileAssociation_VERBOSE `!insertmacro FileAssociation_VERBOSE`
!verbose pop

!macro FileAssociation_VERBOSE _VERBOSE
  !verbose push
  !verbose 3
  !undef _FileAssociation_VERBOSE
  !define _FileAssociation_VERBOSE ${_VERBOSE}
  !verbose pop
!macroend

!macro RegisterExtensionCall _EXECUTABLE _EXTENSION _DESCRIPTION
  !verbose push
  !verbose ${_FileAssociation_VERBOSE}
  Push `${_DESCRIPTION}`
  Push `${_EXTENSION}`
  Push `${_EXECUTABLE}`
  ${CallArtificialFunction} RegisterExtension_
  !verbose pop
!macroend

!macro UnRegisterExtensionCall _EXTENSION _DESCRIPTION
  !verbose push
  !verbose ${_FileAssociation_VERBOSE}
  Push `${_EXTENSION}`
  Push `${_DESCRIPTION}`
  ${CallArtificialFunction} UnRegisterExtension_
  !verbose pop
!macroend

!define RegisterExtension `!insertmacro RegisterExtensionCall`
!define un.RegisterExtension `!insertmacro RegisterExtensionCall`

!macro RegisterExtension
!macroend

!macro un.RegisterExtension
!macroend

!macro RegisterExtension_
  !verbose push
  !verbose ${_FileAssociation_VERBOSE}

  Exch $R2 ;exe
  Exch
  Exch $R1 ;ext
  Exch
  Exch 2
  Exch $R0 ;desc
  Exch 2
  Push $0
  Push $1

  ReadRegStr $1 HKCR $R1 ""  ; read current file association
  StrCmp "$1" "" NoBackup  ; is it empty
  StrCmp "$1" "$R0" NoBackup  ; is it our own
    WriteRegStr HKCR $R1 "backup_val" "$1"  ; backup current value
NoBackup:
  WriteRegStr HKCR $R1 "" "$R0"  ; set our file association

  ReadRegStr $0 HKCR $R0 ""
  StrCmp $0 "" 0 Skip
    WriteRegStr HKCR "$R0" "" "$R0"
    WriteRegStr HKCR "$R0\shell" "" "open"
Skip:
  WriteRegStr HKCR "$R0\DefaultIcon" "" "$R2,1"
  WriteRegStr HKCR "$R0\shell\open\command" "" '"$R2" "%1"'
  WriteRegStr HKCR "$R0\shell\edit" "" "Edit $R0"
  WriteRegStr HKCR "$R0\shell\edit\command" "" '"$R2" "%1"'

  Pop $1
  Pop $0
  Pop $R2
  Pop $R1
  Pop $R0

  !verbose pop
!macroend

!define UnRegisterExtension `!insertmacro UnRegisterExtensionCall`
!define un.UnRegisterExtension `!insertmacro UnRegisterExtensionCall`

!macro UnRegisterExtension
!macroend

!macro un.UnRegisterExtension
!macroend

!macro UnRegisterExtension_
  !verbose push
  !verbose ${_FileAssociation_VERBOSE}

  Exch $R1 ;desc
  Exch
  Exch $R0 ;ext
  Exch
  Push $0
  Push $1

  ReadRegStr $1 HKCR $R0 ""
  StrCmp $1 $R1 0 NoOwn ; only do this if we own it
  ReadRegStr $1 HKCR $R0 "backup_val"
  StrCmp $1 "" 0 Restore ; if backup="" then delete the whole key
  DeleteRegKey HKCR $R0
  Goto NoOwn

Restore:
  WriteRegStr HKCR $R0 "" $1
  DeleteRegValue HKCR $R0 "backup_val"
  DeleteRegKey HKCR $R1 ;Delete key with association name settings

NoOwn:

  Pop $1
  Pop $0
  Pop $R1
  Pop $R0

  !verbose pop
!macroend

!endif # !FileAssociation_INCLUDED


code:
<Application xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
  <VisualElements
      ShowNameOnSquare150x150Logo='on'
      Square150x150Logo='assets\Logo.png'
      Square70x70Logo='assets\SmallLogo.png'
      Square44x44Logo='assets\SmallLogo.png'
      ForegroundText='light'
      BackgroundColor='#249A57'/>
</Application>


code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv3:application>
    <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
        <ms_windowsSettings:dpiAware xmlns:ms_windowsSettings="http://schemas.microsoft.com/SMI/2005/WindowsSettings">false</ms_windowsSettings:dpiAware>
    </asmv3:windowsSettings>
</asmv3:application>
</assembly>


code:
lmmsicon ICON cmake/nsis/icon.ico
lmmsprojecticon ICON cmake/nsis/project.ico
#include <windows.h>

VS_VERSION_INFO VERSIONINFO
  FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
  FILEOS        VOS_NT_WINDOWS32
  FILETYPE      VFT_APP
  FILESUBTYPE   VFT2_UNKNOWN
BEGIN
  BLOCK "StringFileInfo"
  BEGIN
    BLOCK "040904E4"
    //language ID = U.S. English, charset = Windows, Multilingual
    BEGIN
      VALUE "Comments",         "${PROJECT_URL}\0"
      VALUE "CompanyName",      "${PROJECT_AUTHOR}\0"
      VALUE "FileDescription",  "${PROJECT_NAME_UCASE}\0"
      VALUE "FileVersion",      "@VERSION@\0"
      VALUE "LegalCopyright",   "Copyright (c) ${PROJECT_COPYRIGHT}\0"
      VALUE "OriginalFilename", "${CMAKE_PROJECT_NAME}.exe\0"
      VALUE "ProductName",      "${PROJECT_NAME_UCASE}\0"
      VALUE "ProductVersion",   "@VERSION@\0"
    END
  END
END


code:
zynaddsubfx_icon ICON zynaddsubfx/zynaddsubfx.ico
#include <windows.h>

VS_VERSION_INFO	VERSIONINFO
  FILEVERSION   0,2,3,0
  FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
  FILEOS        VOS_NT_WINDOWS32
  FILETYPE      VFT_APP
  FILESUBTYPE   VFT2_UNKNOWN
BEGIN
  BLOCK "StringFileInfo"
  BEGIN
    BLOCK "040904E4"
    //language ID = U.S. English, charset = Windows, Multilingual
    BEGIN
      VALUE "Comments",         "ZynAddSubFX Plugin - ${PROJECT_NAME_UCASE} (${PROJECT_URL})\0"
      VALUE "CompanyName",      "${PROJECT_AUTHOR}\0"
      VALUE "FileDescription",  "ZynAddSubFX ${PROJECT_NAME_UCASE} Plugin\0"
      VALUE "FileVersion",      "2.3.0/@VERSION@\0"
      VALUE "LegalCopyright",   "Copyright (c) Nasca Octavian Paul, Mark McCurry, Harald Hvaal, Tobias Doerffel\0"
      VALUE "OriginalFilename", "RemoteZynAddSubFx.exe\0"
      VALUE "ProductName",      "ZynAddSubFX/${PROJECT_NAME_UCASE}\0"
      VALUE "ProductVersion",   "2.3.0/@VERSION@\0"
    END
  END
END


code:
# GenQrcScript.cmake - Copyright (c) 2015 Lukas W <lukaswhl/at/gmail.com>

INCLUDE(CMakeParseArguments)

FILE(REMOVE ${OUT_FILE})
MACRO(OUT STRING)
	FILE(APPEND ${OUT_FILE} "${STRING}\n")
ENDMACRO()

IF(NOT DEFINED RC_PREFIX)
	SET(RC_PREFIX "/")
ENDIF()

# Write qrc file
OUT("<RCC>")
OUT("	<qresource prefix=\"${RC_PREFIX}\">")
FOREACH(VAR ${FILES})
	GET_FILENAME_COMPONENT(FILENAME ${VAR} NAME)
	IF(IS_ABSOLUTE ${VAR})
		OUT("		<file alias=\"${FILENAME}\">${VAR}</file>")
	ELSE()
		OUT("		<file alias=\"${FILENAME}\">${DIR}/${VAR}</file>")
	ENDIF()
ENDFOREACH()
OUT("	</qresource>")
OUT("</RCC>")


code:
INCLUDE(${CMAKE_CURRENT_LIST_DIR}/common/MSYS.cmake)
INCLUDE(${CMAKE_CURRENT_LIST_DIR}/common/Win32.cmake)

SET(MINGW_PREFIX                /mingw32)


code:
INCLUDE(${CMAKE_CURRENT_LIST_DIR}/common/MSYS.cmake)
INCLUDE(${CMAKE_CURRENT_LIST_DIR}/common/Win64.cmake)

SET(MINGW_PREFIX                /mingw64)
SET(MINGW_PREFIX32              /mingw32)


code:
SET(CMAKE_TOOLCHAIN_FILE_32			"${CMAKE_CURRENT_LIST_DIR}/Ubuntu-MinGW-W64-32.cmake")

INCLUDE(${CMAKE_CURRENT_LIST_DIR}/common/Win64.cmake)
INCLUDE(${CMAKE_CURRENT_LIST_DIR}/common/Ubuntu-MinGW-W64.cmake)


code:
SET(MINGW_PREFIX           /opt/mingw32)

INCLUDE(${CMAKE_CURRENT_LIST_DIR}/common/Ubuntu-MinGW-X-Trusty.cmake)


code:
SET(MINGW_PREFIX   /opt/mingw64)
SET(MINGW_PREFIX32 /opt/mingw32)

SET(WIN64          TRUE)

SET(CMAKE_TOOLCHAIN_FILE_32			"${CMAKE_CURRENT_LIST_DIR}/Ubuntu-MinGW-X-Trusty-32.cmake")
SET(CMAKE_PREFIX_PATH_32			"${MINGW_PREFIX32}")

INCLUDE(${CMAKE_CURRENT_LIST_DIR}/common/Ubuntu-MinGW-X-Trusty.cmake)


code:
# The target environment
SET(CMAKE_FIND_ROOT_PATH            ${MINGW_PREFIX})
SET(CMAKE_INSTALL_PREFIX            ${MINGW_PREFIX})

# Windows msys mingw ships with a mostly-suitable preconfigured environment
SET(STRIP                       ${MINGW_PREFIX}/bin/strip)
SET(CMAKE_RC_COMPILER           ${MINGW_PREFIX}/bin/windres)
SET(CMAKE_C_COMPILER            ${MINGW_PREFIX}/bin/gcc)
SET(CMAKE_CXX_COMPILER          ${MINGW_PREFIX}/bin/g++)

# For 32-bit vst support
IF(WIN64)
	# Specify the 32-bit cross compiler
	SET(CMAKE_C_COMPILER32      ${MINGW_PREFIX32}/bin/gcc)
	SET(CMAKE_CXX_COMPILER32    ${MINGW_PREFIX32}/bin/g++)
ENDIF()

# Msys compiler does not support @CMakeFiles/Include syntax
SET(CMAKE_C_USE_RESPONSE_FILE_FOR_INCLUDES   OFF)
SET(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES OFF)

SET(LMMS_BUILD_MSYS 1)


code:
# Toolchain for Ubuntu MinGw compiler shipped with the mingw-w64 and
# g++-mingw-w64 packages
SET(TOOLCHAIN_PREFIX      ${CMAKE_SYSTEM_PROCESSOR}-w64-mingw32)
set(CMAKE_C_COMPILER      ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER    ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_RC_COMPILER     ${TOOLCHAIN_PREFIX}-windres)

set(CMAKE_FIND_ROOT_PATH  /usr/${TOOLCHAIN_PREFIX})
SET(ENV{PKG_CONFIG}       /usr/bin/${TOOLCHAIN_PREFIX}-pkg-config)

IF(WIN64)
	SET(TOOLCHAIN_PREFIX32   ${CMAKE_SYSTEM_PROCESSOR32}-w64-mingw32)
	SET(CMAKE_C_COMPILER32   ${TOOLCHAIN_PREFIX32}-gcc)
	SET(CMAKE_CXX_COMPILER32 ${TOOLCHAIN_PREFIX32}-g++)
ENDIF()

INCLUDE(${CMAKE_CURRENT_LIST_DIR}/WinCrossCompile.cmake)


code:
IF(WIN64)
	INCLUDE(${CMAKE_CURRENT_LIST_DIR}/Win64.cmake)
ELSE()
	INCLUDE(${CMAKE_CURRENT_LIST_DIR}/Win32.cmake)
ENDIF()
INCLUDE(${CMAKE_CURRENT_LIST_DIR}/WinCrossCompile.cmake)

# The target environment
SET(CMAKE_FIND_ROOT_PATH            ${MINGW_PREFIX})
SET(CMAKE_INSTALL_PREFIX            ${MINGW_PREFIX})

# Linux mingw requires explicitly defined tools to prevent clash with native system tools
SET(MINGW_TOOL_PREFIX           ${MINGW_PREFIX}/bin/${CMAKE_SYSTEM_PROCESSOR}-w64-mingw32-)

# Specify the cross compiler
SET(CMAKE_C_COMPILER            ${MINGW_TOOL_PREFIX}gcc)
SET(CMAKE_CXX_COMPILER          ${MINGW_TOOL_PREFIX}g++)
SET(CMAKE_RC_COMPILER           ${MINGW_TOOL_PREFIX}windres)

# Mingw tools
SET(STRIP                       ${MINGW_TOOL_PREFIX}strip)
SET(ENV{PKG_CONFIG}             ${MINGW_TOOL_PREFIX}pkg-config)

# For 32-bit vst support
IF(WIN64)
	# Specify the 32-bit cross compiler
	SET(MINGW_TOOL_PREFIX32     ${MINGW_PREFIX32}/bin/${CMAKE_SYSTEM_PROCESSOR32}-w64-mingw32-)
	SET(CMAKE_C_COMPILER32      ${MINGW_TOOL_PREFIX32}gcc)
	SET(CMAKE_CXX_COMPILER32    ${MINGW_TOOL_PREFIX32}g++)
ENDIF()

INCLUDE_DIRECTORIES(${MINGW_PREFIX}/include)

LINK_DIRECTORIES(${MINGW_PREFIX}/lib ${MINGW_PREFIX}/bin)

# Qt tools
SET(QT_BINARY_DIR				    ${MINGW_PREFIX}/bin)
SET(QT_QMAKE_EXECUTABLE			    ${QT_BINARY_DIR}/qmake)

# Echo modified cmake vars to screen for debugging purposes
IF(NOT DEFINED ENV{MINGW_DEBUG_INFO})
	MESSAGE("")
	MESSAGE("Custom cmake vars: (blank = system default)")
	MESSAGE("-----------------------------------------")
	MESSAGE("* CMAKE_C_COMPILER                     : ${CMAKE_C_COMPILER}")
	MESSAGE("* CMAKE_CXX_COMPILER                   : ${CMAKE_CXX_COMPILER}")
	MESSAGE("* CMAKE_RC_COMPILER                    : ${CMAKE_RC_COMPILER}")
	MESSAGE("* ENV{PKG_CONFIG}                      : $ENV{PKG_CONFIG}")
	MESSAGE("* MINGW_TOOL_PREFIX32                  : ${MINGW_TOOL_PREFIX32}")
	MESSAGE("* CMAKE_C_COMPILER32                   : ${CMAKE_C_COMPILER32}")
	MESSAGE("* CMAKE_CXX_COMPILER32                 : ${CMAKE_CXX_COMPILER32}")
	MESSAGE("* STRIP                                : ${STRIP}")
	MESSAGE("* QT_BINARY_DIR                        : ${QT_BINARY_DIR}")
	MESSAGE("* QT_QMAKE_EXECUTABLE                  : ${QT_QMAKE_EXECUTABLE}")
	MESSAGE("")
	# So that the debug info only appears once
	SET(ENV{MINGW_DEBUG_INFO} SHOWN)
ENDIF()


code:
SET(CMAKE_SYSTEM_NAME        Windows)
SET(CMAKE_SYSTEM_VERSION     1)

SET(CMAKE_SYSTEM_PROCESSOR   i686)

SET(WIN64                    FALSE)


code:
SET(CMAKE_SYSTEM_NAME        Windows)
SET(CMAKE_SYSTEM_VERSION     1)

SET(CMAKE_SYSTEM_PROCESSOR          x86_64)
SET(CMAKE_SYSTEM_PROCESSOR32        i686)

SET(WIN64                           TRUE)


code:
# Required by cmake if `uname -s` is inadaquate
SET(CMAKE_SYSTEM_NAME               Windows)
SET(CMAKE_SYSTEM_VERSION            1)

# Search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# For libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)


code:
CMAKE_MINIMUM_REQUIRED(VERSION 3.3)

MESSAGE(STATUS "Attempting to create uninstall target for make")

#Remove all of the files listed in install_manifest.txt
SET(INSTALL_MANIFEST_PATH "${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt")
IF(NOT EXISTS ${INSTALL_MANIFEST_PATH})
	MESSAGE(FATAL_ERROR "Could not find install manifest at ${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt\nThis may be because 'make install' has not been run or install_manifest.txt has been deleted")
ENDIF()
MESSAGE(STATUS "install_manifest.txt found")
FILE(STRINGS ${INSTALL_MANIFEST_PATH} FILES_TO_REMOVE)
FOREACH(FILE_TO_REMOVE ${FILES_TO_REMOVE})
	IF(NOT EXISTS "${FILE_TO_REMOVE}")
		MESSAGE(WARNING "Could not find file ${FILE_TO_REMOVE}")
		CONTINUE()
	ENDIF()

	FILE(REMOVE "${FILE_TO_REMOVE}")
	IF(NOT EXISTS "${FILE_TO_REMOVE}")
		MESSAGE(STATUS "Successfully removed file ${FILE_TO_REMOVE}")
	ELSE()
		MESSAGE(FATAL_ERROR "Failed to remove file ${FILE_TO_REMOVE}.")
	ENDIF()
ENDFOREACH(FILE_TO_REMOVE)

# Remove empty directories created during installation

# Checks if a directory is empty and saves the result in out_var
FUNCTION(IS_EMPTY_DIR OUT_VAR DIR)
	FILE(GLOB FILES "${DIR}/*")
	LIST(LENGTH FILES NUM_FILES)
	IF(NUM_FILES EQUAL 0)
		SET(${OUT_VAR} TRUE PARENT_SCOPE)
	ELSE()
		SET(${OUT_VAR} FALSE PARENT_SCOPE)
	ENDIF()
ENDFUNCTION()

# Recursively append all parent directories of path to out_var
FUNCTION(PARENT_DIRECTORIES OUT_VAR PATH)
	GET_FILENAME_COMPONENT(PARENT "${PATH}" DIRECTORY)
	IF(PARENT AND NOT PARENT STREQUAL PATH AND NOT PARENT IN_LIST ${OUT_VAR})
		LIST(APPEND ${OUT_VAR} ${PARENT})
		PARENT_DIRECTORIES(${OUT_VAR} "${PARENT}")
	ENDIF()
	SET(${OUT_VAR} ${${OUT_VAR}} PARENT_SCOPE)
ENDFUNCTION()

# Removes all empty parent directories of the given files
FUNCTION(REMOVE_EMPTY_DIRECTORIES FILES)
	SET(DIRECTORIES)
	FOREACH(FILE_TO_REMOVE ${FILES})
		PARENT_DIRECTORIES(DIRECTORIES "${FILE_TO_REMOVE}")
	endforeach()
	LIST(REMOVE_DUPLICATES DIRECTORIES)
	# Sort and reverse so we remove subdirectories first
	LIST(SORT DIRECTORIES)
	LIST(REVERSE DIRECTORIES)

	FOREACH(DIR ${DIRECTORIES})
		# Skip directories not inside the install prefix
		IF(NOT (EXISTS "${DIR}" AND DIR MATCHES "^${CMAKE_INSTALL_PREFIX}/"))
			CONTINUE()
		ENDIF()

		IS_EMPTY_DIR(DIR_EMPTY "${DIR}")
		IF(DIR_EMPTY)
			MESSAGE(STATUS "Removing empty directory ${DIR}")
			FILE(REMOVE_RECURSE "${DIR}")
		ELSEIF()
			MESSAGE(STATUS "Skipping non-empty directory ${DIR}")
		ENDIF()
	ENDFOREACH()
ENDFUNCTION()

REMOVE_EMPTY_DIRECTORIES("${FILES_TO_REMOVE}")


code:
ADD_SUBDIRECTORY(backgrounds)
ADD_SUBDIRECTORY(locale)
ADD_SUBDIRECTORY(presets)
ADD_SUBDIRECTORY(projects)
ADD_SUBDIRECTORY(samples)
ADD_SUBDIRECTORY(themes)
ADD_SUBDIRECTORY(wavetables)


code:
FILE(GLOB PNG_FILES *.png)
LIST(SORT PNG_FILES)
INSTALL(FILES ${PNG_FILES} DESTINATION "${LMMS_DATA_DIR}/backgrounds")


code:
SET(QT_LUPDATE_EXECUTABLE "${Qt5_LUPDATE_EXECUTABLE}")
SET(QT_LRELEASE_EXECUTABLE "${Qt5_LRELEASE_EXECUTABLE}")

IF(QT_LUPDATE_EXECUTABLE STREQUAL "")
	EXECUTE_PROCESS(COMMAND "lupdate" "-help" RESULT_VARIABLE LUPDATE_FALLBACK OUTPUT_QUIET)
	IF(LUPDATE_FALLBACK EQUAL 0)
        	SET(QT_LUPDATE_EXECUTABLE lupdate)
        	SET(QT_LRELEASE_EXECUTABLE lrelease)
	ELSE()
		MESSAGE(WARNING "Cannot generate locales")
		RETURN()
	ENDIF()
ENDIF()

#
# rules for building localizations
#
SET(ts_targets "")
SET(qm_targets "")
SET(QM_FILES "")

FILE(GLOB lmms_LOCALES ${CMAKE_CURRENT_SOURCE_DIR}/*.ts)
LIST(SORT lmms_LOCALES)
FOREACH(_ts_file ${lmms_LOCALES})
	GET_FILENAME_COMPONENT(_ts_target "${_ts_file}" NAME)
	STRING(REPLACE ".ts" ".qm" _qm_file "${_ts_file}")
	STRING(REPLACE ".ts" ".qm" _qm_target "${_ts_target}")
	ADD_CUSTOM_TARGET(${_ts_target}
		COMMAND "${QT_LUPDATE_EXECUTABLE}" -locations none -no-obsolete -I ${CMAKE_SOURCE_DIR}/include/ ${LMMS_SRCS}  ${LMMS_UIS} ${CMAKE_SOURCE_DIR}/plugins  -ts "\"${_ts_file}\""
		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
	ADD_CUSTOM_TARGET(${_qm_target}
		COMMAND "${QT_LRELEASE_EXECUTABLE}" "${_ts_file}" -qm "${_qm_file}"
		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
	LIST(APPEND ts_targets "${_ts_target}")
	LIST(APPEND qm_targets "${_qm_target}")
	LIST(APPEND QM_FILES "${_qm_file}")
ENDFOREACH(_ts_file ${lmms_LOCALES})

ADD_CUSTOM_TARGET(update-locales)
FOREACH(_item ${ts_targets})
	ADD_DEPENDENCIES(update-locales "${_item}")
ENDFOREACH(_item ${ts_targets})

ADD_CUSTOM_TARGET(finalize-locales ALL)
FOREACH(_item ${qm_targets})
	ADD_DEPENDENCIES(finalize-locales "${_item}")
ENDFOREACH(_item ${qm_targets})

IF(BUNDLE_QT_TRANSLATIONS)
	FILE(GLOB QT_QM_FILES "${QT_TRANSLATIONS_DIR}/qt*.qm")
	LIST(SORT QT_QM_FILES)
ENDIF()

INSTALL(FILES ${QM_FILES} ${QT_QM_FILES} DESTINATION "${LMMS_DATA_DIR}/locale")