@@ -6,83 +6,62 @@ enable_testing()
66set (CMAKE_CXX_STANDARD 17)
77set (CMAKE_CXX_STANDARD_REQUIRED ON )
88set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
9-
10- # Include directories are handled per-target, but we set up the mock path for the object library
11- # ensuring compilation on host works
129set (MOCK_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR} /tests/host/mocks" )
1310
14- # Create an interface library for the header-only code in src/
1511add_library (spresense_core INTERFACE )
1612
17- # Configure include directories for the core library
1813target_include_directories (spresense_core INTERFACE
1914 src
2015 ${MOCK_INCLUDE_DIR}
2116)
2217
23- # Add the tests directory
24- # verify if tests/host directory exists before adding it
2518if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR} /tests/host/CMakeLists.txt" )
2619 add_subdirectory (tests/host)
2720endif ()
2821
2922# ==============================================================================
30- # Arduino / Spresense CLI Integration
23+ # Arduino CLI Integration
3124# ==============================================================================
3225
33- # Variables (can be overridden via -DVAR=VALUE or cmake-gui)
3426set (ARDUINO_CLI "arduino-cli" CACHE STRING "Path to arduino-cli executable" )
3527set (SPRESENSE_FQBN "SPRESENSE:spresense:spresense" CACHE STRING "FQBN for Spresense" )
3628set (PORT "/dev/ttyACM0" CACHE STRING "Serial port for upload" )
3729set (SKETCH "." CACHE STRING "Path to sketch directory" )
3830
39- # Default FQBN to Spresense if not specified
4031if (NOT DEFINED FQBN)
4132 set (FQBN ${SPRESENSE_FQBN} )
4233endif ()
4334
44- # Target: compile (generic)
45- add_custom_target (compile
46- COMMAND ${ARDUINO_CLI} compile --fqbn ${FQBN} ${SKETCH}
47- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
48- COMMENT "Compiling sketch for ${FQBN} ..."
49- )
50-
51- # Target: spresense (compile for spresense)
5235add_custom_target (spresense
5336 COMMAND ${CMAKE_COMMAND} -E echo "Switching to Spresense FQBN..."
5437 COMMAND ${ARDUINO_CLI} compile --fqbn ${SPRESENSE_FQBN} ${SKETCH}
5538 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
5639 COMMENT "Compiling for Spresense..."
5740)
5841
59- # Target: upload (generic)
6042add_custom_target (upload
6143 COMMAND ${ARDUINO_CLI} upload -p ${PORT} --fqbn ${FQBN} ${SKETCH}
6244 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
6345 COMMENT "Uploading to ${PORT} for ${FQBN} ..."
6446)
6547
66- # Target: upload_spresense
67- add_custom_target (upload_spresense
68- COMMAND ${ARDUINO_CLI} compile --fqbn ${SPRESENSE_FQBN} ${SKETCH}
69- COMMAND ${ARDUINO_CLI} upload -p ${PORT} --fqbn ${SPRESENSE_FQBN} ${SKETCH}
70- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
71- COMMENT "Building and uploading for Spresense..."
72- )
73-
74- # Target: clean_arduino_cache
7548add_custom_target (clean_arduino_cache
7649 COMMAND ${ARDUINO_CLI} cache clean
7750 COMMENT "Cleaning Arduino CLI cache..."
7851)
7952
80- # Helper to print usage
81- add_custom_target (arduino_help
53+ add_custom_target (refresh
54+ COMMAND ${ARDUINO_CLI} compile --fqbn ${SPRESENSE_FQBN} ${SKETCH} --build -path build -arduino --only-compilation-database
55+ COMMAND ${CMAKE_COMMAND} -E copy build -arduino/compile_commands.json ${CMAKE_CURRENT_SOURCE_DIR} /compile_commands.json
56+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
57+ COMMENT "Generating compile_commands.json for IDE support..."
58+ )
59+
60+ add_custom_target (howto
8261 COMMAND ${CMAKE_COMMAND} -E echo "Custom Targets:"
8362 COMMAND ${CMAKE_COMMAND} -E echo " spresense - Compile for Spresense"
8463 COMMAND ${CMAKE_COMMAND} -E echo " upload - Upload using current settings"
85- COMMAND ${CMAKE_COMMAND} -E echo " upload_spresense - Compile and upload for Spresense"
8664 COMMAND ${CMAKE_COMMAND} -E echo " clean_arduino_cache - Clean arduino-cli cache"
65+ COMMAND ${CMAKE_COMMAND} -E echo " refresh - Generate compile_commands.json for IDE"
8766 COMMENT "Displaying help..."
8867)
0 commit comments