Any CMake pros?

May 17, 2024, 13:50

philip.2000

I am trying to restructure my project and I cannot get it to compile. My CMakeTexts right now with everything in one folder and everything working:
cmake_minimum_required(VERSION 3.12)

include(pico_sdk_import.cmake)

project(pico_examples C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

pico_sdk_init()

set(FAMILY rp2040)
set(BOARD pico_sdk)

add_executable(keyboard_firmware)

target_sources(keyboard_firmware PUBLIC
        ${CMAKE_CURRENT_LIST_DIR}/main.c
        ${CMAKE_CURRENT_LIST_DIR}/usb_descriptors.c
        )

# Make sure TinyUSB can find tusb_config.h
target_include_directories(keyboard_firmware PUBLIC
        ${CMAKE_CURRENT_LIST_DIR})

target_link_libraries(keyboard_firmware PUBLIC pico_stdlib pico_unique_id tinyusb_device tinyusb_board pico_cyw43_arch_none hardware_pio)

pico_add_extra_outputs(keyboard_firmware)
Everything perfect. Now the new structure:
Project/
β”œβ”€ CMakeLists.txt (1)
β”œβ”€ pico_sdk_import.cmake
β”œβ”€ src/
β”‚  β”œβ”€ CMakeLists.txt (2)
β”‚  β”œβ”€ main.c
β”‚  β”œβ”€ usb/
β”‚  β”‚  β”œβ”€ CMakeLists.txt (3)
β”‚  β”‚  β”œβ”€ tusb_config.h
β”‚  β”‚  β”œβ”€ usb_descriptors.c
β”‚  β”‚  β”œβ”€ usb_descriptors.h
# CMake 1
cmake_minimum_required(VERSION 3.12)

project(pico_examples C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

include(pico_sdk_import.cmake)
pico_sdk_init()


add_executable(keyboard_firmware)
add_subdirectory(src)

target_link_libraries(keyboard_firmware PUBLIC pico_stdlib pico_unique_id tinyusb_device tinyusb_board pico_cyw43_arch_none hardware_pio)

pico_add_extra_outputs(keyboard_firmware)
# CMake 2
target_sources(keyboard_firmware PUBLIC
        ${CMAKE_CURRENT_LIST_DIR}/main.c
        )

    add_subdirectory(usb)

# CMake 3

set(FAMILY rp2040)
set(BOARD pico_sdk)

target_sources(keyboard_firmware PUBLIC
        ${CMAKE_CURRENT_LIST_DIR}/usb_descriptors.c
        )

# Make sure TinyUSB can find tusb_config.h
target_include_directories(keyboard_firmware PUBLIC
        ${CMAKE_CURRENT_LIST_DIR})