idf_component_register(SRCS "sim_main.c" "sim_stubs.c" "sim_timer.c" "sim_rig.c"
                       INCLUDE_DIRS "include" "."
                       REQUIRES esp_http_server esp_timer esp_event cjson main freertos)
target_link_libraries(${COMPONENT_LIB} INTERFACE m)
# main's objects need esp_timer and libm, which come after it on the link line: link sim (and libm) last
target_link_libraries(__idf_main INTERFACE ${COMPONENT_LIB} m)

# The simulated rig's page and drivers (tools/build_sim_web.sh), served at /sim/. Without it the program still
# builds: an empty pack, and /sim/ says how to build the rig.
set(SIM_PACK ${COMPONENT_DIR}/../../../www_dist/sim.pack)
if(NOT EXISTS ${SIM_PACK})
    file(WRITE ${SIM_PACK} "WWW1")
endif()
target_add_binary_data(${COMPONENT_LIB} ${SIM_PACK} BINARY)
