cmake_minimum_required(VERSION 3.15)
project(benchpulse C)

set(CMAKE_C_STANDARD 17)
set(CMAKE_C_STANDARD_REQUIRED ON)

if(WIN32)
    add_definitions(-DBP_PLATFORM_WINDOWS=1)
    set(PLATFORM_SOURCES native/platform/windows/platform.c)
elseif(APPLE)
    add_definitions(-DBP_PLATFORM_DARWIN=1 -D_DARWIN_C_SOURCE=1)
    set(PLATFORM_SOURCES native/platform/darwin/platform.c)
else()
    add_definitions(-DBP_PLATFORM_LINUX=1 -D_GNU_SOURCE=1)
    set(PLATFORM_SOURCES native/platform/linux/platform.c)
endif()

set(BENCHPULSE_NATIVE_SOURCES
    native/error.c
    native/config.c
    native/statistics/statistics.c
    native/report/report.c
    native/runtime/collector_manager.c
    native/runtime/runtime.c
    ${PLATFORM_SOURCES}
)

add_library(benchpulse_native STATIC ${BENCHPULSE_NATIVE_SOURCES})
target_include_directories(benchpulse_native PUBLIC include)

if(WIN32)
    target_link_libraries(benchpulse_native PUBLIC psapi)
endif()

add_library(benchpulse_extension MODULE native/bindings/extension.c)
target_link_libraries(benchpulse_extension PRIVATE benchpulse_native)
target_include_directories(benchpulse_extension PRIVATE include)

if(WIN32)
    set_target_properties(benchpulse_extension PROPERTIES PREFIX "")
    target_link_libraries(benchpulse_extension PRIVATE psapi)
endif()
