MESSAGE(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
MESSAGE(STATUS "AVIDEMUX_INSTALL_DIR: ${AVIDEMUX_INSTALL_DIR}")

IF(WIN32)
  IF(NOT AVIDEMUX_INSTALL_DIR)
    MESSAGE(FATAL_ERROR "Please define AVIDEMUX_INSTALL_DIR using -DAVIDEMUX_INSTALL_DIR=foobar")
  ENDIF()

  SET(AVIDEMUX_BIN_DIR ${AVIDEMUX_INSTALL_DIR})
  SET(AVIDEMUX_LIB_DIR ${AVIDEMUX_INSTALL_DIR})
  SET(AVIDEMUX_RELATIVE_LIB_DIR "")
ELSE()
  # Unix
  IF(NOT AVIDEMUX_INSTALL_DIR)
    SET(AVIDEMUX_INSTALL_DIR "/usr/local")
    MESSAGE(STATUS "No install dir provided, using /usr/local")
  ENDIF()
  SET(AVIDEMUX_BIN_DIR ${AVIDEMUX_INSTALL_DIR}/bin)
  #if we are running debian/ubuntu (assuming 64bits)
  IF(EXISTS "/etc/debian_version" AND CMAKE_LIBRARY_ARCHITECTURE)
    SET(AVIDEMUX_RELATIVE_LIB_DIR "/lib/${CMAKE_LIBRARY_ARCHITECTURE}")
  ELSE()
    IF(CMAKE_C_IMPLICIT_LINK_DIRECTORIES MATCHES "\\/lib64([; ]|$)")
      SET(AVIDEMUX_RELATIVE_LIB_DIR lib64)
    ELSEIF(CMAKE_C_IMPLICIT_LINK_DIRECTORIES MATCHES "\\/lib32([; ]|$)")
      SET(AVIDEMUX_RELATIVE_LIB_DIR lib32)
    ELSE()
      SET(AVIDEMUX_RELATIVE_LIB_DIR lib)
    ENDIF()
  ENDIF()
  SET(AVIDEMUX_LIB_DIR ${AVIDEMUX_INSTALL_DIR}/${AVIDEMUX_RELATIVE_LIB_DIR})
ENDIF()
SET(AVIDEMUX_INSTALL_INCLUDE_DIR ${AVIDEMUX_INSTALL_DIR}/include)
#
IF(NOT FAKEROOT)
  SET(AVIDEMUX_FAKEROOT "")
ELSE()
  SET(AVIDEMUX_FAKEROOT "${FAKEROOT}/")
ENDIF()
SET(AVIDEMUX_SEARCH_INCLUDE_DIR ${AVIDEMUX_FAKEROOT}${AVIDEMUX_INSTALL_INCLUDE_DIR})
SET(AVIDEMUX_SEARCH_LIB_DIR     ${AVIDEMUX_FAKEROOT}${AVIDEMUX_LIB_DIR})
#
MESSAGE(STATUS "FAKEROOT       : ${AVIDEMUX_FAKEROOT}")
MESSAGE(STATUS "AVIDEMUX_BIN_DIR     : ${AVIDEMUX_BIN_DIR}")
MESSAGE(STATUS "AVIDEMUX_LIB_DIR     : ${AVIDEMUX_LIB_DIR}")
MESSAGE(STATUS "AVIDEMUX_INSTALL_INCLUDE_DIR       : ${AVIDEMUX_INSTALL_INCLUDE_DIR}")
MESSAGE(STATUS "AVIDEMUX_SEARCH_INCLUDE_DIR: ${AVIDEMUX_SEARCH_INCLUDE_DIR}")
MESSAGE(STATUS "AVIDEMUX_SEARCH_LIB_DIR    : ${AVIDEMUX_SEARCH_LIB_DIR}")
#
# MACRO TO INSTALL REGULAR LIBS
#
MACRO(ADM_INSTALL_LIB lib)
  INSTALL(TARGETS ${lib} RUNTIME
    DESTINATION ${AVIDEMUX_BIN_DIR}    COMPONENT runtime
    LIBRARY DESTINATION ${AVIDEMUX_LIB_DIR}  COMPONENT runtime
    ARCHIVE DESTINATION ${AVIDEMUX_LIB_DIR}  COMPONENT dev
  )
ENDMACRO()

MACRO(ADM_INSTALL_LIB_FILES files)
  INSTALL(FILES ${files}
      DESTINATION ${AVIDEMUX_LIB_DIR}
      PERMISSIONS WORLD_READ WORLD_EXECUTE GROUP_READ GROUP_EXECUTE OWNER_WRITE OWNER_READ OWNER_EXECUTE
      COMPONENT  runtime
  )
ENDMACRO()

#
# MACRO TO INSTALL REGULAR BIN
#
MACRO(ADM_INSTALL_BIN lib)
  INSTALL(TARGETS ${lib} RUNTIME
    DESTINATION ${AVIDEMUX_BIN_DIR}  COMPONENT runtime
    LIBRARY DESTINATION ${AVIDEMUX_LIB_DIR}  COMPONENT runtime
    ARCHIVE DESTINATION ${AVIDEMUX_LIB_DIR} COMPONENT runtime
  )
ENDMACRO()
#
# Macro to install include folder
#
MACRO(ADM_INSTALL_INCLUDE_FOLDER folder targetName)
  INSTALL(DIRECTORY ${folder}
    DESTINATION ${AVIDEMUX_INSTALL_INCLUDE_DIR}/avidemux/${AVIDEMUX_MAJOR_MINOR}/${targetName}
    COMPONENT dev
    FILES_MATCHING PATTERN "*.h*"
    PATTERN  "*.asm"
  )
ENDMACRO()
# #
#
# Macro to install include folder
#
MACRO(ADM_INSTALL_QT_INCLUDE_FOLDER folder targetName)
  INSTALL(DIRECTORY ${folder}
    DESTINATION ${AVIDEMUX_INSTALL_INCLUDE_DIR}/avidemux/${AVIDEMUX_MAJOR_MINOR}/${QT_EXTENSION}/${targetName}
    COMPONENT dev
    FILES_MATCHING PATTERN "*.h*"
  )
ENDMACRO()
# #
#
# Macro to install cmake folder
#
MACRO(ADM_INSTALL_CMAKE_FOLDER folder)
  INSTALL(DIRECTORY ${folder}
    DESTINATION ${AVIDEMUX_INSTALL_INCLUDE_DIR}/avidemux/${AVIDEMUX_MAJOR_MINOR}/
    COMPONENT dev
    FILES_MATCHING PATTERN "*.cmake*"
    PATTERN "attic" EXCLUDE
  )
ENDMACRO()
#
#
# Macro to install cmake folder
#
MACRO(ADM_INSTALL_CMAKE_HELPER_FOLDER root foldername)
  INSTALL(DIRECTORY ${root}/${foldername}
    DESTINATION ${AVIDEMUX_INSTALL_INCLUDE_DIR}/avidemux/${AVIDEMUX_MAJOR_MINOR}/cmake/${foldername}
    COMPONENT dev
    FILES_MATCHING PATTERN "*.[cir]*"
  )
ENDMACRO()
#
# Macro to install include folder
#
MACRO(ADM_INSTALL_APP_HEADER folder)
  INSTALL(FILE ${folder} ${ARGN}
    DESTINATION ${AVIDEMUX_INSTALL_INCLUDE_DIR}/avidemux/${AVIDEMUX_MAJOR_MINOR}/ADM_app
    COMPONENT dev
  )
ENDMACRO()
#
