0

I am trying to compile a project like below.

myproject
|CMakeLists.txt
|-src
| |main.cpp
| |subSrc1
| | |*.cpp
| | |*.h
| |subSrc2
| | |*.cpp
| | |*.hpp

I want to compile project with all *.cpp and *.h. so I made CMakeLists.txt by referring to the last comment of the url below. CMake with include and source paths - basic setup

>    cmake_minimum_required (VERSION 3.8 FATAL_ERROR)
>     project ("myproject")
>     include_directories ("${PROJECT_SOURCE_DIR}")
>     include_directories (
>       ${PROJECT_SOURCE_DIR}/src
>       ${PROJECT_SOURCE_DIR}/src/exec/
>       ${PROJECT_SOURCE_DIR}/src/host/
>     )
>     
>     file(GLOB all_SRCS
>       "${PROJECT_SOURCE_DIR}/*.cpp"
>       "${PROJECT_SOURCE_DIR}/src/*.cpp"
>       "${PROJECT_SOURCE_DIR}/src/exec/*.cpp"
>       "${PROJECT_SOURCE_DIR}/src/exec/*.h"
>       "${PROJECT_SOURCE_DIR}/src/host/*.cpp"
>     )
>     
>     #add_executable (myproject "myproject/src/main.cpp")
>     add_executable (myproject ${all_SRCS})

but error says "NO SOURCES GIVEN TO TARGET". I think add_executable() needs main.cpp but if I do that, there is no way to tell CMakelist the locations of other sources( .cpp and .h files). Can I get some advise?

doosolLee
  • 43
  • 7
  • The message "No sources given to target" means literally that your target has **no sources**. That is, your variable `all_SRCS` is **empty**. As this variable gets its content from the `file(GLOB)`, then it means your *globbing expressions* return nothing. Please, recheck that you actually have files in the directories which you use in regular expressions. – Tsyvarev Mar 10 '21 at 08:40
  • @Tsyvarev thanks for replying. I missed one file – doosolLee Mar 10 '21 at 13:01

0 Answers0