cmake_minimum_required (VERSION 3.15)

project(Tenmon)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -s")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s")

find_package(Qt5 COMPONENTS Widgets Sql OpenGL REQUIRED)
find_package(OpenCV REQUIRED)
find_library(GSL_LIB gsl REQUIRED)
find_library(EXIF_LIB exif REQUIRED)
find_library(FITS_LIB cfitsio REQUIRED)
find_library(RAW_LIB NAMES raw_r raw REQUIRED)

set(TENMON_SRC
    database.cpp
    databaseview.cpp
    filesystemwidget.cpp
    imageinfo.cpp
    imageringlist.cpp
    imagescrollarea.cpp
    imagescrollareagl.cpp
    loadrunable.cpp
    main.cpp
    mainwindow.cpp
    rawimage.cpp
    starfit.cpp
    stfslider.cpp
    stretchpanel.cpp
)

qt5_add_resources(TENMON_SRC resources.qrc)
if(WIN32)
    list(APPEND TENMON_SRC icon.rc)
    add_compile_definitions("__PCL_WINDOWS")
endif(WIN32)
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux")
    add_compile_definitions("__PCL_LINUX")
endif()

add_executable(tenmon ${TENMON_SRC})

find_path(FITS_INCLUDE fitsio2.h PATH_SUFFIXES cfitsio REQUIRED)
target_include_directories(tenmon PRIVATE ${OpenCV_INCLUDE_DIRS} ${FITS_INCLUDE} 3rdparty/include)

target_link_libraries(tenmon Qt5::Widgets Qt5::Sql Qt5::OpenGL ${OpenCV_LIBS} ${GSL_LIB} ${EXIF_LIB} ${FITS_LIB} ${RAW_LIB})

target_link_directories(tenmon PRIVATE 3rdparty/lib/${CMAKE_HOST_SYSTEM_NAME})
target_link_libraries(tenmon PCL lcms  lz4  RFC6234 zlib)

install(TARGETS tenmon)
if(UNIX)
    install(SCRIPT install.cmake)
endif(UNIX)
