Issue regarding CMake Error: No source given to target

Viewed 27129

I am trying to add FreeRtos to a project of mine using cmake and eclipse but I am getting an error. I am running debian 10 and my cmake version is 3.13.4. The files for cmake can be found at this git repo. When I run the following command:

frank@debian:~/temp2/build$ cmake ../../temp2/AM335X-FreeRTOS-lwip/ -G"Eclipse CDT4 - Unix Makefiles"

I get the following error:

    CMake Error at ProjectIncludes.cmake:46 (add_library):
  No SOURCES given to target: lib_third_party_ti_platform_beaglebone
Call Stack (most recent call first):
  CMakeLists.txt:33 (include)


CMake Error at ProjectIncludes.cmake:30 (add_library):
  No SOURCES given to target: lib_third_party_ti_utils
Call Stack (most recent call first):
  CMakeLists.txt:33 (include)


CMake Error at ProjectIncludes.cmake:38 (add_library):
  No SOURCES given to target: lib_third_party_ti_mmcsdlib
Call Stack (most recent call first):
  CMakeLists.txt:33 (include)


CMake Error at ProjectIncludes.cmake:54 (add_library):
  No SOURCES given to target: lib_third_party_ti_nandlib
Call Stack (most recent call first):
  CMakeLists.txt:33 (include)


CMake Error at CMakeLists.txt:15 (add_executable):
  No SOURCES given to target: freeRTOSBBB.elf


CMake Error at ProjectIncludes.cmake:23 (add_library):
  No SOURCES given to target: lib_third_party_ti_drivers
Call Stack (most recent call first):
  CMakeLists.txt:33 (include)


CMake Error at ProjectIncludes.cmake:115 (add_library):
  No SOURCES given to target:
  lib_third_party_amazon_freertos_kernel_portable_MemMang
Call Stack (most recent call first):
  CMakeLists.txt:33 (include)


CMake Error at ProjectIncludes.cmake:86 (add_library):
  No SOURCES given to target:
  lib_third_party_amazon_libraries_3rdparty_lwip_src
Call Stack (most recent call first):
  CMakeLists.txt:33 (include)


CMake Error at ProjectIncludes.cmake:101 (add_library):
  No SOURCES given to target: src_portable_lwip_ports_cpsw_netif
Call Stack (most recent call first):
  CMakeLists.txt:33 (include)


CMake Error at ProjectIncludes.cmake:106 (add_library):
  No SOURCES given to target: lib_third_party_amazon_freertos_kernel
Call Stack (most recent call first):
  CMakeLists.txt:33 (include)


CMake Error at ProjectIncludes.cmake:111 (add_library):
  No SOURCES given to target:
  src_portable_FreeRTOS_portable_GCC_ARM_CA8_amm335x
Call Stack (most recent call first):
  CMakeLists.txt:33 (include)


CMake Error at ProjectIncludes.cmake:65 (add_library):
  No SOURCES given to target: lib_third_party_ti_system_config_armv7a
Call Stack (most recent call first):
  CMakeLists.txt:33 (include)


CMake Error at ProjectIncludes.cmake:134 (add_library):
  No SOURCES given to target: src_application
Call Stack (most recent call first):
  CMakeLists.txt:33 (include)


CMake Error at ProjectIncludes.cmake:120 (add_library):
  No SOURCES given to target: src_portable_AM335X
Call Stack (most recent call first):
  CMakeLists.txt:33 (include)


CMake Error at ProjectIncludes.cmake:129 (add_library):
  No SOURCES given to target: src_portable_ported_aws_bufpool
Call Stack (most recent call first):
  CMakeLists.txt:33 (include)
2 Answers

The error says what it means: there are no sources for libraries.

#adding entries for lib_third_party_ti_mmcsdlib
    include_directories("${PROJECT_SOURCE_DIR}/lib/third_party/ti/mmcsdlib")
    include_directories("${PROJECT_SOURCE_DIR}/lib/third_party/ti/mmcsdlib/include")
    add_library(lib_third_party_ti_mmcsdlib "") # NO SOURCES HERE!!!!
    target_compile_definitions(lib_third_party_ti_mmcsdlib 
        PRIVATE -DBOOT=MMCSD -DCONSOLE=UARTCONSOLE
    )
    subdirs("${PROJECT_SOURCE_DIR}/lib/third_party/ti/mmcsdlib")
    subdirs("${PROJECT_SOURCE_DIR}/lib/third_party/ti/mmcsdlib/include")

You should read the docs about add_library in cmake. If you don't provide any source files, you should declare it as INTERFACE

add_library(LibName INTERFACE)

In this case no compilation target would be generated. Otherwise, you can declare it as IMPORTED, then cmake will not try to create a target for compilation either.

For SHARED, STATIC or OBJECT you always need to supply sources.

You should check ProjectIncludes.cmake for what you really want to do: compile new libs or import them.

For me (came here from Google), this error occurred when CMake target_sources had only PRIVATE sources, and no PUBLIC sources.

I had to make at least one PUBLIC source file:

old:

target_sources(${PROJECT_NAME}
        PRIVATE
        External/dbscan.cpp

        main.cpp
        )

new:

target_sources(${PROJECT_NAME}
        PRIVATE
        External/dbscan.cpp

        PUBLIC
        main.cpp
        )
Related