# file: Collect all files that need to be compiled. 
# You can use a GLOB function as shown here, or explicitly mention the specific files
#file(GLOB FILES *.c *.h)

# Need to include CTest on every CMakeLists.txt which is going to use tests
include(CTest)
set(TUNNEL_ID "" CACHE STRING "Tunnel ID for JRun") # Default is empty

set(THIS_LIBRARY_NAME srcTestsLib)

file(GLOB FILES
  *.c
)

# add_library: With this declaration, you express the intent to build a library. 
# The first argument is the name of the library, 
# the second argument are the files that will be compiled to create your library.
add_library(${THIS_LIBRARY_NAME} ${FILES})

# target_link_libraries: If you link with other libraries, list them here
target_link_libraries(
  ${THIS_LIBRARY_NAME}
  PRIVATE McuLib
  PRIVATE unityLib
  PRIVATE srcLib
  PRIVATE pico_cyw43_arch_lwip_sys_freertos 
)

# target_include_directories: Libraries need to publish their header files 
# so that you can import them in source code. This statement expresses where to find the files 
# - typically in an include directory of your projects.
target_include_directories(
  ${THIS_LIBRARY_NAME}
  PUBLIC
  .
)

# Add tunnel ID if provided by user during cmake command execution
if(TUNNEL_ID)
  set(JRUN_IP_ARG --ip "tunnel:${TUNNEL_ID}")
else()
  set(JRUN_IP_ARG)
endif()

#################################################################################
# Note: --pc off --sp off are needed, if application runs from the ROM bootloader, might add --verbose
set(JRUN_CTEST_COMMAND "JRun" --device RP2040_M0_0 --rtt -if SWD --pc off --sp off ${JRUN_IP_ARG})

add_test(
  NAME DUMMY
  COMMAND ${JRUN_CTEST_COMMAND} --args "dummy" ${TEST_EXECUTABLE}
)

add_test(
  NAME Sensors 
  COMMAND ${JRUN_CTEST_COMMAND} --args "sensors" ${TEST_EXECUTABLE}
)

add_test(
  NAME DNS
  COMMAND ${JRUN_CTEST_COMMAND} --args "dns" ${TEST_EXECUTABLE}
)

add_test(
  NAME MQTT
  COMMAND ${JRUN_CTEST_COMMAND} --args "mqtt" ${TEST_EXECUTABLE}
)

set_tests_properties(
  DUMMY Sensors DNS MQTT
  PROPERTIES 
  TIMEOUT 200
) 
