./dir/
├── bot_example
│ ├── CMakeLists.txt
│ └── example0.cpp
├── CMakeLists.txt
├── README.md
└── sleepy_discord
├── attachment.cpp
├── attachment.h
├── channel.cpp
├── etc...
我正在将一个纯视觉工作室的项目重构到CMake中,以使它跨平台。我在CMake方面没有广泛的经验,但是这个结构在一个测试项目中工作到调试结束。它没有包含第一个头文件(attachment.h和我似乎无法识别它。我已经搜索了其他答案,但同样的问题,但没有用,任何和所有帮助表示赞赏。CMake - Attachment.h:没有这样的文件或目录
编辑:我应该提到这个工程的窗户下,这就是为什么我很困惑,并深入到堆栈交易所
顶级的CMakeLists.txt
# Project Initialization
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
Project("Sleepy-Discord")
# Component Initialization
add_subdirectory(sleepy_discord)
add_subdirectory(bot_example)
./sleepy_discord/CMakeLists.txt
# Initialize API
cmake_minimum_required(VERSION 3.5)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
SET(BOOST_MIN_VERSION "1.58.0")
FIND_PACKAGE(Boost ${BOOST_MIN_VERSION} REQUIRED)
FIND_PACKAGE(CURL)
SET (sleepy_discord_SOURCES
./attachment.cpp
./attachment.h
./channel.cpp
./channel.h
./client.cpp
./client.h
./common.cpp
./common.h
./default_functions.cpp
./discord_object_interface.cpp
./discord_object_interface.h
./embed.cpp
./embed.h
./error.h
./experimental.cpp
./experimental.h
./json.c
./json.h
./json_wrapper.cpp
./message.cpp
./message.h
./sd_error.cpp
./server.cpp
./server.h
./sleepy_discord.h
./user.cpp
./user.h
)
if(Boost_FOUND)
add_library(sleepy_discord ${sleepy_discord_SOURCES})
target_include_directories(sleepy_discord INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
"$<BUILD_INTERFACE:${Boost_INCLUDE_DIRS}>"
"$<BUILD_INTERFACE:${CURL_INCLUDE_DIR}>"
"$<BUILD_INTERFACE:>${OPENSSL_INCLUDE_DIR}"
"$<BUILD_INTERFACE:>${CPR_INCLUDE_DIR}"
)
else()
message(STATUS "Boost library not found.")
endif()
./bot_example/CMakeLists.txt
# Initialize Bot
cmake_minimum_required(VERSION 3.5)
set(bot_example_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/example0.cpp
)
add_executable(bot_example ${bot_example_SOURCES})
target_link_libraries(bot_example sleepy_discord)
端子输出:
Scanning dependencies of target sleepy_discord
[ 5%] Building CXX object sleepy_discord/CMakeFiles/sleepy_discord.dir/attachment.cpp.o
/home/bleugamer/Development/bots/sleepy_discord/sleepy_discord/attachment.cpp:1:24: fatal error: Attachment.h: No such file or directory
compilation terminated.
sleepy_discord/CMakeFiles/sleepy_discord.dir/build.make:62: recipe for target 'sleepy_discord/CMakeFiles/sleepy_discord.dir/attachment.cpp.o' failed
make[2]: *** [sleepy_discord/CMakeFiles/sleepy_discord.dir/attachment.cpp.o] Error 1
CMakeFiles/Makefile2:85: recipe for target 'sleepy_discord/CMakeFiles/sleepy_discord.dir/all' failed
make[1]: *** [sleepy_discord/CMakeFiles/sleepy_discord.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
而是明确说明你的CMakeLists.txt源文件,你可以使用通配符文件,让CMake的收集您的烃源文件中的文件: 'FILE(GLOB SOURCES_FILES“ * .cpp“)' '文件(GLOB HEADER_FILES”* .h“)' 'SET(ALL_SOURCES $ {SOURCES_FILES} $ {HEADER_FILES})' –
@ vr.one这是不推荐的,因为cmake只更新如果cmake文件已更改,则在构建时间。显式文件发现在大多数大型项目中都是标准的。 Globing是一个临时性的解决方案,我这是一个长期的项目。 – BleuGamer
@ vr.one它不一定是件好事,因为它强制CMake在每个版本上运行。 – arrowd