Skip to content

Latest commit

 

History

History
194 lines (140 loc) · 3.84 KB

File metadata and controls

194 lines (140 loc) · 3.84 KB

🔨 Building Faker C++

This guide provides comprehensive instructions for building the Faker C++ library with different compilers and build systems.

Table of Contents

Prerequisites

  • CMake 3.22 or higher
  • C++ Compiler with C++20 support:
    • GCC 13+
    • Clang 16+
    • Apple Clang 16+
    • MSVC 143 (Visual Studio 2022)+

Quick Start

# Clone the repository
git clone https://github.com/cieslarmichal/faker-cxx.git
cd faker-cxx
git submodule update --init --recursive

# Configure and build (Linux/macOS with default compiler)
cmake -B ./build -DFAKER_BUILD_TESTING=ON
cmake --build ./build

# Run tests
ctest --test-dir ./build

Building with Different Compilers

Note: All compilers require cloning first. Do this once:

git clone https://github.com/cieslarmichal/faker-cxx.git
cd faker-cxx
git submodule update --init --recursive

GCC (Linux)

1. Install GCC:

sudo apt install cmake ninja-build g++-13

2. Configure and build:

cmake -B ./build -DCMAKE_CXX_COMPILER=g++-13 -DFAKER_BUILD_TESTING=ON
cmake --build ./build
ctest --test-dir ./build

Clang (Linux)

1. Install Clang:

sudo apt install clang-18

2. Configure and build:

cmake -B ./build -DCMAKE_CXX_COMPILER=clang++ -DFAKER_BUILD_TESTING=ON
cmake --build ./build
ctest --test-dir ./build

Apple Clang (macOS)

1. Install Apple Clang:

brew install llvm@18
export PATH="/opt/homebrew/opt/llvm@18/bin:$PATH"

2. Configure and build:

cmake -B ./build -DCMAKE_CXX_COMPILER=clang++ -DFAKER_BUILD_TESTING=ON
cmake --build ./build
ctest --test-dir ./build

MSVC (Windows)

1. Configure and build:

cmake -B ./build -G "Visual Studio 17 2022"
cmake --build ./build
ctest --test-dir ./build

Building with CMake Presets

The project includes CMake presets for standardized builds across different environments.

Alternative Build Systems

CMake Presets

cmake --list-presets                                # List all presets
cmake -S . --preset unixlike-gcc-debug-static      # Configure
cmake --build --preset unixlike-gcc-debug-static    # Build

Conan

conan install conanfile.txt --build=missing
cmake --preset=conan-release -DUSE_SYSTEM_DEPENDENCIES:BOOL=ON
cmake --build --preset=conan-release

Bazel

bazel build //:faker-cxx
bazel test //tests:all

Running Tests

Using CTest:

ctest --test-dir ./build              # Run all tests
ctest --test-dir ./build --verbose    # With verbose output
ctest --test-dir ./build -R "PersonTest"  # Run specific tests

Direct execution:

./build/tests/faker-cxx-UT  # Linux/macOS
./build/tests/Debug/faker-cxx-UT.exe  # Windows

Troubleshooting

CMake can't find the compiler:

export CXX=/usr/bin/g++-13
cmake -B ./build -DCMAKE_CXX_COMPILER=$CXX

Submodule not initialized:

git submodule update --init --recursive

Tests not found:

cmake -B ./build -DFAKER_BUILD_TESTING=ON

Advanced Options

cmake -B ./build \
  -DUSE_SYSTEM_DEPENDENCIES=ON \
  -DFAKER_BUILD_TESTING=OFF \
  -DCMAKE_INSTALL_PREFIX=/custom/path \
  -G Ninja

Next Steps