cmake_minimum_required(VERSION 3.15)
project(Bluehound)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# SimpleBLE local build
set(SIMPLEBLE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/simpleble/simpleble")
set(SIMPLEBLE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/simpleble")
add_library(simpleble STATIC IMPORTED)
set_target_properties(simpleble PROPERTIES
    IMPORTED_LOCATION "${SIMPLEBLE_DIR}/build/lib/libsimpleble.a"
    INTERFACE_INCLUDE_DIRECTORIES "${SIMPLEBLE_DIR}/include;${SIMPLEBLE_DIR}/build/export;${SIMPLEBLE_ROOT}/dependencies/external"
)

# Find other packages
find_package(SQLite3 REQUIRED)

# cpp-httplib v0.14.3 vendored under third_party for offline builds
set(HTTPLIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party")

# Executable
add_executable(bluehound
    bluehound.cpp
    classic_bluetooth.mm
)

# Enable Objective-C++ for .mm files
set_source_files_properties(classic_bluetooth.mm PROPERTIES
    COMPILE_FLAGS "-x objective-c++ -fobjc-arc"
)

target_link_libraries(bluehound
    simpleble
    SQLite::SQLite3
    pthread
    "-framework Foundation"
    "-framework CoreBluetooth"
    "-framework IOKit"
    "-framework IOBluetooth"
)

target_include_directories(bluehound PRIVATE
    ${HTTPLIB_DIR}
)

# Installation
install(TARGETS bluehound DESTINATION bin)
