cmake_minimum_required(VERSION 3.16)

project(GenerateCell VERSION 0.1 LANGUAGES CXX)

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

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)

if(MSVC)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
endif(MSVC)

# VTK
set(VTK_DIR "E:/projects/items/VTK/9.3.3/build-vs2019" CACHE PATH "VTK directory")
find_package(VTK REQUIRED)

set(COMMON
    common/global.cpp
    common/global.h
    common/appinfo.cpp
    common/appinfo.h
    common/cellshapestruct.h
    common/cellshapestruct.cpp
)
source_group(common FILES ${COMMON})

set(THREAD
    thread/generatefilethread.cpp
    thread/generatefilethread.h
)
source_group(thread FILES ${THREAD})

set(SKINUI
    ui/skinui/BaseWidget.cpp
    ui/skinui/BaseWidget.h
    ui/skinui/NcFramelessHelper.cpp
    ui/skinui/NcFramelessHelper.h
    ui/skinui/Skin.cpp
    ui/skinui/Skin.h
    ui/skinui/StateButton.cpp
    ui/skinui/StateButton.h
    ui/skinui/TitleBar.cpp
    ui/skinui/TitleBar.h
)
source_group(ui/skinui FILES ${SKINUI})

set(UI
    ui/mainwidget.cpp
    ui/mainwidget.h
    ui/mainwidget.ui
    ui/cmessagebox.cpp
    ui/cmessagebox.h
    ui/cmessagebox.ui
)
source_group(ui FILES ${UI})

set(MAIN
    main/main.cpp
)
source_group(main FILES ${MAIN})

set(RES
    res/skin.qrc
    res/images/icon/logo.rc
)
source_group(res FILES ${RES})

include_directories(
    common
    thread
    ui
    ui/skinui
)

if(WIN32)
    source_group("temp" REGULAR_EXPRESSION "ui_.*\\.h$|mocs_.*\\.cpp|\\.stamp$|\\.rule$|qrc_.*\\.cpp$")
endif()

add_executable(${PROJECT_NAME}
    ${COMMON}
    ${THREAD}
    ${MAIN}
    ${UI}
    ${SKINUI}
    ${RES}
)

target_link_libraries(GenerateCell PRIVATE
    Qt${QT_VERSION_MAJOR}::Widgets
    ${VTK_LIBRARIES}
)

# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
  set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.GenerateCell)
endif()
set_target_properties(GenerateCell PROPERTIES
    ${BUNDLE_ID_OPTION}
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

include(GNUInstallDirs)
install(TARGETS GenerateCell
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(GenerateCell)
endif()

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
