cmake_minimum_required(VERSION 3.12)

project(PropertyEditor CXX)

option(BUILD_SHARED_LIBS "Build shared library (ON) or static library (OFF)" OFF)

find_package(Qt6 COMPONENTS Core Widgets Gui QuickWidgets QuickTemplates2 QuickControls2 REQUIRED)

qt6_add_resources(QRC_FILE resources.qrc)

file(GLOB_RECURSE PROJECT_SOURCE FILES ${CMAKE_CURRENT_SOURCE_DIR}/source/*.h  ${CMAKE_CURRENT_SOURCE_DIR}/source/*.hpp ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/resources/*)

source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${PROJECT_SOURCE})

if(BUILD_SHARED_LIBS)
	add_library(PropertyEditor SHARED ${PROJECT_SOURCE} ${QRC_FILE})
	target_compile_definitions(PropertyEditor PRIVATE PROPERTY_EDITOR_SHARED_LIBRARY)
else()
	add_library(PropertyEditor STATIC ${PROJECT_SOURCE} ${QRC_FILE})
	target_compile_definitions(PropertyEditor PUBLIC PROPERTY_EDITOR_STATIC_LIBRARY) 
endif()


set_property(TARGET PropertyEditor PROPERTY AUTOMOC ON)
set_property(TARGET PropertyEditor PROPERTY USE_FOLDERS ON)
set_property(TARGET PropertyEditor PROPERTY AUTOGEN_SOURCE_GROUP "Generated Files")

target_compile_definitions(PropertyEditor PRIVATE PROPERTY_EDITOR_LIBRARY)

target_link_libraries(PropertyEditor PUBLIC
	Qt::Gui
	Qt::GuiPrivate
	Qt::Widgets
	Qt::WidgetsPrivate
	Qt::QuickWidgets 
	Qt::QuickPrivate
	Qt::QuickTemplates2
	Qt::QuickTemplates2Private
	Qt::QuickControls2
)

target_include_directories(PropertyEditor PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/source/include)
file(GLOB_RECURSE PUBLIC_FILES LIST_DIRECTORIES TRUE ${CMAKE_CURRENT_SOURCE_DIR}/source/include/*)
foreach(PUBLIC_FILE ${PUBLIC_FILES})
    if(IS_DIRECTORY ${PUBLIC_FILE})
        target_include_directories(PropertyEditor PRIVATE  ${PUBLIC_FILE})
    endif()
endforeach()

set_target_properties(
    PropertyEditor
    PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${pd_PlatformDir}/bin"  
    LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${pd_PlatformDir}/lib"  
    ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${pd_PlatformDir}/lib"  
)

if(PROJECT_IS_TOP_LEVEL)
	add_subdirectory(example)
endif()
