# Configuration file for CamiTK
#
# Do not modify this file, it has been generated automatically by CamiTK SDK
#
# CAMITK_DIR should be known before this file is read by CMake
#
# see:
# http://www.itk.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file
# http://www.cmake.org/Wiki/CMake/Tutorials/Packaging

#-- CamiTK current version
set(CAMITK_VERSION_MAJOR "@CAMITK_VERSION_MAJOR@")
set(CAMITK_VERSION_MINOR "@CAMITK_VERSION_MINOR@")
# CamiTK short version name we are looking for
set(CAMITK_SHORT_VERSION_STRING "camitk-${CAMITK_VERSION_MAJOR}.${CAMITK_VERSION_MINOR}")

#-- Compiler configuration for pre-release
# Check all warnings to fix possible bugs
# Not needed all the time, although recommended
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")

# CamiTK requires C++20
# All target after this declaration will be compile with c++14 policy
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) # for wider compatibility across platforms and compiler

#-- Check dependencies: Check VTK first, it will determine which Qt version is required
# Find VTK
if("${CAMITK_VERSION_MAJOR}.${CAMITK_VERSION_MINOR}" VERSION_LESS 5.2)
    find_package(VTK REQUIRED)
else()
    # vtk components can be deduced thanks to the vtk example web site utility available at
    # https://gitlab.kitware.com/vtk/vtk-examples/-/blob/master/src/Python/Utilities/VTKModulesForCxx.py
    #
    # by running the following command in top level CamiTK CE CEP set directory:
    # python VTKModulesForCxx.py /path/VTK/build/modules.json $(find .  -name "*.h" -printf "%p ")
    # 
    # Note that you need to have a build/ VTK directory (beware to configure the build enabling the required VTK groups
    # so that the module.json contains all the modules that CamiTK depends on)
    #
    # Note that some module might not be found by the script (e.g. IOExport) or that some suggested module
    # might not exist in the VTK9 distribution package (e.g. RenderingCellGrid)
    set(CAMITK_VTK_COMPONENTS   CommonCore
                                CommonDataModel
                                CommonExecutionModel
                                CommonMath
                                CommonTransforms
                                FiltersCore
                                FiltersExtraction
                                FiltersGeneral
                                FiltersSources
                                GUISupportQt
                                IOImage
                                ImagingCore
                                ImagingStatistics
                                InteractionWidgets
                                RenderingAnnotation
                                RenderingCore
                                RenderingOpenGL2
                                # Adding suggested modules as well
                                FiltersParallel       # implements VTK::FiltersCore
                                InteractionStyle      # implements VTK::RenderingCore
                                #RenderingCellGrid    # implements VTK::RenderingCore
                                RenderingFreeType     # implements VTK::RenderingCore
                                RenderingGL2PSOpenGL2 # implements VTK::RenderingOpenGL2
                                RenderingUI
                                # Manually added for CamiTK CE
                                IOGeometry             # required by basicmesh action
                                FiltersVerdict         # required by CamiTK basicmesh action
                                ImagingStencil         # required by CamiTK basicmesh action
                                RenderingVolume        # required by CamiTK volumerendering action
                                RenderingVolumeOpenGL2 # required by CamiTK volumerendering action
                                IOImport               # required by CamiTK core
                                IOExport               # required by CamiTK vrml component
                                IOExportGL2PS          # required by CamiTK core
    )    
    find_package(VTK REQUIRED
                 COMPONENTS ${CAMITK_VTK_COMPONENTS}
    )
    # add VTK:: to the component names (used later in target_link_libraries)
    string(REGEX REPLACE "([^;]+)" "VTK::\\1" CAMITK_VTK_LIBRARIES "${CAMITK_VTK_COMPONENTS}")
endif()
if(NOT VTK_FOUND)
    message(SEND_ERROR "Failed to find VTK. VTK is required.")
endif()
if("${VTK_VERSION}" VERSION_LESS 7.1)
    message(FATAL_ERROR "Found VTK ${VTK_VERSION} version but at least 7.1 is required. Please update your version of VTK.")
endif()
message(STATUS "Found suitable version of VTK : ${VTK_VERSION} (VTK 7.1 or above required)")
set(CAMITK_VTK_VERSION ${VTK_VERSION_MAJOR}.${VTK_VERSION_MINOR})
if("${VTK_VERSION}" VERSION_LESS 9.0)
    include(${VTK_USE_FILE}) # This automatically set the include dirs (remain the link_directories and target_link_libraries)
else()
    # nothing to do.
    # VTK is install in ${VTK_PREFIX_PATH}, include directories should be in
    # "${VTK_PREFIX_PATH}/include/vtk-${CAMITK_VTK_VERSION}"
    # VTK_LIBRARIES variable contains IMPORTED targets (in form of VTK::foo)
    # linking with the content of that variable using target_link_libraries will 
    # automatically provide include directories.
    # see https://docs.vtk.org/en/latest/advanced/migration_guides/ModuleMigration.html
endif()
set(VTK_LIBRARY_DIR ${VTK_DIR}/../..)


# Find Qt
if ("${VTK_QT_VERSION}" EQUAL "6")
    # List of Qt6 modules that are required in CamiTK
    set(CAMITK_QT_COMPONENTS Core Gui Widgets Xml UiTools StateMachine Test)
elseif("${VTK_QT_VERSION}" EQUAL "5")
     # Qt5 modules differ from Qt6 (e.g. StateMachine is included in Core)
     set(CAMITK_QT_COMPONENTS Core Gui Widgets Xml UiTools Test)
else()
    message(SEND_ERROR "CamiTK SDK : VTK ${VTK_VERSION} was built using an unsupported version of Qt${VTK_QT_VERSION}. Please install matching and supported Qt/VTK versions.")
endif()

# list of namespace prefixed to use in target_link_libraries
string(REGEX REPLACE "([^;]+)" "Qt::\\1" CAMITK_QT_LIBRARIES "${CAMITK_QT_COMPONENTS}")

# Find the Qt version that was used to build VTK 
find_package(Qt${VTK_QT_VERSION} COMPONENTS ${CAMITK_QT_COMPONENTS})

if (Qt5_FOUND OR Qt6_FOUND)
    set(Qt_VERSION "${Qt${VTK_QT_VERSION}_VERSION_MAJOR}.${Qt${VTK_QT_VERSION}_VERSION_MINOR}.${Qt${VTK_QT_VERSION}_VERSION_PATCH}")
    message(STATUS "CamiTK SDK : found Qt ${Qt_VERSION}.")
    set(QT_INCLUDE_DIRS ${QtWidgets_INCLUDE_DIRS} ${QtCore_INCLUDE_DIRS} ${QtGui_INCLUDE_DIRS} ${QtXml_INCLUDE_DIRS} ${QtDeclarative_INCLUDE_DIRS} ${QtHelp_INCLUDE_DIRS} ${QtUiTools_INCLUDE_DIRS} ${QtOpenGL_INCLUDE_DIRS} ${QtOpenGLExtensions_INCLUDE_DIRS})
    # force Qt to print more debug information
    add_definitions(-DQT_MESSAGELOGCONTEXT)
    add_compile_definitions(QT_DISABLE_DEPRECATED_UP_TO=0x050F00)
    add_compile_definitions(QT_WARN_DEPRECATED_UP_TO=0x050F00)
else()
    message(SEND_ERROR "CamiTK SDK : VTK ${VTK_VERSION} built using Qt${VTK_QT_VERSION} but CMake failed to find Qt${VTK_QT_VERSION}. Please install matching Qt/VTK versions.")
endif()


#-- supply default values for CMake
if(UNIX)
  include(GNUInstallDirs)
else()
  if (WIN32)
    set(CMAKE_INSTALL_LIBDIR "lib")
    set(CMAKE_INSTALL_BINDIR "bin")
  else()
    message(FATAL_ERROR "Detected system is not UNIX nor WIN32 - not implemented yet")
  endif()
endif()

#-- deduce correct install lib directory
set(CAMITK_INSTALL_LIB_DIR ${CMAKE_INSTALL_LIBDIR})
# Special case when building extension outside CamiTK Community Edition
# and when Debian package is built or installed, CAMITK_INSTALL_LIB_DIR might
# be in a ${CMAKE_LIBRARY_ARCHITECTURE} subdirectory
if (NOT CAMITK_COMMUNITY_EDITION_BUILD AND UNIX AND CMAKE_LIBRARY_ARCHITECTURE AND NOT EXISTS ${CAMITK_DIR}/${CAMITK_INSTALL_LIB_DIR}/${CAMITK_SHORT_VERSION_STRING})
    if(EXISTS ${CAMITK_DIR}/lib64/${CAMITK_SHORT_VERSION_STRING})
        set(CAMITK_INSTALL_LIB_DIR "lib64")
    else()
        if (EXISTS ${CAMITK_DIR}/lib/${CMAKE_LIBRARY_ARCHITECTURE}/${CAMITK_SHORT_VERSION_STRING})
            set(CAMITK_INSTALL_LIB_DIR "lib/${CMAKE_LIBRARY_ARCHITECTURE}")
        else()
            message(FATAL_ERROR "Cannot find ${CAMITK_SHORT_VERSION_STRING} repository in ${CAMITK_DIR}/${CAMITK_INSTALL_LIB_DIR}")
        endif()
    endif()
endif()

#-- CAMITK_DIR variable
set(CAMITK_BIN_DIR         ${CAMITK_DIR}/bin                                                      )
set(CAMITK_PRIVATE_LIB_DIR ${CAMITK_DIR}/${CAMITK_INSTALL_LIB_DIR}/${CAMITK_SHORT_VERSION_STRING} )
set(CAMITK_PUBLIC_LIB_DIR  ${CAMITK_DIR}/${CAMITK_INSTALL_LIB_DIR}                                )
set(CAMITK_INCLUDE_DIR     ${CAMITK_DIR}/include/${CAMITK_SHORT_VERSION_STRING}                   )
set(CAMITK_TESTDATA_DIR    ${CAMITK_DIR}/share/${CAMITK_SHORT_VERSION_STRING}/testdata            )
set(CAMITK_CMAKE_DIR       ${CAMITK_DIR}/share/${CAMITK_SHORT_VERSION_STRING}/cmake               )

#-- User Config directory variable
# see https://doc.qt.io/qt-5/qsettings.html#platform-specific-notes
if(WIN32)
    # %APPDATA%\MySoft\Star Runner.ini
    set(CAMITK_USER_BASE_DIR_WINDOWS $ENV{APPDATA})
    file(TO_CMAKE_PATH "${CAMITK_USER_BASE_DIR_WINDOWS}" CAMITK_USER_BASE_DIR)
else()
    # (UNIX OR APPLE)
    # $HOME/.config/MySoft/Star Runner.ini
    set(CAMITK_USER_BASE_DIR "$ENV{HOME}/.config")
endif()
set(CAMITK_USER_DIR "${CAMITK_USER_BASE_DIR}/CamiTK")
set(CAMITK_USER_BIN_DIR          ${CAMITK_USER_DIR}/bin                                                    )
set(CAMITK_USER_PRIVATE_LIB_DIR  ${CAMITK_USER_DIR}/${CMAKE_INSTALL_LIBDIR}/${CAMITK_SHORT_VERSION_STRING} )
set(CAMITK_USER_PUBLIC_LIB_DIR   ${CAMITK_USER_DIR}/${CMAKE_INSTALL_LIBDIR}                                )
set(CAMITK_USER_INCLUDE_DIR      ${CAMITK_USER_DIR}/include/${CAMITK_SHORT_VERSION_STRING}                 )
set(CAMITK_USER_TESTDATA_DIR     ${CAMITK_USER_DIR}/share/${CAMITK_SHORT_VERSION_STRING}/testdata          )
set(CAMITK_USER_CMAKE_DIR        ${CAMITK_USER_DIR}/share/${CAMITK_SHORT_VERSION_STRING}/cmake             )

#-- Current build dir
set(CAMITK_BUILD_DIR ${CMAKE_BINARY_DIR})
set(CAMITK_BUILD_BIN_DIR         ${CAMITK_BUILD_DIR}/bin                                                    )
set(CAMITK_BUILD_PRIVATE_LIB_DIR ${CAMITK_BUILD_DIR}/${CMAKE_INSTALL_LIBDIR}/${CAMITK_SHORT_VERSION_STRING} )
set(CAMITK_BUILD_PUBLIC_LIB_DIR  ${CAMITK_BUILD_DIR}/${CMAKE_INSTALL_LIBDIR}                                )
set(CAMITK_BUILD_INCLUDE_DIR     ${CAMITK_BUILD_DIR}/include/${CAMITK_SHORT_VERSION_STRING}                 )
set(CAMITK_BUILD_TESTDATA_DIR    ${CAMITK_BUILD_DIR}/share/${CAMITK_SHORT_VERSION_STRING}/testdata          )
set(CAMITK_BUILD_CMAKE_DIR       ${CAMITK_BUILD_DIR}/share/${CAMITK_SHORT_VERSION_STRING}/cmake             )

# no need to see this
mark_as_advanced ( CMAKE_RUNTIME_OUTPUT_DIRECTORY CMAKE_LIBRARY_OUTPUT_DIRECTORY CMAKE_ARCHIVE_OUTPUT_DIRECTORY)

#
# Convenience variables
#


# name of the camitk core lib
set(CAMITK_CORE_LIB_NAME camitkcore)
set(CAMITK_EXTENSIONLIBRARY_LIB_NAME camitkextensiongenerator)

if(PACKAGING_NSIS)
    set(CAMITK_EXTENSIONGENERATOR_TARGET_LIB_NAME library_${CAMITK_EXTENSIONLIBRARY_LIB_NAME})
    set(CAMITK_CORE_TARGET_LIB_NAME library_${CAMITK_CORE_LIB_NAME})
else()
    set(CAMITK_EXTENSIONGENERATOR_TARGET_LIB_NAME library-${CAMITK_EXTENSIONLIBRARY_LIB_NAME})
    set(CAMITK_CORE_TARGET_LIB_NAME library-${CAMITK_CORE_LIB_NAME})
endif()

# All the link directories
set(CAMITK_LINK_DIRECTORIES
    # private and public libs (including bin dir for windows)
    ${CAMITK_PRIVATE_LIB_DIR}
    ${CAMITK_PUBLIC_LIB_DIR}
    ${CAMITK_BIN_DIR}
    ${CAMITK_USER_PRIVATE_LIB_DIR}
    ${CAMITK_USER_PUBLIC_LIB_DIR}
    ${CAMITK_USER_BIN_DIR}
    ${CAMITK_BUILD_PRIVATE_LIB_DIR}
    ${CAMITK_BUILD_PUBLIC_LIB_DIR}
    ${CAMITK_BUILD_BIN_DIR}
    # CEP extensions dependencies
    ${CAMITK_PRIVATE_LIB_DIR}/components
    ${CAMITK_PRIVATE_LIB_DIR}/actions
    ${CAMITK_PRIVATE_LIB_DIR}/viewers
    ${CAMITK_USER_PRIVATE_LIB_DIR}/components
    ${CAMITK_USER_PRIVATE_LIB_DIR}/actions
    ${CAMITK_USER_PRIVATE_LIB_DIR}/viewers
    ${CAMITK_BUILD_PRIVATE_LIB_DIR}/components
    ${CAMITK_BUILD_PRIVATE_LIB_DIR}/actions
    ${CAMITK_BUILD_PRIVATE_LIB_DIR}/viewers
)

# List of directories where the compiler should look for CamiTK core headers as well
# as all the tools headers and dependencies headers (Qt, Vtk)
set(CAMITK_INCLUDE_DIRECTORIES
    ${CAMITK_INCLUDE_DIR}
    ${CAMITK_INCLUDE_DIR}/libraries
    ${CAMITK_INCLUDE_DIR}/libraries/qtpropertybrowser
    ${CAMITK_INCLUDE_DIR}/libraries/${CAMITK_EXTENSIONLIBRARY_LIB_NAME}
    ${CAMITK_INCLUDE_DIR}/libraries/${CAMITK_CORE_LIB_NAME}
    ${CAMITK_USER_INCLUDE_DIR}
    ${CAMITK_BUILD_INCLUDE_DIR}
    ${QT_INCLUDE_DIRS}
    ${VTK_INCLUDE_DIRS}
    ${CAMITK_BUILD_INCLUDE_DIR}/libraries
)
# TODO: remove ${CAMITK_BUILD_INCLUDE_DIR}/libraries => find a better way to organize dependencies

# postfix for MSVC debug version
set(CAMITK_DEBUG_POSTFIX "-debug")

# basic list of all lib needed for linking with CamiTK core
if(MSVC)
    # name of the camitk core lib
    set(CAMITK_CORE_LIBRARIES optimized ${CAMITK_CORE_LIB_NAME}
                              debug ${CAMITK_CORE_LIB_NAME}${CAMITK_DEBUG_POSTFIX}
    )

    # Construct list of VTK libraries for linking
    # CAMITK_VTK_LIBRARIES = VTK input libraries at linkage
    foreach(VTK_LIBRARY ${VTK_LIBRARIES})
        # Clear some errors on VTK configuration
        # rename correctly verdict -> vtkverdict, vtkproj -> vtklibproj, vtkhdf5_hl -> vtkhdf5_hl_src, vtkhdf5 -> vtkhdf5_src libraries
        if(VTK_LIBRARY STREQUAL "verdict")
            set(VTK_LIBRARY "vtkverdict")
        endif()
		if("${VTK_VERSION}" VERSION_GREATER_EQUAL 8.2)
			if(VTK_LIBRARY STREQUAL "vtkhdf5_hl_src")
				set(VTK_LIBRARY "vtkhdf5_hl")
			endif()
			if(VTK_LIBRARY STREQUAL "vtkhdf5_src")
				set(VTK_LIBRARY "vtkhdf5")
			endif()
			if(VTK_LIBRARY STREQUAL "vtklibproj")
				set(VTK_LIBRARY "vtkproj")
			endif()
            # Check if the variable starts with "VTK::" (new "module"/"lib" names)
            # if (${VTK_LIBRARY} MATCHES "^VTK::")
            #     # Replace "VTK::" with "vtk"
            #     string(REGEX REPLACE "^VTK::" "vtk" VTK_LIBRARY "${VTK_LIBRARY}")
            # endif()
		endif()
        if("${VTK_VERSION}" VERSION_LESS 9.0)
            set(CAMITK_VTK_LIBRARIES ${CAMITK_VTK_LIBRARIES} debug ${VTK_LIBRARY_DIR}/${VTK_LIBRARY}-${CAMITK_VTK_VERSION}${CAMITK_DEBUG_POSTFIX}.lib optimized ${VTK_LIBRARY_DIR}/${VTK_LIBRARY}-${CAMITK_VTK_VERSION}.lib)
        endif()
    endforeach()

    if("${VTK_VERSION}" VERSION_LESS 9.0)
        # add missing vtkIOExport, vtkImagingStencil, vtkIOImport, vtkImagingMath library
        set(CAMITK_VTK_LIBRARIES ${CAMITK_VTK_LIBRARIES} debug ${VTK_LIBRARY_DIR}/vtkIOExport-${CAMITK_VTK_VERSION}${CAMITK_DEBUG_POSTFIX}.lib optimized ${VTK_LIBRARY_DIR}/vtkIOExport-${CAMITK_VTK_VERSION}.lib)
        set(CAMITK_VTK_LIBRARIES ${CAMITK_VTK_LIBRARIES} debug ${VTK_LIBRARY_DIR}/vtkImagingStencil-${CAMITK_VTK_VERSION}${CAMITK_DEBUG_POSTFIX}.lib optimized ${VTK_LIBRARY_DIR}/vtkImagingStencil-${CAMITK_VTK_VERSION}.lib)
        set(CAMITK_VTK_LIBRARIES ${CAMITK_VTK_LIBRARIES} debug ${VTK_LIBRARY_DIR}/vtkIOImport-${CAMITK_VTK_VERSION}${CAMITK_DEBUG_POSTFIX}.lib optimized ${VTK_LIBRARY_DIR}/vtkIOImport-${CAMITK_VTK_VERSION}.lib)
        set(CAMITK_VTK_LIBRARIES ${CAMITK_VTK_LIBRARIES} debug ${VTK_LIBRARY_DIR}/vtkImagingMath-${CAMITK_VTK_VERSION}${CAMITK_DEBUG_POSTFIX}.lib optimized ${VTK_LIBRARY_DIR}/vtkImagingMath-${CAMITK_VTK_VERSION}.lib)
    else()
        set(CAMITK_VTK_LIBRARIES ${VTK_LIBRARIES})
    endif()
    
    # list of all core dependencies
    set(CAMITK_EXTENSIONGENERATOR_LIBRARY debug ${CAMITK_EXTENSIONLIBRARY_LIB_NAME}${CAMITK_DEBUG_POSTFIX}.lib
                                          optimized ${CAMITK_EXTENSIONLIBRARY_LIB_NAME})
    set(CAMITK_LIBRARIES
            ${CAMITK_EXTENSIONGENERATOR_LIBRARY}
            ${CAMITK_VTK_LIBRARIES}
            debug qtpropertybrowser${CAMITK_DEBUG_POSTFIX}.lib optimized qtpropertybrowser
    )
else()
    # Name of the core library to link against
    set(CAMITK_CORE_LIBRARIES ${CAMITK_CORE_LIB_NAME})

    # list of all core dependencies
    set(CAMITK_EXTENSIONGENERATOR_LIBRARY ${CAMITK_EXTENSIONLIBRARY_LIB_NAME})
    set(CAMITK_LIBRARIES
        ${CAMITK_EXTENSIONGENERATOR_LIBRARY}
        ${CAMITK_VTK_LIBRARIES} # no need to add more libraries in the list, CMake & VTK handle it correctly on Linux & Apple
        qtpropertybrowser
    )
endif()

mark_as_advanced (CAMITK_CORE_LIB CAMITK_LINK_DIRECTORIES CAMITK_INCLUDE_DIRECTORIES CAMITK_LIBRARIES)

# additional unix system resources
if (UNIX)
    # only possible on unix
    if(DEFINED ENV{SOURCE_DATE_EPOCH})
        # to enable reproducible builds, see Debian bug #794740
        execute_process(COMMAND "date" "-u" "+%Y-%m-%d" "--date=@$ENV{SOURCE_DATE_EPOCH}"
                        OUTPUT_VARIABLE CURRENT_DATE
                        OUTPUT_STRIP_TRAILING_WHITESPACE
        )
    else()
        execute_process(COMMAND "date" "+%Y-%m-%d"
                        OUTPUT_VARIABLE CURRENT_DATE
                        OUTPUT_STRIP_TRAILING_WHITESPACE
        )
    endif()

    # Application man pages (always in section 1, this is an application...)
    set(CAMITK_APPLICATION_MAN_INSTALL_DIR "share/man/man1")
    # Desktop file always in share/applications (freedesktop standard)
    set(CAMITK_APPLICATION_DESKTOP_INSTALL_DIR "share/applications")
    # icons file always in pixmaps (should be xpm or svg)
    set(CAMITK_APPLICATION_PIXMAP_INSTALL_DIR "share/pixmaps")
endif()

# RPATH settings for Linux
# This settings allow running the exe from the build tree and running them from its install location
# without doing anything in particular.
# see http://www.itk.org/Wiki/CMake_RPATH_handling
# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)

# when building, don't use the install RPATH already
# (but later on when installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")

# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

# the RPATH to be used when installing, but only if it's not a system directory
# TODO : write a specific macro camitk_install to use for installing library
# This macro should not only do the usual install job, but also should add the
# specific install path in the CMAKE_INSTALL_RPATH variables
# On windows: write a message at the end of the installation process with the value
# of CMAKE_INSTALL_RPATH
# On Windows: build a specific .bat for each application?
# Even better, try this: cumulate the CMAKE_INSTALL_RPATH in a file containing the list
# of all needed dir in the path. This file is read at run-time to add the path using
# Application::instance()->addLibraryPath(path#i.canonicalPath());
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
    set(CMAKE_INSTALL_RPATH  "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
                             "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${CAMITK_SHORT_VERSION_STRING}"
                             "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${CAMITK_SHORT_VERSION_STRING}/components"
                             "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${CAMITK_SHORT_VERSION_STRING}/actions"
                             "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${CAMITK_SHORT_VERSION_STRING}/viewers")
endif()

#-- update module path
# for SDK look also directly in source dir
if(CAMITK_COMMUNITY_EDITION_BUILD)
    set(CMAKE_MODULE_PATH   ${CMAKE_MODULE_PATH}
                            ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules
                            ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/macros
                            ${CMAKE_CURRENT_SOURCE_DIR}/../sdk/cmake/modules
                            ${CMAKE_CURRENT_SOURCE_DIR}/../sdk/cmake/modules/macros
    )
endif()
set(CMAKE_MODULE_PATH   ${CMAKE_MODULE_PATH}
                        ${CAMITK_CMAKE_DIR}
                        ${CAMITK_CMAKE_DIR}/modules
                        ${CAMITK_CMAKE_DIR}/modules/macros
                        ${CAMITK_CMAKE_DIR}/macros
                        ${CAMITK_USER_CMAKE_DIR}
                        ${CAMITK_USER_CMAKE_DIR}/modules
                        ${CAMITK_BUILD_CMAKE_DIR}
                        ${CAMITK_BUILD_CMAKE_DIR}/modules
)


# include useful modules
include(CamiTKMacros)

# include CamiTK log configuration
include(CamiTKLog)

# TODO check this
#
# # By default, validate all projects are build in the build/bin directory (no subfolder).
# # Note that, subfolders for actions / components are added later.
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CAMITK_BIN_DIR})
# set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CAMITK_BIN_DIR})
# set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CAMITK_BIN_DIR})
#
# # Remove the Debug, Release subfolders in build/bin, natively created with Visual Studio
# if ( ${CMAKE_GENERATOR} MATCHES "Visual Studio") # MSVC compiler
#         foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
#                 string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
#                 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CAMITK_BIN_DIR} CACHE TYPE STRING)
#                 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CAMITK_BIN_DIR} CACHE TYPE STRING)
#                 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CAMITK_BIN_DIR} CACHE TYPE STRING)
#         endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES )
# endif(${CMAKE_GENERATOR} MATCHES "Visual Studio")
#
# # Create the Xml data for Project.xml description, fyi store in the global variable CAMITK_SUBPROJECTS
# camitk_init_manifest_data()
