cmake_minimum_required(VERSION 3.25)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded")
if(WIN32)
  project(FrameyApp LANGUAGES CXX RC)
elseif(APPLE)
  project(FrameyApp LANGUAGES CXX OBJCXX)
else()
  project(FrameyApp LANGUAGES CXX)
endif()
set(CMAKE_CXX_FLAGS_RELEASE "-Os -DNDEBUG")
set(CMAKE_OBJCXX_FLAGS_RELEASE "-Os -DNDEBUG")
set(SOURCES src/core.cpp)
if(WIN32)
  list(APPEND SOURCES src/ui_win.cpp app.rc)
elseif(APPLE)
  list(APPEND SOURCES src/ui_mac.mm)
else()
  list(APPEND SOURCES src/ui_gtk.cpp)
endif()
add_executable(FrameyApp ${SOURCES})
target_include_directories(FrameyApp PRIVATE generated src)
target_compile_options(FrameyApp PRIVATE -std=c++2c -fno-rtti -ffunction-sections -fdata-sections -Wall)
if(WIN32)
  target_link_options(FrameyApp PRIVATE -fuse-ld=lld -Wl,/OPT:REF,/OPT:ICF,/SUBSYSTEM:WINDOWS,/ENTRY:mainCRTStartup)
  target_link_libraries(FrameyApp PRIVATE user32 gdi32 comctl32 comdlg32 shell32 -Wl,/MANIFEST:NO)
  set_source_files_properties(app.rc PROPERTIES OBJECT_DEPENDS "${CMAKE_SOURCE_DIR}/assets/framey.ico;${CMAKE_SOURCE_DIR}/app.manifest")
elseif(APPLE)
  target_compile_options(FrameyApp PRIVATE -mmacosx-version-min=13.3 -fobjc-arc)
  target_link_options(FrameyApp PRIVATE -mmacosx-version-min=13.3 -Wl,-dead_strip)
  target_link_libraries(FrameyApp PRIVATE "-framework Cocoa" "-framework QuartzCore")
else()
  find_package(PkgConfig REQUIRED)
  pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
  find_package(Threads REQUIRED)
  target_include_directories(FrameyApp PRIVATE ${GTK3_INCLUDE_DIRS})
  target_link_libraries(FrameyApp PRIVATE ${GTK3_LIBRARIES} Threads::Threads)
  target_link_options(FrameyApp PRIVATE -Wl,--gc-sections -s)
endif()
