cmake_minimum_required(VERSION 3.3)

project(common_pages VERSION 1.0)

if (NOT DEFINED ENV{MIDASSYS})
    message(FATAL_ERROR "The system variable MIDASSYS is not defined.")
endif()

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
    set(
        CMAKE_INSTALL_PREFIX
        "$ENV{MIDASSYS}/pages"
        CACHE PATH "Install path"
        FORCE
    )
endif()

# Install all common pages except Beamline_overview_images.json.
# That file is handled separately so the parent project can override it.
install(
    DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/pages/
    DESTINATION .
    PATTERN "Beamline_overview_images.json" EXCLUDE
)

# The parent project may provide a different file through
# BEAMLINE_OVERVIEW_IMAGES_FILE. Otherwise use the common default.
if(NOT DEFINED BEAMLINE_OVERVIEW_IMAGES_FILE)
    set(
        BEAMLINE_OVERVIEW_IMAGES_FILE
        "${CMAKE_CURRENT_SOURCE_DIR}/pages/Beamline_elements/Beamline_overview_images.json"
    )
endif()

install(
    FILES "${BEAMLINE_OVERVIEW_IMAGES_FILE}"
    DESTINATION Beamline_elements
)

install(
    SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/configure_odb.cmake"
)
