这是我的目录结构,下面是我在每个目录下的 CMakeLists.txt 文件。
app
include
inc.hpp
lib
question.cpp
answer.cpp
CMakeLists.txt
src
answer.cpp
CMakeLists.txt
CMakeLists.txt
app/CMakeLists.txt
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(hg2g_example LANGUAGES CXX)
add_subdirectory(src)
add_subdirectory(lib)
app/src/CMakeLists.txt(内容)
include_directories(../include)
add_executable(answer answer.cpp)
target_link_libraries(answer liber)
install(TARGETS answer DESTINATION bin)
app/lib/CMakeLists.txt
set(lib_headers ../include/inc.hpp
"${CMAKE_CURRENT_BINARY_DIR}/include/inc.hpp")
set(lib_sources answer.cpp question.cpp)
add_library(liber ${lib_sources} ${lib_headers})
target_include_directories(liber PUBLIC
include
"${CMAKE_CURRENT_BINARY_DIR}/include")
install(TARGETS liber DESTINATION lib)
install(FILES ${lib_headers} DESTINATION include)
inc.hpp 有两个函数的声明,一个在 lib/question.cpp 中定义,另一个在 lib/answer.cpp 中,src/answer.cpp 进一步调用这些函数。
我无法理解如何使用 CMake 生成这种文件结构,只要所有文件都在同一文件夹中,我就可以使用 CMake。
有人可以帮助我了解这对服务于不同目的的多个目录是如何工作的吗?
编辑:已解决