########################################################
# Files

# Obtain the list with 
# for i in $(ls *.cpp -1 | grep -v ^moc.* | grep -v ^qrc.*) ; do echo "  $i";done
SET (massxpert_SRCS
  aboutDlg.cpp
  application.cpp
  atomDefDlg.cpp
  calculatorChemPadDlg.cpp
  calculatorChemPadGroupBox.cpp
  calculatorRecorderDlg.cpp
  calculatorWnd.cpp
  chemPadButton.cpp
  cleavageDlg.cpp
  cleaveOligomerTreeView.cpp
  cleaveOligomerTreeViewItem.cpp
  cleaveOligomerTreeViewMimeData.cpp
  cleaveOligomerTreeViewModel.cpp
  cleaveOligomerTreeViewSortProxyModel.cpp
  cleaveSpecDefDlg.cpp
  compositionsDlg.cpp
  compositionTreeView.cpp
  compositionTreeViewItem.cpp
  compositionTreeViewModel.cpp
  compositionTreeViewSortProxyModel.cpp
  configurationSettingsDlg.cpp
  crossLinkerDefDlg.cpp
  decimalPlacesOptionsDlg.cpp
  fragmentationDlg.cpp
  fragmentOligomerTreeView.cpp
  fragmentOligomerTreeViewItem.cpp
  fragmentOligomerTreeViewMimeData.cpp
  fragmentOligomerTreeViewModel.cpp
  fragmentOligomerTreeViewSortProxyModel.cpp
  fragSpecDefDlg.cpp
  isotopicPatternCalculationDlg.cpp
  main.cpp
  mainWindow.cpp
  massSearchDlg.cpp
  massSearchOligomerTreeView.cpp
  massSearchOligomerTreeViewItem.cpp
  massSearchOligomerTreeViewMimeData.cpp 
  massSearchOligomerTreeViewModel.cpp
  massSearchOligomerTreeViewSortProxyModel.cpp
  modifDefDlg.cpp
  monomerCodeEvaluator.cpp
  monomerCrossLinkDlg.cpp
  monomerDefDlg.cpp
  monomerModificationDlg.cpp
  mzCalculationDlg.cpp
  mzCalculationTreeView.cpp
  mzCalculationTreeViewItem.cpp
  mzCalculationTreeViewModel.cpp
  mzCalculationTreeViewSortProxyModel.cpp
  mzLabInputOligomerTreeView.cpp
  mzLabInputOligomerTreeViewDlg.cpp
  mzLabInputOligomerTreeViewItem.cpp
  mzLabInputOligomerTreeViewModel.cpp
  mzLabInputOligomerTreeViewSortProxyModel.cpp
  mzLabOutputOligomerTreeView.cpp
  mzLabOutputOligomerTreeViewDlg.cpp
  mzLabOutputOligomerTreeViewItem.cpp
  mzLabOutputOligomerTreeViewModel.cpp
  mzLabOutputOligomerTreeViewSortProxyModel.cpp
  mzLabWnd.cpp
  pkaPhPiDlg.cpp
  polChemDefWnd.cpp
  polymerModificationDlg.cpp
  regionSelection.cpp
  sequenceEditorFindDlg.cpp
  sequenceEditorGraphicsView.cpp
  sequenceEditorGraphicsViewKeyboardHandling.cpp
  sequenceEditorGraphicsViewKeySequenceHandling.cpp
  sequenceEditorWnd.cpp
  sequenceImportDlg.cpp
  sequencePurificationDlg.cpp
  sequenceSelection.cpp
)

# Obtain the list with 
# for i in $(grep -l Q_OBJECT *.hpp) ; do echo "  $i"; done
SET (massxpert_MOC_HDRS
  aboutDlg.hpp
  application.hpp
  atomDefDlg.hpp
  calculatorChemPadDlg.hpp
  calculatorChemPadGroupBox.hpp
  calculatorRecorderDlg.hpp
  calculatorWnd.hpp
  chemPadButton.hpp
  cleavageDlg.hpp
  cleaveOligomerTreeView.hpp
  cleaveOligomerTreeViewMimeData.hpp
  cleaveOligomerTreeViewModel.hpp
  cleaveSpecDefDlg.hpp
  compositionsDlg.hpp
  compositionTreeView.hpp
  compositionTreeViewModel.hpp
  configurationSettingsDlg.hpp
  crossLinkerDefDlg.hpp
  decimalPlacesOptionsDlg.hpp
  fragmentationDlg.hpp
  fragmentOligomerTreeView.hpp
  fragmentOligomerTreeViewMimeData.hpp
  fragmentOligomerTreeViewModel.hpp
  fragSpecDefDlg.hpp
  isotopicPatternCalculationDlg.hpp
  mainWindow.hpp
  massSearchDlg.hpp
  massSearchOligomerTreeView.hpp
  massSearchOligomerTreeViewMimeData.hpp
  massSearchOligomerTreeViewModel.hpp
  modifDefDlg.hpp
  monomerCodeEvaluator.hpp
  monomerCrossLinkDlg.hpp
  monomerDefDlg.hpp
  monomerModificationDlg.hpp
  mzCalculationDlg.hpp
  mzCalculationTreeView.hpp
  mzCalculationTreeViewModel.hpp
  mzLabInputOligomerTreeView.hpp
  mzLabInputOligomerTreeViewDlg.hpp
  mzLabInputOligomerTreeViewModel.hpp
  mzLabOutputOligomerTreeView.hpp
  mzLabOutputOligomerTreeViewDlg.hpp
  mzLabOutputOligomerTreeViewModel.hpp
  mzLabWnd.hpp
  pkaPhPiDlg.hpp
  polChemDefWnd.hpp
  polymerModificationDlg.hpp
  sequenceEditorFindDlg.hpp
  sequenceEditorGraphicsView.hpp
  sequenceEditorWnd.hpp
  sequenceImportDlg.hpp
  sequencePurificationDlg.hpp
  )

# Obtain the list with 
# for i in $(ls ui/*.ui) ; do echo "  $i"; done
SET (massxpert_UIS
  ui/aboutDlg.ui
  ui/atomDefDlg.ui
  ui/calculatorChemPadDlg.ui
  ui/calculatorRecorderDlg.ui
  ui/calculatorWnd.ui
  ui/cleavageDlg.ui
  ui/cleaveSpecDefDlg.ui
  ui/compositionsDlg.ui
  ui/configurationSettingsDlg.ui
  ui/crossLinkerDefDlg.ui
  ui/fragmentationDlg.ui
  ui/fragSpecDefDlg.ui
  ui/decimalPlacesOptionsDlg.ui
  ui/isotopicPatternCalculationDlg.ui
  ui/massSearchDlg.ui
  ui/modifDefDlg.ui
  ui/monomerCrossLinkDlg.ui
  ui/monomerDefDlg.ui
  ui/monomerModificationDlg.ui
  ui/mzCalculationDlg.ui
  ui/mzLabInputOligomerTreeViewDlg.ui
  ui/mzLabOutputOligomerTreeViewDlg.ui
  ui/mzLabWnd.ui
  ui/pkaPhPiDlg.ui
  ui/polChemDefWnd.ui
  ui/polymerModificationDlg.ui
  ui/sequenceEditorFindDlg.ui
  ui/sequenceEditorWnd.ui
  ui/sequenceImportDlg.ui
  ui/sequencePurificationDlg.ui
)


#############################################################
# application icon
IF (WIN32 AND NOT MSVC)
  # Icon for windows
  # Note: can't include .rc directly to source files
  # as it's ignored when used MinGW
  IF (NOT WINDRES)
    FIND_PROGRAM (WINDRES windres)
    IF (NOT WINDRES)
      MESSAGE (FATAL_ERROR "windres not found - aborting")
    ENDIF (NOT WINDRES)
  ENDIF (NOT WINDRES)
  
  IF (MINGW)
    # resource compilation for MinGW
    ADD_CUSTOM_COMMAND (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/icon.obj
      COMMAND ${WINDRES} 
      -I${CMAKE_CURRENT_SOURCE_DIR} -i${CMAKE_CURRENT_SOURCE_DIR}/massxpert.rc
      -o ${CMAKE_CURRENT_BINARY_DIR}/icon.obj
      )
    SET (massxpert_SRCS ${massxpert_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/icon.obj)
  ELSE (MINGW)
    SET (massxpert_SRCS ${massxpert_SRCS} 
      ${CMAKE_CURRENT_SOURCE_DIR}/massxpert.rc)
  ENDIF (MINGW)
  
ENDIF (WIN32 AND NOT MSVC)


########################################################
# Build

QT4_WRAP_CPP (massxpert_MOC_SRCS  ${massxpert_MOC_HDRS})

QT4_WRAP_UI (massxpert_UIS_H ${massxpert_UIS})

QT4_ADD_RESOURCES (massxpertQRC_CPP application.qrc)

IF (APPLE)

ADD_EXECUTABLE (${PROGNAME}  MACOSX_BUNDLE 
  ${massxpert_SRCS} 
  ${massxpert_MOC_SRCS}
  ${massxpert_UIS_H} 
  ${massxpertQRC_CPP})

# Apple bundle configuration

  SET (MACOSX_BUNDLE_INFO_STRING "massXpert - version ${VERSION}")
  SET (MACOSX_BUNDLE_BUNDLE_VERSION ${VERSION})
  # Change following line to point to actual icns file in bundle.
  SET (MACOSX_BUNDLE_ICON_FILE "massXpert.icns")
  # means bundle is set to be org.massxpert
  SET (MACOSX_BUNDLE_GUI_IDENTIFIER "org.massxpert")
  SET (MACOSX_BUNDLE_BUNDLE_NAME "massXpert")

  EXEC_PROGRAM ("mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/massXpert.app/Contents/Resources")
  
EXEC_PROGRAM ("cp ${CMAKE_CURRENT_SOURCE_DIR}/images/massXpert.icns ${CMAKE_CURRENT_BINARY_DIR}/massXpert.app/Contents/Resources")
  
# We want to build universal binaries 
SET (CMAKE_OSX_ARCHITECTURES "ppc;i386" 
  CACHE STRING "Build architectures for OSX" FORCE) 

# That can be deployed on older system 
# (Qt 4.4.0 is available starting at 10.3.9) 
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.3" 
  CACHE STRING "Flags used by the compiler during all build types." FORCE)

SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden" 
  CACHE STRING "Flags used by the compiler during all build types." FORCE)

SET (CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.4u.sdk" 
  CACHE STRING "MacOSX10.4u.sdk." FORCE)

SET_SOURCE_FILES_PROPERTIES (application.qrc ${TARGET}_fr.qm 
  PROPERTIES MACOSX_BUNDLE_LOCATION Resources)

ELSE (APPLE)

ADD_EXECUTABLE (${PROGNAME}
  ${massxpert_SRCS} 
  ${massxpert_MOC_SRCS}
  ${massxpert_UIS_H} 
  ${massxpertQRC_CPP})

ENDIF (APPLE)

INCLUDE_DIRECTORIES (
  ${QT_INCLUDE_DIR}
  ${QT_QTXML_INCLUDE_DIR}
  ${QT_QTSVG_INCLUDE_DIR}
  ${CMAKE_CURRENT_SOURCE_DIR}
  ${CMAKE_CURRENT_BINARY_DIR} 
  ${CMAKE_BINARY_DIR} # for the config.h file generated from config.h.in
  ../lib
  )


# Make sure all the symbols from libmasslib.a are in the executable binary!
IF (APPLE)
  SET(MASSLIB -Wl,-all_load ${massxpert_BINARY_DIR}/lib/libmasslib.a -Wl,-noall_load -Wl,-framework,CoreFoundation)
ELSE (APPLE)
  SET(MASSLIB -Wl,-whole-archive ${massxpert_BINARY_DIR}/lib/libmasslib.a -Wl,-no-whole-archive)
ENDIF (APPLE)

  
TARGET_LINK_LIBRARIES (${PROGNAME}
  ${QT_LIBRARIES}
  ${QT_QTXML_LIBRARIES}
  ${QT_QTSVG_LIBRARIES}
  ${MASSLIB}
  )

IF (APPLE)
  # Copy the massXpert.icns icon file in the bundle
  INSTALL (FILES images/massXpert.icns
    DESTINATION ${BUNDLE_DIR}/Contents/Resources)
  
  # Copy the Info.plist file in the bundle
  #INSTALL (FILES ${CMAKE_CURRENT_BINARY_DIR}/massXpert.app/Contents/Info.plist
  #  DESTINATION ${BUNDLE_DIR}/Contents)

ENDIF (APPLE)

IF (NOT APPLE)

  # When building a Mac bundle, we do not install the target
  # because the bundle is being fabricated already.

  INSTALL (TARGETS ${PROGNAME} 
    RUNTIME DESTINATION ${MASSXPERT_BIN_DIR})

ENDIF (NOT APPLE)
