0
的CMakeLists.txt如何設置cmake,以便將txt文件作爲資源添加到工作目錄中?
cmake_minimum_required(VERSION 3.8)
project(untitled)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(untitled ${SOURCE_FILES})
的main.cpp
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string line;
ifstream myfile ("test.txt");
if (myfile.is_open())
{
while (getline (myfile,line))
{
cout << line << '\n';
}
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
我得到這個輸出 「無法打開文件」。 文件test.txt
,CMakeLists.txt
和main.cpp
位於相同的目錄中。 IDE是CLion。
如何設置CMakeLists.txt
,以便將test.txt
文件添加到工作目錄中作爲資源?
非常感謝。有沒有辦法,一次可以將多個文件複製到二進制目錄中? – TrW236
當然。使用'GLOB'關鍵字:'file(GLOB MY_FILES「* .txt」)file(COPY $ {MY_FILES} DESTINATION $ {CMAKE_CURRENT_BINARY_DIR})' –