# The math library (libm), found as a full path. A bare `m` could be mistaken
# for a target of the same name (a module called `m`). Empty where the math
# functions are part of the C library itself (Windows, macOS).
find_library(JM_MATH_LIBRARY m)
if(NOT JM_MATH_LIBRARY)
  set(JM_MATH_LIBRARY "")
endif()

# The component's C code, compiled once and linked into both its
# Python extension and the project's C library.
add_library(wfm_writer_core OBJECT wfm_writer_core.c write_blue_header.c)
target_include_directories(
  wfm_writer_core PUBLIC ${CMAKE_SOURCE_DIR}/native/inc
                         ${CMAKE_SOURCE_DIR}/native/inc/doppler/wfm_writer)
target_link_libraries(wfm_writer_core PUBLIC
    wfm_cjson_core
    wfm_keywords_core
    wfm_draw_core)

# The C unit test; `ctest` runs it.
add_executable(test_wfm_writer_core
               ${CMAKE_SOURCE_DIR}/native/tests/wfm_writer/test_wfm_writer_core.c
               ${CMAKE_SOURCE_DIR}/native/tests/wfm_writer/test_wfm_writer_symbols.c)
target_link_libraries(test_wfm_writer_core
                      PRIVATE wfm_writer_core wfm_cjson_core
    wfm_keywords_core
    wfm_draw_core
    ${JM_MATH_LIBRARY})
target_include_directories(test_wfm_writer_core
                           PRIVATE ${CMAKE_SOURCE_DIR}/native/inc
                                   ${CMAKE_SOURCE_DIR}/native/tests)
add_test(NAME test_wfm_writer_core COMMAND test_wfm_writer_core)

# The C benchmark; built, but not run by ctest.
add_executable(
  bench_wfm_writer_core
  ${CMAKE_SOURCE_DIR}/native/benchmarks/wfm_writer/bench_wfm_writer_core.c)
target_link_libraries(bench_wfm_writer_core
                      PRIVATE wfm_writer_core wfm_cjson_core
    wfm_keywords_core
    wfm_draw_core
    ${JM_MATH_LIBRARY})
target_include_directories(
  bench_wfm_writer_core PRIVATE ${CMAKE_SOURCE_DIR}/native/inc
                                   ${CMAKE_SOURCE_DIR}/native/benchmarks)
# The math library (libm), found as a full path. A bare `m` could be mistaken
# for a target of the same name (a module called `m`). Empty where the math
# functions are part of the C library itself (Windows, macOS).
find_library(JM_MATH_LIBRARY m)
if(NOT JM_MATH_LIBRARY)
  set(JM_MATH_LIBRARY "")
endif()

if(BUILD_PYTHON)
# wfm_writer Python module — aggregates: Writer
Python3_add_library(wfm_writer MODULE WITH_SOABI wfm_writer_ext.c)
target_link_libraries(wfm_writer PRIVATE
    wfm_writer_core
    wfm_cjson_core
    wfm_keywords_core
    wfm_draw_core
    Python3::NumPy)
target_include_directories(wfm_writer PRIVATE ${CMAKE_SOURCE_DIR}/native/inc)
set_target_properties(wfm_writer PROPERTIES
    LIBRARY_OUTPUT_DIRECTORY "${PYTHON_PACKAGE_DIR}/wfm"
    RUNTIME_OUTPUT_DIRECTORY "${PYTHON_PACKAGE_DIR}/wfm")
add_custom_command(TARGET wfm_writer POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_if_different
        "$<TARGET_FILE:wfm_writer>"
        "${PYTHON_PACKAGE_DIR}/wfm/$<TARGET_FILE_NAME:wfm_writer>"
    VERBATIM
    COMMENT "Copy wfm_writer extension module")
endif()

# Your own CMake for this directory goes in wfm_writer_extra.cmake beside this
# file: it is included here and never overwritten. This file is
# regenerated by just-makeit.
include(${CMAKE_CURRENT_LIST_DIR}/wfm_writer_extra.cmake OPTIONAL)
