0

我正在尝试编译如下所示的项目。

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

我想用所有 *.cpp 和 *.h 编译项目。所以我通过参考下面网址的最后一条评论制作了 CMakeLists.txt。 带有包含和源路径的 CMake - 基本设置

>    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})

但错误显示“没有给目标提供资源”。我认为 add_executable() 需要 main.cpp 但如果我这样做,则无法告诉 CMakelist 其他来源(.cpp 和 .h 文件)的位置。我能得到一些建议吗?

4

0 回答 0