CMakeLists.txt 나는 "파일을 열 수 없습니다"이 출력을 가지고리소스로 작업 디렉토리에 txt 파일을 추가하기 위해 cmake를 설정하는 방법은 무엇입니까?
#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;
}
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. 파일 test.txt
, CMakeLists.txt
및 main.cpp
은 같은 디렉토리에 있습니다. IDE는 Clion입니다.
파일을 자원으로 작업 디렉토리에 추가하려면 CMakeLists.txt
을 어떻게 설정합니까?
대단히 감사합니다. 여러 파일을 바이너리 디렉토리에 한 번 복사 할 수있는 방법이 있습니까? – TrW236
확실히. 'GLOB' 키워드 사용 :'file (GLOB MY_FILES "* .txt") 파일 (COPY $ {MY_FILES} DESTINATION $ {CMAKE_CURRENT_BINARY_DIR})' –