CMake:无法在子目录中看到源文件

时间:2018-06-06 17:31:24

标签: build cmake

我有一个目录树,CMake正确解析,但在顶级CMakeLists.txt文件中,它会丢失对源文件的跟踪。

# CMakeLists.txt - Top level
...
include_directories(${PROJECT_SOURCE_DIR}/include)
add_subdirectory(src)

# CMakeLists.txt - src
...
add_subdirectory(sub1)
add_subdirectory(sub2)
...
include_directories(
    ${CMAKE_CURRENT_LIST_DIR}/sub1
    ${CMAKE_CURRENT_LIST_DIR}/sub2
    ...
)

set(SOURCES src0.cpp ${SOURCES})

message("Sources from src: ${SOURCES}")

add_executable(${PROJECT_NAME} ${SOURCES})

## CMakeLists.txt - sub1

set(SOURCES ${SOURCES} sub1.cpp sub2.cpp)

message("Sources from sub1: ${SOURCES}")

我得到的是:

Sources from sub1: sub1.cpp sub2.cpp
Sources from src: src0.cpp

我需要的是:

Sources from sub1: sub1.cpp sub2.cpp
Sources from src: src0.cpp sub1.cpp sub2.cpp

0 个答案:

没有答案