Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,15 @@
*.app

build/
.vscode/
.vscode/

# CMake generated files
CMakeFiles/
CMakeCache.txt
cmake_install.cmake
Makefile
*.cmake

# Build output directories
bin/
lib/
114 changes: 99 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,107 @@
cmake_minimum_required(VERSION 3.10)
project(CPP_CONSOLE VERSION 1.0.0)
cmake_minimum_required(VERSION 3.15)

set(CMAKE_CXX_STANDARD 17)
set(PROJECT_NAME "CPP_CONSOLE")
if (UNIX)
set(PROJECT_NAME "CPP_CONSOLE.exe")
# Modern project declaration with explicit language specification
project(CPPConsole
VERSION 1.0.0
DESCRIPTION "A header-only C++ library for enhanced console output with colors, cursor control, and formatting"
HOMEPAGE_URL "https://github.com/Villy-P/CPPConsole"
LANGUAGES CXX
)

# Set default build type to Release if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
endif()

include_directories(include/)
# Create header-only interface library
add_library(CPPConsole INTERFACE)
add_library(CPPConsole::CPPConsole ALIAS CPPConsole)

# Set C++ standard and features using modern target-based approach
target_compile_features(CPPConsole INTERFACE cxx_std_17)

add_executable(${PROJECT_NAME}
"${CMAKE_CURRENT_SOURCE_DIR}/test/test.cpp"
# Add include directories using target-based approach
target_include_directories(CPPConsole
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
# Platform-specific compile definitions
if(WIN32)
target_compile_definitions(CPPConsole INTERFACE __WIN32)
endif()

# Option to build tests (default: ON for development, can be disabled for packaging)
option(CPPCONSOLE_BUILD_TESTS "Build CPPConsole tests" ON)

if(CPPCONSOLE_BUILD_TESTS)
# Test executable with proper naming convention
add_executable(CPPConsole_test
"${CMAKE_CURRENT_SOURCE_DIR}/test/test.cpp"
)

# Link the test executable to our library
target_link_libraries(CPPConsole_test PRIVATE CPPConsole::CPPConsole)

# Modern compiler options using generator expressions
target_compile_options(CPPConsole_test PRIVATE
$<$<CXX_COMPILER_ID:GNU,Clang>:-Wall -Wextra -pedantic>
$<$<CXX_COMPILER_ID:GNU,Clang>:$<$<CONFIG:Debug>:-g -O0>>
$<$<CXX_COMPILER_ID:GNU,Clang>:$<$<CONFIG:Release>:-O3 -DNDEBUG>>
$<$<CXX_COMPILER_ID:MSVC>:/W4>
$<$<CXX_COMPILER_ID:MSVC>:$<$<CONFIG:Debug>:/Od /Zi>>
$<$<CXX_COMPILER_ID:MSVC>:$<$<CONFIG:Release>:/O2 /DNDEBUG>>
)

# Set output directory for test executable
set_target_properties(CPPConsole_test PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin"
OUTPUT_NAME "cppconsole_test"
)

# Enable colored diagnostics if supported
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(CPPConsole_test PRIVATE -fdiagnostics-color=always)
endif()
endif()

# Installation rules for header-only library
include(GNUInstallDirs)

install(TARGETS CPPConsole
EXPORT CPPConsoleTargets
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.hpp"
)

install(EXPORT CPPConsoleTargets
FILE CPPConsoleTargets.cmake
NAMESPACE CPPConsole::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CPPConsole
)

# Generate and install config files for find_package support
include(CMakePackageConfigHelpers)

configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/CPPConsoleConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/CPPConsoleConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CPPConsole
)

write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/CPPConsoleConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)

target_compile_options(${PROJECT_NAME} PRIVATE
"-Wall"
"-std=c++17"
"-fdiagnostics-color=always"
"-g"
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/CPPConsoleConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/CPPConsoleConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/CPPConsole
)
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,65 @@ CPPConsole is a header-only library for `C++` projects that adds features to the

## Using CPPConsole

### Header-Only Installation (Simple)

To use CPPConsole in your project, copy all the file located in the `include/` directory into your own personal `include/` folder.

After that, you can add `#include "cppconsole.hpp"` to your file to include all CPPConsole functions, or include each file individually.

### CMake Installation (Recommended)

CPPConsole now includes a modern CMake build system that allows easy integration into CMake-based projects.

#### Installing CPPConsole System-Wide

```bash
# Clone and build
git clone https://github.com/Villy-P/CPPConsole.git
cd CPPConsole
mkdir build && cd build

# Configure (library-only, no tests)
cmake .. -DCPPCONSOLE_BUILD_TESTS=OFF

# Install to system
sudo make install
```

#### Using CPPConsole in Your CMake Project

Once installed, you can easily use CPPConsole in your CMake projects:

```cmake
# Find the library
find_package(CPPConsole REQUIRED)

# Create your executable
add_executable(your_app main.cpp)

# Link to CPPConsole
target_link_libraries(your_app PRIVATE CPPConsole::CPPConsole)

# Set C++ standard (required)
target_compile_features(your_app PRIVATE cxx_std_17)
```

#### Building and Testing CPPConsole

```bash
# Build with tests (default)
make build

# Run tests (once build issues are resolved)
make test

# Build library only
make configure-lib-only && make build

# Get help
make help
```

## Features

* ANSI Escape Code support
Expand Down
5 changes: 5 additions & 0 deletions cmake/CPPConsoleConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/CPPConsoleTargets.cmake")

check_required_components(CPPConsole)
70 changes: 64 additions & 6 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,69 @@
.ONESHELL:

# Platform detection
ifeq ($(OS),Windows_NT)
DETECTED_OS := Windows
EXE_EXT := .exe
RM_CMD := rmdir /s /q
MKDIR_CMD := mkdir
else
DETECTED_OS := Unix
EXE_EXT :=
RM_CMD := rm -rf
MKDIR_CMD := mkdir -p
endif

# Default target
.PHONY: all build test clean reset run install

all: build

# Reset build directory
reset:
rmdir build
mkdir build
cd build
cmake -GNinja ..
$(RM_CMD) build
$(MKDIR_CMD) build
cd build && cmake -GNinja ..

run:
# Build the project
build:
@if [ ! -d "build" ]; then $(MAKE) reset; fi
ninja -C build
.\CPP_CONSOLE.exe

# Build and run tests
test: build
cd build && ctest --output-on-failure

# Run the test executable
run: build
ifeq ($(DETECTED_OS),Windows)
.\build\bin\cppconsole_test$(EXE_EXT)
else
./build/bin/cppconsole_test$(EXE_EXT)
endif

# Install to system (requires privileges)
install: build
ninja -C build install

# Clean build artifacts
clean:
$(RM_CMD) build

# Configure without tests
configure-lib-only:
$(RM_CMD) build
$(MKDIR_CMD) build
cd build && cmake -GNinja -DCPPCONSOLE_BUILD_TESTS=OFF ..

# Help target
help:
@echo "Available targets:"
@echo " all - Build the project (default)"
@echo " build - Build the project"
@echo " test - Build and run tests"
@echo " run - Build and run the test executable"
@echo " reset - Clean and reconfigure build directory"
@echo " install - Install library to system"
@echo " clean - Remove build directory"
@echo " configure-lib-only - Configure without building tests"
@echo " help - Show this help message"