From a53ad977eb84b8e43e81aba780d9bf9566abe27f Mon Sep 17 00:00:00 2001 From: Afonso Clerigo Mendes de Sousa Date: Wed, 15 Oct 2025 12:03:56 +0100 Subject: [PATCH] Initial commit --- .gitignore | 10 +++++++ CMakeLists.txt | 75 ++++++++++++++++++++++++++++++++++++++++++++++ build.sh | 23 ++++++++++++++ include/.gitkeep | 0 libraries/.gitkeep | 0 source/main.cpp | 7 +++++ 6 files changed, 115 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100755 build.sh create mode 100644 include/.gitkeep create mode 100644 libraries/.gitkeep create mode 100644 source/main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9fd5b3e --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +*.a +*.log +*.so +*.swp + +/build/ +/.cache/ +/.DS_store +/.env +/imgui.ini diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..9b40ae0 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,75 @@ +cmake_minimum_required(VERSION 3.20) +project(CPP_TEMPLATE VERSION 0.1.0 LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +# Set output directories +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + +# Add include directories +include_directories(${CMAKE_SOURCE_DIR}/include) +include_directories(${CMAKE_SOURCE_DIR}/libraries) + +# Gather all source files (.cpp, .c) +file(GLOB_RECURSE PROJECT_SOURCES + ${CMAKE_SOURCE_DIR}/include/*.cpp + ${CMAKE_SOURCE_DIR}/include/*.c + ${CMAKE_SOURCE_DIR}/libraries/*.cpp + ${CMAKE_SOURCE_DIR}/libraries/*.c + ${CMAKE_SOURCE_DIR}/source/*.cpp + ${CMAKE_SOURCE_DIR}/source/*.c +) + +# Gather all header files (.hpp, .h) +file(GLOB_RECURSE PROJECT_HEADERS + ${CMAKE_SOURCE_DIR}/include/*.hpp + ${CMAKE_SOURCE_DIR}/include/*.h + ${CMAKE_SOURCE_DIR}/libraries/*.hpp + ${CMAKE_SOURCE_DIR}/libraries/*.h + ${CMAKE_SOURCE_DIR}/source/*.hpp + ${CMAKE_SOURCE_DIR}/source/*.h +) + +# Allow user to set output program name +option(OUTPUT_NAME "Name of the output executable" "") +if(OUTPUT_NAME STREQUAL "") + set(EXECUTABLE_NAME ${PROJECT_NAME}) +else() + set(EXECUTABLE_NAME ${OUTPUT_NAME}) +endif() + +# Add executable with all sources +add_executable(${EXECUTABLE_NAME} + ${PROJECT_SOURCES} + ${PROJECT_HEADERS} +) + +# Set output name property (for consistency) +set_target_properties(${EXECUTABLE_NAME} PROPERTIES OUTPUT_NAME ${EXECUTABLE_NAME}) + +# Enable warnings and extra diagnostics +if (MSVC) + target_compile_options(${EXECUTABLE_NAME} PRIVATE /W4 /permissive- /analyze) +else() + target_compile_options(${EXECUTABLE_NAME} PRIVATE + -Wall + -Wextra + -Wpedantic + -Wshadow + -Wconversion + -Wsign-conversion + -Wuninitialized + -Wunused + -Werror=return-type + -fsanitize=address,undefined + -g + ) + target_link_options(${EXECUTABLE_NAME} PRIVATE -fsanitize=address,undefined) +endif() + +# Optionally, enable testing +# enable_testing() +# add_subdirectory(tests) \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..d58bfd0 --- /dev/null +++ b/build.sh @@ -0,0 +1,23 @@ +if [ -z "$1" ]; then + echo "Error: Invalid Argument" + echo "Usage: $0 " + exit 1 +fi + +if [ ! -d "./build" ]; then + echo "Creating build directory..." + mkdir build +fi + +echo ">>> Building C++ Project <<<" +cd ./build +cmake -DOUTPUT_NAME=$1 .. +echo ">>> Compiling... <<<" +make +if [ $? -ne 0 ]; then + echo "Error: Build failed" + exit 1 +fi +cp ./bin/$1 ../ +echo ">>> Build Complete <<<" +echo ">>> Executable: $1 <<<" \ No newline at end of file diff --git a/include/.gitkeep b/include/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/libraries/.gitkeep b/libraries/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/source/main.cpp b/source/main.cpp new file mode 100644 index 0000000..df28b27 --- /dev/null +++ b/source/main.cpp @@ -0,0 +1,7 @@ +#include + +int main() +{ + std::cout << "Hello, World!" << std::endl; + return 0; +} \ No newline at end of file