2.0 KiB
2.0 KiB
CMake 2026 Project Setup Plan
Overview
This document outlines the technical plan for setting up a CMake-based C++ project with the following requirements:
- clang++ compiler with C++23 defaults
- Automatic source file discovery in src/ directory
- Executable generation from files containing 'main' in filename
- External dependency handling for git submodules
- Organized compile flags and variables
Key Components
1. Compiler Configuration
- Use clang++ as the C++ compiler
- Set C++ standard to C++23
- Configure appropriate compiler flags for clang
2. Source File Discovery
- Scan src/ directory for all .cpp files
- Use regex pattern
.*main.*\.cpp$to identify main files - Separate main files from other source files
3. Executable Generation
- Automatically create executables from files with 'main' in filename
- Create a library from all non-main source files
- Link the library to each executable
4. External Dependency Management
- Handle dependencies in external/ directory
- Example: spdlog in external/spdlog with namespace spdlog
- Create interface libraries for external dependencies
5. Compile Flags Organization
- Debug build flags: -g -O0 -Wall -Wextra
- Release build flags: -O3 -DNDEBUG -Wall -Wextra
- Common flags: -std=c++23 -fPIC
Implementation Details
Regex Pattern
.*main.*\.cpp$
Used to detect files containing 'main' in their filename.
Directory Structure
src/- Source files directoryexternal/- Git submodules directoryinclude/- Header files directory
File Processing Logic
- Find all .cpp files in src/
- Separate main files from other source files
- Create library from non-main files
- Generate executables from main files
- Link library and external dependencies to each executable
CMake Commands Used
cmake_minimum_required(VERSION 3.15)project(ProjectEuler CXX)file(GLOB_RECURSE)list(APPEND)add_executable()add_library()target_link_libraries()target_compile_features()find_package()add_subdirectory()