commit 89361cc73544a2581ff0817ee66f7c74fd0fb815 Author: Fabian Schmidt Date: Tue Feb 4 13:44:55 2025 +0100 Simple cmake example with working ccls diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d4fe85c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.ccls-cache +compile_commands.json +build diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..68089e2 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,16 @@ +# Specify the minimum version of CMake required +cmake_minimum_required(VERSION 3.10) + +# Set the project name and version +project(MyProject VERSION 1.0) + +# Specify the C++ standard +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED True) + +# Include the header files +include_directories(include) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +# Add the executable +add_executable(MyProject src/main.cpp src/HelloWorld.cpp) diff --git a/include/HelloWorld.h b/include/HelloWorld.h new file mode 100644 index 0000000..2e0ce63 --- /dev/null +++ b/include/HelloWorld.h @@ -0,0 +1,11 @@ +#ifndef HELLOWORLD_H +#define HELLOWORLD_H + +#include + +class HelloWorld { +public: + void printMessage(const std::string &message); +}; + +#endif // HELLOWORLD_H diff --git a/justfile b/justfile new file mode 100644 index 0000000..fff8c7f --- /dev/null +++ b/justfile @@ -0,0 +1,13 @@ +default: run + +build: + mkdir -p build && cd build && cmake .. && cmake --build . + +run: build + cd build && ./MyProject + +ccls: + mkdir -p build && cd build && cmake .. && cd .. && ln -s build/compile_commands.json . + +clean: + rm -rf build && rm compile_commands.json diff --git a/src/HelloWorld.cpp b/src/HelloWorld.cpp new file mode 100644 index 0000000..3f12451 --- /dev/null +++ b/src/HelloWorld.cpp @@ -0,0 +1,6 @@ +#include "HelloWorld.h" +#include + +void HelloWorld::printMessage(const std::string &message) { + std::cout << message << std::endl; +} diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..abf95f9 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,7 @@ +#include "HelloWorld.h" + +int main() { + HelloWorld hello; + hello.printMessage("Hello, World!"); + return 0; +}