Skip to content

Instantly share code, notes, and snippets.

@msmoiz
Last active June 22, 2021 16:39
Show Gist options
  • Save msmoiz/7aa91495b47e2df0ecf58b4663f9731b to your computer and use it in GitHub Desktop.
Save msmoiz/7aa91495b47e2df0ecf58b4663f9731b to your computer and use it in GitHub Desktop.
CMake Debug Settings with Visual Studio
Hello World!
cmake_minimum_required(VERSION 3.19)
project(foo)
add_executable(foo src/main.cpp)
set_target_properties(foo PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
VS_DEBUGGER_COMMAND_ARGUMENTS "bar.txt")
{
"version": "0.2.1",
"defaults": {},
"configurations": [
{
"type": "default",
"project": "CMakeLists.txt",
"projectTarget": "foo.exe",
"name": "foo.exe [with args]",
"currentDir": "${workspaceRoot}",
"args": ["bar.txt"]
}
]
}
#include <iostream>
#include <fstream>
#include <string>
int main(int argc, const char** argv)
{
if (argc < 2)
{
std::cerr << "Insufficient arguments." << std::endl;
return -1;
}
std::ifstream file(argv[1]);
if (!file.is_open())
{
std::cerr << "Could not open file: " << argv[1] << "." << std::endl;
return -1;
}
std::string line;
while (std::getline(file, line))
{
std::cout << line << std::endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment