#--------------------------------------------
#         CamiTK Extension Project
#
# You should probably NOT modify this file...
# Please edit CEPDescription.cmake instead
#--------------------------------------------

cmake_minimum_required(VERSION 2.6)

include(SDKConfig.cmake)

# Please add your project name inside the project() brackets, e.g. project(myProject)
project(${CEP_NAME})

# Mini find CamiTK inside SDK
set(CAMITK_DIR ${CMAKE_BINARY_DIR})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CAMITK_DIR}/share/${CAMITK_SHORT_VERSION_STRING}/cmake)
include(CamiTKConfig)

# include global install of SDK
#-- camitk_global_install == install in CAMITK_DIR
if (CAMITK_SDK_BUILD)
    # if the SDK is currently being build => install in CMAKE_INSTALL_PREFIX
    add_custom_target(sdk_global_install
		# First remove the WIN32 system runtime libraries dependencies
		COMMAND ${CMAKE_COMMAND} -DCMAKE_INSTALL_SYSTEM_RUNTIME_LIBS:STRING=" " ${CMAKE_BINARY_DIR}
		COMMENT "Finishing configuration for ${CMAKE_INSTALL_PREFIX}"
        # Second cmake to install
        COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target install --config ${CMAKE_CFG_INTDIR}
        COMMENT "Global Installation in ${CMAKE_INSTALL_PREFIX}"
        # Copy the CamiTKDir.txt file in the ${CMAKE_USER_DIR} directory 
        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/CamiTKDir.txt ${CAMITK_USER_DIR}
    )
    
else()
    # this is called from a normal CEP build => install in CAMITK_DIR
    add_custom_target(sdk_global_install
        # First cmake to redefine install prefix and remove the WIN32 system runtime libraries dependencies
        COMMAND ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX:PATH=${CAMITK_DIR} -DCMAKE_INSTALL_SYSTEM_RUNTIME_LIBS:STRING=" " ${CMAKE_BINARY_DIR}
		COMMENT "Finishing configuration for ${CAMITK_DIR}"
        # Second cmake to install
        COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target install --config ${CMAKE_CFG_INTDIR}
        COMMENT "Global Installation in ${CAMITK_DIR}"
        # Copy the CamiTKDir.txt file in the ${CMAKE_USER_DIR} directory 
        COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/CamiTKDir.txt ${CAMITK_USER_DIR}
    )
endif()


# camitk_local_install == install in User Config directory
add_custom_target(sdk_local_install
    # First cmake to redefine install prefix
    COMMAND ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX:PATH=${CAMITK_USER_DIR} -DCMAKE_INSTALL_SYSTEM_RUNTIME_LIBS:STRING=" " ${CMAKE_BINARY_DIR}
	COMMENT "Finishing configuration for ${CAMITK_USER_DIR}"
    COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target install --config ${CMAKE_CFG_INTDIR}
    COMMENT "Local Installation in ${CAMITK_USER_DIR}"
    # Copy the CamiTKDir.txt file in the ${CMAKE_USER_DIR} directory 
    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/CamiTKDir.txt ${CAMITK_USER_DIR}
)

# include CamiTK auto-documentation generation
include(CamiTKApiDoc)

# initialize subproject management
camitk_sub_project_init()

# add all subprojects
camitk_add_subdirectory(libraries)
camitk_add_subdirectory(components)
camitk_add_subdirectory(actions)
camitk_add_subdirectory(viewers)
camitk_add_subdirectory(applications)
add_subdirectory(cmake) # for cmake module installation

# Validate project.xml file for CDash
camitk_sub_project_validate()



message(STATUS "compiling in ${CMAKE_BUILD_TYPE}")
message(STATUS "CMAKE_CFG_INTDIR=${CMAKE_CFG_INTDIR}")
message(STATUS "CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
message(STATUS "CMAKE_CONFIGURATION_TYPES=${CMAKE_CONFIGURATION_TYPES}")


