Project(Slicer3ExampleModules)

cmake_minimum_required(VERSION 2.6)

#
# Disable the warnings that DevStudio 2005 emits wrt to sprintf, strcpu, etc.
#
IF(CMAKE_COMPILER_2005)
  ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
ENDIF(CMAKE_COMPILER_2005)

#
# This example can be packaged into an installer.
#
INCLUDE(CPack)

#
# If building Slicer3ExampleModules outside of another project, define a library 
# and an executable output path
#
If (${CMAKE_SOURCE_DIR} STREQUAL ${Slicer3ExampleModules_SOURCE_DIR})
  SET (LIBRARY_OUTPUT_PATH ${Slicer3ExampleModules_BINARY_DIR}/bin/ 
        CACHE PATH 
        "Single output directory for building all libraries." 
        FORCE)
  SET (EXECUTABLE_OUTPUT_PATH ${Slicer3ExampleModules_BINARY_DIR}/bin/ 
        CACHE PATH 
        "Single output directory for building all executables." 
        FORCE)
Endif (${CMAKE_SOURCE_DIR} STREQUAL ${Slicer3ExampleModules_SOURCE_DIR})

#
# Find Slicer3. This will locate all the components needed to build modules 
# for Slicer3.
#
FIND_PACKAGE(Slicer3 REQUIRED)
IF (Slicer3_FOUND)
  INCLUDE(${Slicer3_USE_FILE})    
ELSE (Slicer3_FOUND)
  MESSAGE(ERROR "Cannot build without a Slicer3 build tree or a Slicer3 installation. Please set Slicer3_DIR. If using a Slicer3 build, Slicer3_DIR needs to be set to the root of the build tree of Slicer3.  If using an installation of Slicer3, Slicer3_DIR needs to be set to <SlicerInstallation>/lib/Slicer3.")
ENDIF (Slicer3_FOUND)



#
# Define our new plugin that uses ITK.  This plugin is compiled as both a 
# shared object and an executable
#
SET ( ExampleModule_SOURCE ExampleModule.cxx )
GENERATECLP(ExampleModule_SOURCE ExampleModule.xml)
ADD_LIBRARY(ExampleModuleLib SHARED ${ExampleModule_SOURCE})
SET_TARGET_PROPERTIES (ExampleModuleLib PROPERTIES COMPILE_FLAGS "-Dmain=ModuleEntryPoint")
TARGET_LINK_LIBRARIES ( ExampleModuleLib ITKStatistics ITKIO ITKBasicFilters ITKCommon)
ADD_EXECUTABLE ( ExampleModule ${ExampleModule_SOURCE})
TARGET_LINK_LIBRARIES ( ExampleModule ITKStatistics ITKIO ITKBasicFilters ITKCommon)

#
# Define our new plugin that uses ITK.  This plugin is compiled as both a 
# shared object and an executable
#
SET ( PolyDataToLabelmap_SOURCE PolyDataToLabelmap.cxx )
GENERATECLP(PolyDataToLabelmap_SOURCE PolyDataToLabelmap.xml)
ADD_LIBRARY(PolyDataToLabelmapLib SHARED ${PolyDataToLabelmap_SOURCE})
SET_TARGET_PROPERTIES (PolyDataToLabelmapLib PROPERTIES COMPILE_FLAGS "-Dmain=ModuleEntryPoint")
TARGET_LINK_LIBRARIES ( PolyDataToLabelmapLib ITKIO ITKCommon vtkIO vtkCommon vtkFiltering vtkGraphics)
ADD_EXECUTABLE ( PolyDataToLabelmap ${PolyDataToLabelmap_SOURCE})
TARGET_LINK_LIBRARIES ( PolyDataToLabelmap ITKIO ITKCommon vtkIO vtkCommon vtkFiltering vtkGraphics)

#
# Another plugin using MRML.  This plugin is compiled as both a shared object 
# and an executable
#
SET ( ExampleMRMLModule_SOURCE ExampleMRMLModule.cxx )
GENERATECLP(ExampleMRMLModule_SOURCE ExampleMRMLModule.xml)
ADD_LIBRARY(ExampleMRMLModuleLib SHARED ${ExampleMRMLModule_SOURCE})
SET_TARGET_PROPERTIES (ExampleMRMLModuleLib PROPERTIES COMPILE_FLAGS "-Dmain=ModuleEntryPoint")
TARGET_LINK_LIBRARIES ( ExampleMRMLModuleLib MRML vtkGraphics vtkFiltering vtksys SlicerBaseCLI ITKIO)
ADD_EXECUTABLE ( ExampleMRMLModule ${ExampleMRMLModule_SOURCE})
TARGET_LINK_LIBRARIES ( ExampleMRMLModule MRML vtkGraphics vtkFiltering vtksys ITKIO)


#
# Install into a local plugins directory
#
set(TARGETS ExampleModule ExampleModuleLib ExampleMRMLModule ExampleMRMLModuleLib PolyDataToLabelmap PolyDataToLabelmapLib)
foreach(targ ${TARGETS})
  slicer3_set_plugins_output_path(${targ})
endforeach(targ ${TARGETS})
slicer3_install_plugins(${TARGETS})


#
# CPack information
#
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Examples for Slicer3 module developers.")
SET(CPACK_PACKAGE_VENDOR "NA-MIC")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${Slicer3ExampleModules_SOURCE_DIR}/Readme.txt")
SET(CPACK_RESOURCE_FILE_LICENSE "${Slicer3ExampleModules_SOURCE_DIR}/License.txt")
SET(CPACK_PACKAGE_VERSION_MAJOR "0")
SET(CPACK_PACKAGE_VERSION_MINOR "1")
SET(CPACK_PACKAGE_VERSION_PATCH "0")


