include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/osc_strict_compiler_options.cmake)  # OSC_STRICT_COMPILER_OPTIONS

option(OSC_FORCE_ASSERTS_ENABLED             "Enable OSC's runtime assertions - even if building a release build" ON)
option(OSC_RUNTIME_PERF_MEASUREMENTS_ENABLED "Enable whether the `OSC_PERF` macro records performance or not"     ON)
option(OSC_EMSCRIPTEN                        "Enable special build parameters for emscripten (emsdk)"             OFF)
mark_as_advanced(OSC_EMSCRIPTEN)  # don't try the option this unless you know what you're doing ;)

# find library packages
if (NOT ${OSC_EMSCRIPTEN})
    # These libraries are either provided by emscripten later on, or aren't
    # supported by the emscripten build (they're #ifdef'd out in `oscar`'s
    # source code).
    find_package(glad REQUIRED CONFIG)
    find_package(SDL3 REQUIRED CONFIG)
endif()
find_package(imgui REQUIRED CONFIG)
find_package(implot REQUIRED CONFIG)
find_package(tomlplusplus REQUIRED CONFIG)
find_package(stb REQUIRED CONFIG)
find_package(lunasvg REQUIRED CONFIG)
find_package(unordered_dense REQUIRED CONFIG)
find_package(Threads REQUIRED)  # implicitly required by SDL3

# generate `oscarconfig.h`
configure_file(
    "${CMAKE_CURRENT_SOURCE_DIR}/oscarconfig.h.in"
    "${CMAKE_CURRENT_BINARY_DIR}/liboscar/oscarconfig.h"
    @ONLY
)

# gather source code, exclude tests
file(GLOB_RECURSE OSC_SOURCE_AND_HEADER_FILES "*.cpp")
list(FILTER OSC_SOURCE_AND_HEADER_FILES EXCLUDE REGEX "(testing|\.tests\.cpp)")
add_library(oscar STATIC ${OSC_SOURCE_AND_HEADER_FILES})
set_target_properties(oscar PROPERTIES CXX_EXTENSIONS OFF)
target_compile_features(oscar PUBLIC cxx_std_23)
target_compile_options(oscar PRIVATE ${OSC_STRICT_COMPILER_OPTIONS})
target_include_directories(oscar PUBLIC
    "${CMAKE_CURRENT_SOURCE_DIR}/.."  # so that `#include <liboscar/HEADER.h>` works
    "${CMAKE_CURRENT_BINARY_DIR}/"    # so that #include <liboscar/oscarconfig.h> works
)
target_link_libraries(oscar
PRIVATE
    # these libraries are either provided by emscripten later on, or aren't
    # supported by the emscripten build (they're #ifdef'd out)
    $<$<NOT:$<BOOL:${OSC_EMSCRIPTEN}>>:glad>
    $<$<NOT:$<BOOL:${OSC_EMSCRIPTEN}>>:SDL3::SDL3>

    unordered_dense::unordered_dense
    tomlplusplus::tomlplusplus
    imgui
    implot
    stb
    lunasvg::lunasvg
    Threads::Threads  # implicitly required by SDL3
)

if(BUILD_TESTING)
    add_subdirectory(testing)
endif()
