cmake_minimum_required(VERSION 3.31)
project(ChromiumDataDumper LANGUAGES C CXX)

set(CMAKE_C_STANDARD 17)
set(CMAKE_C_STANDARD_REQUIRED ON)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# decryptor
set(CHROMIUM_DECRYPTOR_HEADERS
    decryptor/include/types.h
    decryptor/include/buffer.h
    decryptor/include/utils.h
    decryptor/include/crypto.h
    decryptor/include/browser.h
    decryptor/include/profile.h
    decryptor/include/handle_duplicator.h
    decryptor/include/extractor.h
    decryptor/include/orchestrator.h

    decryptor/include/reflective_loader.h
)

set(CHROMIUM_DECRYPTOR_SOURCES
    decryptor/src/dllmain.c
    decryptor/src/buffer.c
    decryptor/src/utils.c
    decryptor/src/crypto.c
    decryptor/src/browser.c
    decryptor/src/profile.c
    decryptor/src/handle_duplicator.c
    decryptor/src/extractor.c
    decryptor/src/orchestrator.c

    decryptor/src/reflective_loader.c
)

find_package(EASTL CONFIG REQUIRED)

add_library(ChromiumDecryptor SHARED ${CHROMIUM_DECRYPTOR_HEADERS} ${CHROMIUM_DECRYPTOR_SOURCES})

target_include_directories(ChromiumDecryptor PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}/decryptor/include
    ${CMAKE_CURRENT_SOURCE_DIR}/third_party/sqlite
)

add_library(sqlite3 STATIC 
    third_party/sqlite/sqlite3.h
    third_party/sqlite/sqlite3.c
)

target_link_libraries(ChromiumDecryptor PRIVATE sqlite3 EASTL)

# injector
set(CHROMIUM_INJECTOR_HEADERS
    injector/include/types.h
    injector/include/utils.h
    injector/include/browser_resolver.h
    injector/include/target_process.h
    injector/include/pipe_communicator.h
    injector/include/injection_manager.h
)

set(CHROMIUM_INJECTOR_SOURCES
    injector/src/main.c
    injector/src/utils.c
    injector/src/browser_resolver.c
    injector/src/target_process.c
    injector/src/pipe_communicator.c
    injector/src/injection_manager.c
)

add_executable(ChromiumInjector ${CHROMIUM_INJECTOR_HEADERS} ${CHROMIUM_INJECTOR_SOURCES})

target_include_directories(ChromiumInjector PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}/injector/include
)

if (MSVC)
    add_compile_options(/wd4471)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
    add_compile_options(-Wno-enum-forward-declaration)
endif()